package log
import "hauru.club/x/okrzeja/service/log"
Package log implements logging and telemetry utilities for okrzeja web server.
You configure logging in Okrzeja by setting up environmental variable OKRZEJA_ENV.
Available values for OKRZEJA_ENV are:
- PRD - it is default value. Logs will be formatted as JSON objects.
- DEV - optional option for development environment. Logs will be formatted as key, value pairs with timestamps.
- TEST - in the test environment, logs are disabled. You can enable them again, by setting up OKRZEJA_ENV to one from the above values.
Index ¶
- func ContextWithFields(ctx context.Context, fields ...slog.Attr) context.Context
- func Error(ctx context.Context, msg string, err error)
- func ErrorInfo(ctx context.Context, msg string, err error)
- func FirstAdminUser(ctx context.Context, id uuid.UUID, username string)
- func HTTPKnownError(ctx context.Context, err error)
- func NewLogFormatter() middleware.LogFormatter
- func ServerShutdown()
- func ServerStart(addr string)
- type Logger
Functions ¶
func ContextWithFields ¶
ContextWithFields fills context with logging key/value fields that will be used by every logging event that accepts context as argument.
If there are already some fields in the context, new fields will be appended.
func Error ¶
Error logs message about given error at the ERROR level.
func ErrorInfo ¶
ErrorInfo logs message about given error at the INFO level.
func FirstAdminUser ¶
FirstAdminUser is event fired when first user has been registered and marked as admin user as well.
func HTTPKnownError ¶
HTTPKnownError logs information about non-critical error from HTTP server that is well defined and expected.
For example: requested resource was not found or user doesn't have access to requested resources.
func NewLogFormatter ¶
func NewLogFormatter() middleware.LogFormatter
NewLogFormatter returns chi LogFormatter interface implementation for okrzeja internal logger.
func ServerShutdown ¶
func ServerShutdown()
ServerShutdown is event fired when HTTP server stops.
func ServerStart ¶
func ServerStart(addr string)
ServerStart is event fired when HTTP server starts.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger logs information about state of the server in the formatted way. The only safe way to initialize Logger is to use NewLogger.
It uses global logger instance of the application.
func NewLogger ¶
NewLogger is the only safe constructor for Logger.
You can pass optional source argument which is the source of the log messages.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
func (*Logger) Fatalf ¶
func (*Logger) Print ¶
func (l *Logger) Print(v ...interface{})
func (*Logger) Printf ¶
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Source Files ¶
events.go log.go logger.go
- Version
- v0.0.0-20231010043146-4292577f982b (latest)
- Published
- Oct 10, 2023
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 1 day ago –
Tools for package owners.