-
Notifications
You must be signed in to change notification settings - Fork 0
Supertaining #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supertaining #8
Changes from all commits
2858cb5
fc091df
5d2c700
5323103
3340c64
a6df87b
bf0e37f
30316a1
eb48b9b
bd46683
cf5ce5e
4abc4e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,9 @@ import ( | |
| var ErrUserNotFound errific.Err = "user not found" | ||
|
|
||
| func main() { | ||
| // Configure pretty JSON output for readability | ||
| errific.Configure(errific.OutputJSONPretty) | ||
|
|
||
| // Return an error with context | ||
| err := GetUser("user-123") | ||
| fmt.Println(err) | ||
|
|
@@ -36,15 +39,23 @@ func GetUser(userID string) error { | |
| ``` | ||
|
|
||
| **Output:** | ||
| ``` | ||
| user not found [main.go:20.GetUser] | ||
| ```json | ||
| { | ||
| "error": "user not found", | ||
| "code": "USER_404", | ||
| "caller": "main.go:27.GetUser", | ||
| "context": { | ||
| "source": "database", | ||
| "user_id": "user-123" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The error includes: | ||
| - ✅ Automatic caller information (`main.go:20.GetUser`) | ||
| - ✅ Error code (`USER_404`) | ||
| - ✅ Structured context (user_id, source) | ||
| - ✅ JSON serializable for logging | ||
| - ✅ Error code (`USER_404`) visible in output | ||
| - ✅ Structured context (user_id, source) visible in output | ||
| - ✅ JSON output by default for structured logging | ||
|
|
||
| ## ✨ Features | ||
|
|
||
|
|
@@ -133,6 +144,78 @@ jsonBytes, _ := json.Marshal(err) | |
| log.Info(string(jsonBytes)) | ||
| ``` | ||
|
|
||
| ### 🎨 Output Formats & Verbosity | ||
|
|
||
| Errific supports multiple output formats and verbosity levels. **By default, errors output as JSON with all metadata visible**. | ||
|
|
||
| ```go | ||
| // Default: JSON format with full verbosity (shows all metadata) | ||
| errific.Configure() // or Configure(OutputJSON, VerbosityFull) | ||
|
Comment on lines
+152
to
+153
|
||
|
|
||
| err := ErrUserNotFound. | ||
| WithCode("USER_404"). | ||
| WithContext(errific.Context{"user_id": "user-123"}) | ||
|
|
||
| fmt.Println(err) | ||
| // Output: {"error":"user not found","code":"USER_404","caller":"main.go:20","context":{"user_id":"user-123"}} | ||
|
|
||
| // JSON Pretty format (indented JSON for docs/debugging) | ||
| errific.Configure(OutputJSONPretty) | ||
| fmt.Println(err) | ||
| // Output: | ||
| // { | ||
| // "error": "user not found", | ||
| // "code": "USER_404", | ||
| // "caller": "main.go:20", | ||
| // "context": { | ||
| // "user_id": "user-123" | ||
| // } | ||
| // } | ||
|
|
||
| // Pretty format (multi-line, human-readable text) | ||
| errific.Configure(OutputPretty) | ||
| fmt.Println(err) | ||
| // Output: | ||
| // user not found [main.go:20.GetUser] | ||
| // code: USER_404 | ||
| // context: map[user_id:user-123] | ||
|
|
||
| // Compact format (single-line key=value) | ||
| errific.Configure(OutputCompact) | ||
| fmt.Println(err) | ||
| // Output: user not found [main.go:20] code=USER_404 user_id=user-123 | ||
|
|
||
| // Minimal verbosity (only message + caller, useful for simple logging) | ||
| errific.Configure(VerbosityMinimal) | ||
| fmt.Println(err) | ||
| // Output (JSON): {"error":"user not found","caller":"main.go:20"} | ||
|
|
||
| // Standard verbosity (message + caller + code + category + context) | ||
| errific.Configure(VerbosityStandard) | ||
| fmt.Println(err) | ||
| // Output (JSON): {"error":"user not found","code":"USER_404","caller":"main.go:20","context":{"user_id":"user-123"}} | ||
|
|
||
| // Custom verbosity (show only specific fields) | ||
| errific.Configure(VerbosityFull, HideContext, HideMCPData) | ||
| fmt.Println(err) | ||
| // Output (JSON): {"error":"user not found","code":"USER_404","caller":"main.go:20","http_status":404} | ||
| ``` | ||
|
|
||
| **Available output formats:** | ||
| - `OutputJSON` (default) - Compact JSON for structured logging | ||
|
||
| - `OutputJSONPretty` - Indented JSON for documentation and debugging | ||
| - `OutputPretty` - Multi-line, human-readable text | ||
| - `OutputCompact` - Single-line key=value pairs | ||
|
|
||
| **Available verbosity levels:** | ||
| - `VerbosityFull` (default) - Show all non-empty fields | ||
| - `VerbosityStandard` - Show code, category, context | ||
| - `VerbosityMinimal` - Show only message and caller | ||
| - `VerbosityCustom` - Use with `Show*`/`Hide*` flags for granular control | ||
|
|
||
| **Granular field control:** | ||
| `HideCode`, `HideCategory`, `HideContext`, `HideHTTPStatus`, `HideRetryMetadata`, `HideMCPData`, `HideTags`, `HideLabels`, `HideTimestamps` | ||
|
|
||
| ### JSON Output | ||
|
|
||
| ```json | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,19 @@ func Configure(opts ...Option) { | |||||
| c.withStack = false | ||||||
| c.trimPrefixes = nil | ||||||
| c.trimCWD = false | ||||||
| c.outputFormat = OutputJSON | ||||||
|
||||||
| c.outputFormat = OutputJSON | |
| c.outputFormat = OutputPretty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation shows
main.go:20.GetUserbut the example output above (line 46) showsmain.go:27.GetUser. These line numbers should be consistent. The actual call in the example is at line 32-37 in GetUser function, so the caller reference should reflect the actual location.