hlog

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 7 Imported by: 46

README

Warning: We cannot import anything from the hexa package in this package.

Documentation

Index

Constants

View Source
const ErrorStackLogKey = "_stack"

Variables

View Source
var Any = zap.Any
View Source
var Bool = zap.Bool
View Source
var Debug = global.Debug
View Source
var Duration = zap.Duration
View Source
var Enabled = global.Enabled
View Source
var Err = zap.Error
View Source
var Error = global.Error
View Source
var Info = global.Info
View Source
var Int = zap.Int
View Source
var Int32 = zap.Int32
View Source
var Int64 = zap.Int64
View Source
var Message = global.Message
View Source
var NamedErr = zap.NamedError
View Source
var String = zap.String
View Source
var Time = zap.Time
View Source
var Timep = zap.Timep
View Source
var Times = zap.Times
View Source
var Uint32 = zap.Uint32
View Source
var Uint64 = zap.Uint64
View Source
var Warn = global.Warn
View Source
var With = global.With
View Source
var WithCtx = global.WithCtx

Functions

func FieldToKeyVal

func FieldToKeyVal(f Field) (key string, val any)

func NewWriter

func NewWriter(l Logger, lvl Level) io.Writer

NewWriter creates a new io.Writer using logger. Logger param is optional and its default value is the global logger.

func SetGlobalLogger

func SetGlobalLogger(l Logger)

func ZapLevel

func ZapLevel(l Level) zapcore.Level

Types

type Field

type Field = zapcore.Field

func ErrStack

func ErrStack(err error) Field

ErrStack prints error stack(if exists) using logger

func MapToFields

func MapToFields(m map[string]any) []Field

type Level

type Level int8

Level can use by all drivers to map to the real level of their logger.

const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
)

func LevelFromString

func LevelFromString(l string) Level

LevelFromString converts string to log level.

func (Level) CanLog

func (l Level) CanLog(target Level) bool

func (Level) String

func (l Level) String() string

String returns a lower-case ASCII representation of the log level.

type Logger

type Logger interface {
	// Core function returns the logger core concrete struct.
	// this is because sometimes we need to convert one logger
	// interface to another and need to the concrete logger.
	Core() any

	// Enabled returns true if the logger covers the provided log level.
	// Each level covers itself and all higher logging levels.
	// For example the InfoLevel level covers WarnLevel and ErrorLevel.
	Enabled(lvl Level) bool

	// WithCtx gets the hexa context and some keyValues
	// and return new logger contains key values as
	// log fields.
	WithCtx(ctx context.Context, args ...Field) Logger

	// With method set key,values and return new logger
	// contains this key values as log fields.
	With(f ...Field) Logger

	// Debug log debug message.
	Debug(msg string, args ...Field)

	// Info log info message.
	Info(msg string, args ...Field)

	// Message log the value as a message.
	// Use this to send message to some loggers that just want to get messages.
	// all loggers see message as info and just add simple _message tag to it.
	// but some other loggers just log messages (like our sentry logger).
	// severity of Message it just like info.
	Message(msg string, args ...Field)

	// Warn log warning message.
	Warn(msg string, args ...Field)

	// Error log error message
	Error(msg string, args ...Field)
}

func GlobalLogger

func GlobalLogger() Logger

func NewPrinterDriver

func NewPrinterDriver(l Level) Logger

NewPrinterDriver returns new instance of hexa logger with printer driver. Note: printer logger driver is just for test purpose. dont use it in production.

type Writer

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

Writer is an io.Writer implementation using Logger. Some packages get standard Go log.Logger as their logger. The log.Logger gets as writer as param to use for writing logs. we can use this writer as the log.Logger's writer.

func (*Writer) Write

func (w *Writer) Write(in []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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