Documentation ¶
Overview ¶
Package logger provides tooling for structured logging. With logger, you can use context to add logging details to your call stack.
Example (WithDetails) ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Info(ctx, "foo", logger.Details{ "userID": 42, "accountID": 24, }) }
Output:
Index ¶
- func ContextWithDetails(ctx context.Context, details Details) context.Context
- func Debug(ctx context.Context, msg string, ds ...Details)
- func Error(ctx context.Context, msg string, ds ...Details)
- func Fatal(ctx context.Context, msg string, ds ...Details)
- func Info(ctx context.Context, msg string, ds ...Details)
- func Stub(tb testingTB) *bytes.Buffer
- func Warn(ctx context.Context, msg string, ds ...Details)
- type Details
- type Logger
- func (l Logger) Debug(ctx context.Context, msg string, ds ...Details)
- func (l Logger) Error(ctx context.Context, msg string, ds ...Details)
- func (l Logger) Fatal(ctx context.Context, msg string, ds ...Details)
- func (l Logger) Info(ctx context.Context, msg string, ds ...Details)
- func (l Logger) Warn(ctx context.Context, msg string, ds ...Details)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithDetails ¶
Example ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" ) func main() { ctx := context.Background() ctx = logger.ContextWithDetails(ctx, logger.Details{ "foo": "bar", "baz": "qux", }) logger.Info(ctx, "message") // will have details from the context }
Output:
func Debug ¶
Example ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Debug(ctx, "foo") }
Output:
func Error ¶
Example ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Error(ctx, "foo") }
Output:
func Fatal ¶
Example ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Fatal(ctx, "foo") }
Output:
func Info ¶
Example ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Info(ctx, "foo") }
Output:
func Stub ¶
Stub the logger.Default and return the buffer where the logging output will be recorded. Stub will restore the logger.Default after the test.
Example ¶
package main import ( "github.com/adamluzsi/frameless/pkg/logger" "strings" "testing" ) func main() { var tb testing.TB buf := logger.Stub(tb) // stub will clean up after itself when the test is finished logger.Info(nil, "foo") strings.Contains(buf.String(), "foo") // true }
Output:
Types ¶
type Details ¶
Click to show internal directories.
Click to hide internal directories.