You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** If `Printer.AsPrintable` is not set, the package-level `AsPrintable` function is used, which checks if the value implements the `Printable` interface.
201
200
202
-
### Global Configuration with DefaultPrinter
201
+
### Integration with go-errs
203
202
204
-
The `DefaultPrinter` variable is used by all package-level print functions (`pretty.Sprint`, `pretty.Println`, etc.) and can be configured globally. This is especially useful when you want to customize formatting for third-party packages that use go-pretty (like `go-errs` for error formatting) without implementing the `Printable` interface on your types.
203
+
The `go-errs` package uses a configurable `Printer` variable (of type `*pretty.Printer`) for formatting function parameters in error call stacks. You can customize this printer to mask secrets, adapt types, or change formatting without implementing the `Printable` interface on your types.
205
204
206
205
**Use cases:**
207
206
- Hide sensitive data (secrets, passwords, tokens) in error messages and stack traces
@@ -215,12 +214,22 @@ import (
215
214
"io"
216
215
"reflect"
217
216
"strings"
217
+
"github.com/domonda/go-errs"
218
218
"github.com/domonda/go-pretty"
219
219
)
220
220
221
+
// Wrapper that adapts any interface to pretty.Printable
222
+
type printableAdapter struct {
223
+
format func(io.Writer)
224
+
}
225
+
226
+
func(pprintableAdapter) PrettyPrint(wio.Writer) {
227
+
p.format(w)
228
+
}
229
+
221
230
funcinit() {
222
-
// Configure the global DefaultPrinter used by go-errs and other packages
1.**Centrally control** how all values are formatted in your application
270
+
1.**Centrally control** how all values are formatted in error call stacks
262
271
2.**Protect sensitive data** in logs, error traces, and debug output
263
-
3.**Customize third-party package behavior** without modifying their code
272
+
3.**Customize error formatting** without modifying go-errs code
264
273
4.**Apply formatting rules** to types you don't control
265
274
266
-
**Note:**If `Printer.AsPrintable`is not set, the package-level `AsPrintable` function is used, which checks if the value implements the `Printable` interface.
275
+
**Note:**The `errs.Printer` variable is a `*pretty.Printer` that can be fully configured with custom settings like `MaxStringLength`, `MaxErrorLength`, `MaxSliceLength`, and `AsPrintable`.
0 commit comments