Documentation
ΒΆ
Index ΒΆ
- func WithLogrus() compogo.Option
- type Logger
- func (logger *Logger) AddHook(hook logrus.Hook)
- func (logger *Logger) Debug(i ...interface{})
- func (logger *Logger) Debugf(s string, i ...interface{})
- func (logger *Logger) Error(i ...interface{})
- func (logger *Logger) Errorf(s string, i ...interface{})
- func (logger *Logger) GetLogger(name string) logger.Logger
- func (logger *Logger) GetStdErr() *logrus.Logger
- func (logger *Logger) GetStdOut() *logrus.Logger
- func (logger *Logger) Info(i ...interface{})
- func (logger *Logger) Infof(s string, i ...interface{})
- func (logger *Logger) Panic(i ...interface{})
- func (logger *Logger) Panicf(s string, i ...interface{})
- func (logger *Logger) Print(i ...interface{})
- func (logger *Logger) Printf(s string, i ...interface{})
- func (logger *Logger) SetLevel(level logger.Level) error
- func (logger *Logger) Warn(i ...interface{})
- func (logger *Logger) Warnf(s string, i ...interface{})
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func WithLogrus ΒΆ
WithLogrus returns a Compogo option that integrates logrus as the application's logging system. It automatically:
- Registers the logger in the DI container
- Adds command-line flags for log level configuration
- Sets up the log level from configuration
- Injects the application name into the logger
Usage:
app := compogo.NewApp("myapp",
logrus.WithLogrus(),
// other options...
)
Types ΒΆ
type Logger ΒΆ added in v0.0.14
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps a logrus.Logger to implement the logger.Logger interface. It adds application name prefixing to all log messages and supports creating child loggers for sub-components.
The decorator maintains separate stdout and stderr loggers, allowing different outputs for different log levels if needed.
func NewLogger ΒΆ added in v0.0.14
func NewLogger() *Logger
NewLogger creates a new Logger instance with default logrus loggers. Both stdout and stderr loggers are initialized with default settings. The actual log level will be set later via SetLevel.
func (*Logger) AddHook ΒΆ added in v0.0.14
AddHook adds a logrus hook to both stdout and stderr loggers. This enables integration with external logging systems like Sentry, file logging, or custom formatters.
func (*Logger) Debug ΒΆ added in v0.0.14
func (logger *Logger) Debug(i ...interface{})
Debug logs a message at Debug level. The application name is prepended to the arguments. If this is a child logger, the call is delegated to the parent.
func (*Logger) Debugf ΒΆ added in v0.0.14
Debugf logs a formatted message at Debug level. The message is prefixed with the application name in brackets. If this is a child logger, the call is delegated to the parent.
func (*Logger) Error ΒΆ added in v0.0.14
func (logger *Logger) Error(i ...interface{})
Error logs a message at Error level. The application name is prepended to the arguments. If this is a child logger, the call is delegated to the parent.
func (*Logger) Errorf ΒΆ added in v0.0.14
Errorf logs a formatted message at Error level. The message is prefixed with the application name in brackets. If this is a child logger, the call is delegated to the parent.
func (*Logger) GetLogger ΒΆ added in v0.0.14
GetLogger creates a child logger with the given name. The child logger will prefix all messages with its own name in addition to the parent's name, creating a chain like: [app] [child] message
This is useful for sub-components that need their own log identity while still being part of the main application.
func (*Logger) GetStdErr ΒΆ added in v0.0.14
GetStdErr returns the underlying logrus.Logger used for error output. This can be used for advanced configuration or adding hooks.
func (*Logger) GetStdOut ΒΆ added in v0.0.14
GetStdOut returns the underlying logrus.Logger used for standard output. This can be used for advanced configuration or adding hooks.
func (*Logger) Info ΒΆ added in v0.0.14
func (logger *Logger) Info(i ...interface{})
Info logs a message at Info level. The application name is prepended to the arguments. If this is a child logger, the call is delegated to the parent.
func (*Logger) Infof ΒΆ added in v0.0.14
Infof logs a formatted message at Info level. The message is prefixed with the application name in brackets. If this is a child logger, the call is delegated to the parent.
func (*Logger) Panic ΒΆ added in v0.0.14
func (logger *Logger) Panic(i ...interface{})
Panic logs a message at Panic level and then panics. The application name is prepended to the arguments. If this is a child logger, the call is delegated to the parent.
func (*Logger) Panicf ΒΆ added in v0.0.14
Panicf logs a formatted message at Panic level and then panics. The message is prefixed with the application name in brackets. If this is a child logger, the call is delegated to the parent.
func (*Logger) Print ΒΆ added in v0.0.14
func (logger *Logger) Print(i ...interface{})
Print logs a message at Info level (for compatibility). The application name is prepended to the arguments. If this is a child logger, the call is delegated to the parent.
func (*Logger) Printf ΒΆ added in v0.0.14
Printf logs a formatted message at Info level (for compatibility). The message is prefixed with the application name in brackets. If this is a child logger, the call is delegated to the parent.
func (*Logger) SetLevel ΒΆ added in v0.0.14
SetLevel changes the logging level for both stdout and stderr loggers. The level is converted from Compogo's logger.Level to logrus.Level using the LoggerLevelToLogrusLevel mapper. Returns an error if the level conversion fails.