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, }) }
Output:
Index ¶
- Variables
- func AsyncLogging() func()
- func Configure(blk ConfigurationFunc) struct{}
- func ContextWith(ctx context.Context, lds ...logging.Detail) context.Contextdeprecated
- func Debug(ctx context.Context, msg string, ds ...logging.Detail)
- func ErrField(err error) logging.Detaildeprecated
- 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.Detaildeprecated
- 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 Fieldsdeprecated
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
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") }
Output:
func Configure ¶ added in v0.218.0
func Configure(blk ConfigurationFunc) struct{}
func Debug ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Debug(ctx, "foo") }
Output:
func Error ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Error(ctx, "foo") }
Output:
func Fatal ¶
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/logger" ) func main() { ctx := context.Background() logger.Fatal(ctx, "foo") }
Output:
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") }
Output:
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 }
Output:
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)) }
Output:
Types ¶
type ConfigurationFunc ¶ added in v0.218.0
Click to show internal directories.
Click to hide internal directories.