Documentation
¶
Overview ¶
Example (WithDetails) ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" "go.llib.dev/frameless/pkg/logging" ) func main() { ctx := context.Background() logger.Info(ctx, "foo", logging.Fields{ "userID": 42, "accountID": 24, }) }
Index ¶
- Variables
- func AsyncLogging() func()
- func Configure(blk ConfigurationFunc) struct{}
- func ContextWith(ctx context.Context, lds ...logging.Detail) context.Context
- func Debug(ctx context.Context, msg string, ds ...logging.Detail)
- func ErrField(err error) logging.Detail
- func Error(ctx context.Context, msg string, ds ...logging.Detail)
- func Fatal(ctx context.Context, msg string, ds ...logging.Detail)
- func Field(key string, value any) logging.Detail
- func Hijack(fn logging.HijackFunc)
- func Info(ctx context.Context, msg string, ds ...logging.Detail)
- func Stub(tb testingTB, optionalConfiguration ...ConfigurationFunc) logging.StubOutput
- func Testing(tb testingTB)
- func Warn(ctx context.Context, msg string, ds ...logging.Detail)
- type ConfigurationFunc
- type Fields
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var LogWithTB = Testing
LogWithTB is backward compatibility.
DEPRECATED: use logger.Testing instead
Functions ¶
func AsyncLogging ¶
func AsyncLogging() func()
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() defer logger.AsyncLogging()() logger.Info(ctx, "this log message is written out asynchronously") }
func Configure ¶ added in v0.218.0
func Configure(blk ConfigurationFunc) struct{}
func ContextWith ¶
ContextWith
DEPRECATED: functionality is moved to logging package, use it from there.
func Debug ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Debug(ctx, "foo") }
func Error ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Error(ctx, "foo") }
func Fatal ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Fatal(ctx, "foo") }
func Field ¶
Field creates a single key value pair based logging detail. It will enrich the log entry with a value in the key you gave.
DEPRECATED: functionality is moved to logging package, use it from there.
func Hijack ¶ added in v0.218.0
func Hijack(fn logging.HijackFunc)
func Info ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Info(ctx, "foo") }
func Stub ¶
func Stub(tb testingTB, optionalConfiguration ...ConfigurationFunc) logging.StubOutput
Stub the logger.Default and return the buffer where the logging output will be recorded. Stub will restore the logger.Default after the test. optionally, the stub logger can be further configured by passing a configuration function block
Example ¶
package main import ( "context" "strings" "testing" "go.llib.dev/frameless/pkg/logger" ) func main() { var tb testing.TB buf := logger.Stub(tb) // stub will clean up after itself when the test is finished logger.Info(context.Background(), "foo") strings.Contains(buf.String(), "foo") // true }
func Testing ¶ added in v0.218.0
func Testing(tb testingTB)
Testing pipes all application log generated during the test execution through the testing.TB's Log method. Testing meant to help debugging your application during your TDD flow.
Example ¶
package main import ( "context" "testing" "go.llib.dev/frameless/pkg/logger" "go.llib.dev/frameless/pkg/logging" ) func main() { var tb testing.TB logger.Testing(tb) // somewhere in your application logger.Debug(context.Background(), "the logging message", logging.Field("bar", 24)) }