typelog

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 10 Imported by: 42

Documentation

Overview

Package typelog is a slog modified for extra static type safety and extra boilerplating out of the box

Index

Constants

View Source
const (
	TOOL_NAME = "typelog"
)

Variables

View Source
var RegisteredLoggers []*Logger

RegisteredLoggers leaves option for end applications to access all registered loggers and choosing their own log levels to override for them

Functions

func CompL

func CompL[T any, V any](objs []T, lambda func(x T) V) []V

func GetCallingFile

func GetCallingFile(level int) string

func Group

func Group(name string, attrs ...slog.Attr) slog.Attr

func IsMsgEnabled

func IsMsgEnabled(current_level, msg_level LogLevel) bool

func LevelToInt

func LevelToInt(level LogLevel) int

func StructToMap

func StructToMap(somestruct any) map[string]any

func TurnMapToAttrs

func TurnMapToAttrs(params map[string]any) []slog.Attr

func TurnStructToAttrs

func TurnStructToAttrs(somestruct any) []slog.Attr

Types

type LogAtrs

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

func (*LogAtrs) Append

func (s *LogAtrs) Append(params ...slog.Attr)

func (LogAtrs) Render

func (s LogAtrs) Render() []SlogAttr

type LogLevel

type LogLevel string
const (
	LEVEL_DEBUG        LogLevel = "DEBUG"
	LEVEL_INFO         LogLevel = "INFO"
	LEVEL_WARN         LogLevel = "WARN"
	LEVEL_ERROR        LogLevel = "ERROR"
	LEVEL_FATAL        LogLevel = "FATAL"
	LEVEL_DEFAULT_WARN LogLevel = ""
)

func (LogLevel) ToStr

func (l LogLevel) ToStr() string

type LogType

type LogType func(r *LogAtrs)

func Actual

func Actual(value any) LogType

func Any

func Any(key string, value any) LogType

func Args

func Args(value []string) LogType

func Bool

func Bool(key string, value bool) LogType

func Bytes

func Bytes(key string, value []byte) LogType

func Expected

func Expected(value any) LogType

func Float32

func Float32(key string, value float32) LogType

func Float64

func Float64(key string, value float64) LogType

func Int

func Int(key string, value int) LogType

func Int64

func Int64(key string, value int64) LogType

func Items

func Items[T any](item_name string, value []T) LogType

func Map

func Map(value map[string]any) LogType

func NestedMap added in v0.4.0

func NestedMap(key string, value map[string]any) LogType

func NestedStruct

func NestedStruct(key string, value StructType) LogType

func OptError

func OptError(err error) LogType

func Records

func Records[T any](value []T) LogType

func String

func String(key string, value string) LogType

func Struct

func Struct(value StructType) LogType

func TestParam

func TestParam(value int) LogType

func Time

func Time(key string, value time.Time) LogType

type Logger

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

func NewLogger

func NewLogger(
	name string,
	options ...LoggerParam,
) *Logger

func (*Logger) CheckDebug

func (l *Logger) CheckDebug(err error, msg string, opts ...LogType) bool

func (*Logger) CheckError

func (l *Logger) CheckError(err error, msg string, opts ...LogType) bool

func (*Logger) CheckFatal

func (l *Logger) CheckFatal(err error, msg string, opts ...LogType)

CheckFatal has shorter error output in comparison to CheckPanic

func (*Logger) CheckPanic

func (l *Logger) CheckPanic(err error, msg string, opts ...LogType)

func (*Logger) CheckWarn

func (l *Logger) CheckWarn(err error, msg string, opts ...LogType) bool

func (*Logger) Debug

func (l *Logger) Debug(msg string, opts ...LogType)

func (*Logger) Error

func (l *Logger) Error(msg string, opts ...LogType)

Error is bad but program can recover from it

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, opts ...LogType)

Fatal when encountered, Program is not allowed to run further with fatal

func (*Logger) GetName

func (l *Logger) GetName() string

func (*Logger) Info

func (l *Logger) Info(msg string, opts ...LogType)

func (*Logger) Initialized

func (l *Logger) Initialized() *Logger

func (*Logger) OverrideOption

func (l *Logger) OverrideOption(options ...LoggerParam) *Logger

OverrideOption for overrides by external libraries

func (*Logger) Panic

func (l *Logger) Panic(msg string, opts ...LogType)

func (*Logger) Warn

func (l *Logger) Warn(msg string, opts ...LogType)

Warn is for just potentially bad behavior to be aware of

func (*Logger) WithFields

func (l *Logger) WithFields(opts ...LogType) *Logger

type LoggerParam

type LoggerParam func(r *Logger)

func WithFileShowing

func WithFileShowing(state bool) LoggerParam

func WithIoWriter added in v0.6.0

func WithIoWriter(writer io.Writer) LoggerParam

func WithJsonFormat

func WithJsonFormat(state bool) LoggerParam

func WithLogLevel

func WithLogLevel(log_level_str LogLevel) LoggerParam

func WithLogLevelStr

func WithLogLevelStr(log_level_str string) LoggerParam

type SlogAttr

type SlogAttr = any

type StructType added in v0.3.3

type StructType = any

type TypelogEnvs added in v0.6.1

type TypelogEnvs struct {
	EnableJson        bool
	EnableFileShowing bool
}
var Env TypelogEnvs = TypelogEnvs{
	EnableJson:        os.Getenv(strings.ToUpper(TOOL_NAME)+"_LOG_JSON") == "true",
	EnableFileShowing: os.Getenv(strings.ToUpper(TOOL_NAME)+"_LOG_FILE_SHOWING") == "true",
}

Jump to

Keyboard shortcuts

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