logger

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 11 Imported by: 0

README

logger

Convenience wrapper for zerolog and zwrap.

import "git.tcp.direct/kayos/logger"


const MaximumSyncErrors = 10000
func CreateDatedLogFile
func CreateDatedLogFile(directory, prefix string) (*os.File, error)
func CreateDatedLogFileCtx
func CreateDatedLogFileCtx(ctx context.Context, directory, prefix string) (*os.File, error)
func CreateDatedLogFileFormatted
func CreateDatedLogFileFormatted(directory, prefix string, format string) (*os.File, error)
func CreateDatedLogFileFormattedCtx
func CreateDatedLogFileFormattedCtx(ctx context.Context, directory, prefix string, format string) (*os.File, error)
func DisableSyncErrorAccounting
func DisableSyncErrorAccounting()

DisableSyncErrorAccounting disables storing and panicking upon exceeding the maximum sync error constant with regard to log files created with [CreateDatedLogfile] and managed by [StartPeriodicSync]. By default, this behavior is enabled.

func EnableSyncErrorAccounting
func EnableSyncErrorAccounting()

EnableSyncErrorAccounting enables storing and panicking upon exceeding the maximum sync error constant with regard to log files created with [CreateDatedLogfile] and managed by [StartPeriodicSync]. By default, this behavior is enabled.

func StartPeriodicSync
func StartPeriodicSync(ctx context.Context, f *os.File, dur time.Duration)
type Log
type Log struct {
}
func Global
func Global() *Log

Global acquires the assigned global logger.

IMPORTANT: you MUST make your instance of [Log] globally accecible by calling [WithGlobalPackageAccess].

func NewLogger
func NewLogger(writers ...io.Writer) *Log

NewLogger creates a logger that writes to the given writers, as well as pretty prints to stdout.

func NewLoggerNoColor
func NewLoggerNoColor(writers ...io.Writer) *Log
func NewQuietLogger
func NewQuietLogger(writers ...io.Writer) *Log

NewQuietLogger creates a logger that writes to the given writers with no console writer added.

func (*Log) AddWriter
func (l *Log) AddWriter(w io.Writer)

AddWriter adds a writer to the logger.

Note: this may have unintended consequences if certain [zwrap.Logger] configuration values have been set via [Log.C]. That said, the [zwrap.Logger] prefix value will be preserved.

func (*Log) C
func (l *Log) C() zwrap.ZWrapLogger

C returns a [zwrap.ZWrapLogger] which is a highly compattible interface to fit many other log intrefaces.

func (*Log) WithGlobalPackageAccess
func (l *Log) WithGlobalPackageAccess()
func (*Log) Z
func (l *Log) Z() *zerolog.Logger

Z rerturns a pointer to the underlying [zerolog.Logger].


Documentation

Index

Examples

Constants

View Source
const MaximumSyncErrors = 10000

Variables

This section is empty.

Functions

func CreateDatedLogFile

func CreateDatedLogFile(directory, prefix string) (*os.File, error)

func CreateDatedLogFileCtx

func CreateDatedLogFileCtx(ctx context.Context, directory, prefix string) (*os.File, error)

func CreateDatedLogFileFormatted

func CreateDatedLogFileFormatted(directory, prefix string, format string) (*os.File, error)

func CreateDatedLogFileFormattedCtx

func CreateDatedLogFileFormattedCtx(ctx context.Context, directory, prefix string, format string) (*os.File, error)

func DisableSyncErrorAccounting

func DisableSyncErrorAccounting()

DisableSyncErrorAccounting disables storing and panicking upon exceeding the maximum sync error constant with regard to log files created with [CreateDatedLogfile] and managed by StartPeriodicSync. By default, this behavior is enabled.

func EnableSyncErrorAccounting

func EnableSyncErrorAccounting()

EnableSyncErrorAccounting enables storing and panicking upon exceeding the maximum sync error constant with regard to log files created with [CreateDatedLogfile] and managed by StartPeriodicSync. By default, this behavior is enabled.

func StartPeriodicSync

func StartPeriodicSync(ctx context.Context, f *os.File, dur time.Duration)

Types

type Log

type Log struct {
	// contains filtered or unexported fields
}

func Global

func Global() *Log

Global acquires the assigned global logger.

IMPORTANT: you MUST make your instance of Log globally accecible by calling [WithGlobalPackageAccess].

func NewLogger

func NewLogger(writers ...io.Writer) *Log

NewLogger creates a logger that writes to the given writers, as well as pretty prints to stdout.

Example
f, _ := CreateDatedLogFile("./", "kayos_logger_example")
log := NewLogger(f)
log.C().SetPrefix(f.Name())
log.Z().Info().Msg("hello")
log.C().Info("world")
time.Sleep(50 * time.Millisecond)
Output:

func NewLoggerNoColor

func NewLoggerNoColor(writers ...io.Writer) *Log

func NewQuietLogger

func NewQuietLogger(writers ...io.Writer) *Log

NewQuietLogger creates a logger that writes to the given writers with no console writer added.

func (*Log) AddWriter

func (l *Log) AddWriter(w io.Writer)

AddWriter adds a writer to the logger.

Note: this may have unintended consequences if certain zwrap.Logger configuration values have been set via Log.C. That said, the zwrap.Logger prefix value will be preserved.

func (*Log) C

func (l *Log) C() zwrap.ZWrapLogger

C returns a zwrap.ZWrapLogger which is a highly compattible interface to fit many other log intrefaces.

func (*Log) WithGlobalPackageAccess

func (l *Log) WithGlobalPackageAccess()

func (*Log) Z

func (l *Log) Z() *zerolog.Logger

Z rerturns a pointer to the underlying zerolog.Logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL