Documentation ¶
Index ¶
- Variables
- func Debug() *zerolog.Event
- func Error() *zerolog.Event
- func Fatal() *zerolog.Event
- func Info() *zerolog.Event
- func InitLogger(ctx context.Context, config Config) (err error)
- func InitRotatedfileWriterRotation(ctx context.Context, config RotatedFilewriterConfig, ...) (err error)
- func LeveledWriter(logger *zerolog.Logger, severity zerolog.Level) leveledWriter
- func NewCronLogger(logger *zerolog.Logger) *cronLoggerType
- func NewGcpLoggingWriter(ctx context.Context, config GcpLoggingConfig, ...) (writer zerolog.LevelWriter, err error)
- func Panic() *zerolog.Event
- func Trace() *zerolog.Event
- func Warn() *zerolog.Event
- type Config
- type GcpLoggingConfig
- type GcpLoggingSeverityMapType
- type GcpLoggingWriter
- type RotatedFilewriterConfig
- type WriterStructWithDefaultDestination
Constants ¶
This section is empty.
Variables ¶
var DefaultCronLogger cronLoggerType
var GcpLoggingSeverityMap = GcpLoggingSeverityMapType{ zerolog.TraceLevel: logging.Debug, zerolog.DebugLevel: logging.Debug, zerolog.InfoLevel: logging.Info, zerolog.WarnLevel: logging.Warning, zerolog.ErrorLevel: logging.Error, zerolog.FatalLevel: logging.Critical, zerolog.PanicLevel: logging.Critical, }
GcpLoggingSeverityMap contains the default zerolog.Level -> logging.Severity mappings.
var Logger zerolog.Logger = log.Logger
Logger is the default zerolog.Logger in this package. It should be initialized with InitLoggerr, otherwise it defaults to zerolog's standard default logger
It is used in this package's convenience functions like Info(), Error()
Functions ¶
func InitLogger ¶
InitLogger initializes the loggers in accordance to the configuration passed, which initiates the default exported Logger
While the configuration can be passed into this function, this function is intended to help configure a logger quickly from YAML based configuration.
refer tho the repo root's example.config.yaml for reference.
func InitRotatedfileWriterRotation ¶
func InitRotatedfileWriterRotation(ctx context.Context, config RotatedFilewriterConfig, destination ...*WriterStructWithDefaultDestination) (err error)
InitRotatedfileWriterRotation creates a new rotated file logger. Only one (optional) destination should be specified. If the (optional) destination is not specified, this rotates the packages' internal rotated file writer destination
This should be only called once
func LeveledWriter ¶ added in v0.0.7
LeveledWriter creates a io.Writer that writes to the log with the specified severity and the passed bytes as Msg
This makes it compatible with stdlib's Log Writer, while maintaining a severity level consistent with other logs
func NewCronLogger ¶
NewCronLogger accepts a custom zerolog logger and adapts it to a cron.Logger (github.com/robfig/cron/v3)
The rationale of providing an adaptor to the excellent cron is to provide a levelled and structured logging to the cron, since the cron's logger Info and Error interface is more akin to non structured loggers. This provides automatic recognition of field key if the even indexed elements is string, helping transforming it to a map[string]interface{} passed to zerolog.Logger as Interface()
func NewGcpLoggingWriter ¶
func NewGcpLoggingWriter(ctx context.Context, config GcpLoggingConfig, gcpLogOptions ...logging.LoggerOption) (writer zerolog.LevelWriter, err error)
Types ¶
type Config ¶
type Config struct { Destinations outputDestinationsSetting `yaml:"Destinations" env:"LOG_DESTINATIONS"` GcpLoggingConfig GcpLoggingConfig `yaml:"GcpLoggingConfig"` RotatedFileConfig RotatedFilewriterConfig `yaml:"RotatedFileConfig"` }
type GcpLoggingConfig ¶
type GcpLoggingConfig struct { ProjectId string `yaml:"ProjectId" env:"GCPLOGGING_PROJECTID"` LogId string `yaml:"LogId" env:"GCPLOGGING_LOGID"` ServiceAccountFilePath string `yaml:"ServiceAccountFilePath" env:"GOOGLE_APPLICATION_CREDENTIALS"` ServiceAccountJSON string `yaml:"ServiceAccountJSON" env:"GCPLOGGING_SERVICEACCOUNTJSON"` DefaultLabels map[string]string `yaml:"DefaultLabels" env:"GCPLOGGING_DEFAULTLABELS"` }
type GcpLoggingWriter ¶
type GcpLoggingWriter struct { zerolog.LevelWriter // contains filtered or unexported fields }
func (*GcpLoggingWriter) WriteLevel ¶
type RotatedFilewriterConfig ¶
type RotatedFilewriterConfig struct { FolderPath string `yaml:"FolderPath" env:"LOGROTATE_FOLDER_PATH"` RotateCronFrequency string `yaml:"RotateCronFrequency" env:"LOGROTATE_ROTATE_CRON_FREQUENCY"` FileNameFormat string `yaml:"FileNameFormat" env:"LOGROTATE_FILE_NAME_FORMAT"` MaxLogFilesKept int `yaml:"MaxLogFilesKept" env:"LOGROTATE_MAX_LOG_FILES_KEPT"` MinLogFilesKept int `yaml:"MinLogFilesKept" env:"LOGROTATE_MIN_LOG_FILES_KEPT"` MaxTotalLogFileSize string `yaml:"MaxTotalLogFileSize" env:"LOGROTATE_MAX_TOTAL_LOG_FILE_SIZE"` }
type WriterStructWithDefaultDestination ¶
type WriterStructWithDefaultDestination struct { // when set, will write to the destination // otherwise, will write to the default package rotatedLogFile Destination io.Writer // contains filtered or unexported fields }
WriterStructWithDefaultDestination provides a way to change the destination io.Writer while maintaining the pointer to the struct itself, allowing the log's destination writer to be changed without reinitiating the log itself.
Intended to be used with constructs like file rotation
func (*WriterStructWithDefaultDestination) SetOutput ¶
func (w *WriterStructWithDefaultDestination) SetOutput(output io.Writer)
SetOutput changes the destination. If the destination is io.WriteCloser, it will be closed before reassignment