rogger

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: BSD-3-Clause Imports: 15 Imported by: 25

Documentation

Index

Constants

View Source
const (
	Admin = "dyeUserManage"
)

Variables

This section is empty.

Functions

func AddDyeingUser added in v1.1.2

func AddDyeingUser(key string) error

AddDyeingUser add dyeing key to dyeingUserMap. key is separated by ','

func Colored

func Colored()

Colored enable colored level string when use console writer

func FlushLogger

func FlushLogger()

FlushLogger flush all log to disk.

func GetAllDyeingUser added in v1.1.2

func GetAllDyeingUser() []string

GetAllDyeingUser get all dyeing key from dyeingUserMap. key is separated by ','

func GetDyeingLogQueue added in v1.1.2

func GetDyeingLogQueue() *chan *dyeingLogValue

GetDyeingLogQueue get dyeingLogQueue, which will contain dyeing log if dyeing switch is on(by call DyeingSwitch). If dyeing switch is on, user must guarantee the dyeingLogQueue can be continuous consumed in case of goroutine blocked.

func GetFormat added in v1.3.3

func GetFormat() string

GetFormat get global log format and return string

func GetLevel added in v1.1.2

func GetLevel() string

GetLevel get global log level and return string

func HandleDyeingAdmin added in v1.1.2

func HandleDyeingAdmin(command string) (string, error)

HandleDyeingAdmin handle the dyeing key operation from admin. For example add a dyeing key. Send "dyeUserManage help" from admin, will see help.

func IsDyeingUser added in v1.1.2

func IsDyeingUser(key string) bool

IsDyeingUser return whether dyeingKey exist in dyeingUserMap

func RemoveDyeingUser added in v1.1.2

func RemoveDyeingUser(key string) error

RemoveDyeingUser remove dyeing key from dyeingUserMap. key is separated by ','

func SetCallerFlag added in v1.1.2

func SetCallerFlag(flag bool)

SetCallerFlag enable/disable caller string when write log

func SetCallerSkip added in v1.1.2

func SetCallerSkip(skip int)

SetCallerSkip sets the caller skip

func SetDyeingUser added in v1.1.2

func SetDyeingUser(v []string)

SetDyeingUser set dyeing key to dyeingUserMap(overwrite)

func SetFormat added in v1.3.3

func SetFormat(format LogFormat)

SetFormat sets the log format

func SetLevel

func SetLevel(level LogLevel)

SetLevel sets the log level

Types

type ConsoleWriter

type ConsoleWriter struct {
}

ConsoleWriter writes the logs to the console.

func (*ConsoleWriter) NeedPrefix

func (w *ConsoleWriter) NeedPrefix() bool

NeedPrefix shows whether needs the prefix for the console writer.

func (*ConsoleWriter) Write

func (w *ConsoleWriter) Write(v []byte)

type DateType

type DateType uint8

DateType is uint8

const (
	DAY DateType = iota
	HOUR
)

DAY for rotate log by day

type DateWriter

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

DateWriter rotate logs by date.

func NewDateWriter

func NewDateWriter(logpath, name string, dateType DateType, num int) *DateWriter

NewDateWriter returns a writer which keeps logs in hours or day format.

func (*DateWriter) NeedPrefix

func (w *DateWriter) NeedPrefix() bool

NeedPrefix shows whether needs prefix info for DateWriter or not.

func (*DateWriter) SetPrefix

func (w *DateWriter) SetPrefix(enable bool)

func (*DateWriter) Write

func (w *DateWriter) Write(v []byte)

Write method implement for the DateWriter

type HourWriter

type HourWriter struct {
}

HourWriter for rotate logs by hour

type JsonLog added in v1.3.3

type JsonLog struct {
	Pre   string `json:pre,omitempty`
	Time  string `json:"time"`
	Func  string `json:"func"`
	File  string `json:"file"`
	Level string `json:"level"`
	Msg   string `json:"msg"`
}

type LogFormat added in v1.3.3

type LogFormat uint8

LogFormat is uint8 format

const (
	Text LogFormat = iota
	Json
)

Format LogFormat

func GetLogFormat added in v1.3.3

func GetLogFormat() LogFormat

GetLogFormat get global log format

func (*LogFormat) String added in v1.3.3

func (lv *LogFormat) String() string

String returns the LogFormat to string.

type LogLevel

type LogLevel uint8

LogLevel is uint8 type

const (
	DEBUG LogLevel = iota
	INFO
	WARN
	ERROR
	OFF
)

DEBUG loglevel

func GetLogLevel added in v1.1.2

func GetLogLevel() LogLevel

GetLogLevel get global log level

func StringToLevel

func StringToLevel(level string) LogLevel

StringToLevel turns string to LogLevel

func (*LogLevel) String

func (lv *LogLevel) String() string

String returns the LogLevel to string.

type LogWriter

type LogWriter interface {
	Write(v []byte)
	NeedPrefix() bool
}

LogWriter is interface for different writer.

type Logger

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

Logger is the struct with name and writer.

func GetLogger

func GetLogger(name string) *Logger

GetLogger return an logger instance

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug logs interface in debug loglevel.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf logs interface in debug loglevel with formating string

func (*Logger) DyeingDebug added in v1.1.2

func (l *Logger) DyeingDebug(ctx context.Context, ext interface{}, v ...interface{})

func (*Logger) DyeingDebugf added in v1.1.2

func (l *Logger) DyeingDebugf(ctx context.Context, ext interface{}, format string, v ...interface{})

func (*Logger) DyeingError added in v1.1.2

func (l *Logger) DyeingError(ctx context.Context, ext interface{}, v ...interface{})

func (*Logger) DyeingErrorf added in v1.1.2

func (l *Logger) DyeingErrorf(ctx context.Context, ext interface{}, format string, v ...interface{})

func (*Logger) DyeingInfo added in v1.1.2

func (l *Logger) DyeingInfo(ctx context.Context, ext interface{}, v ...interface{})

func (*Logger) DyeingInfof added in v1.1.2

func (l *Logger) DyeingInfof(ctx context.Context, ext interface{}, format string, v ...interface{})

func (*Logger) DyeingWarn added in v1.1.2

func (l *Logger) DyeingWarn(ctx context.Context, ext interface{}, v ...interface{})

func (*Logger) DyeingWarnf added in v1.1.2

func (l *Logger) DyeingWarnf(ctx context.Context, ext interface{}, format string, v ...interface{})

func (*Logger) DyeingWritef added in v1.1.2

func (l *Logger) DyeingWritef(ctx context.Context, depth int, level LogLevel, ext interface{}, format string, v []interface{})

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error logs interface in Error loglevel

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf logs interface in Error loglevel with formating string

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info logs interface in Info loglevel.

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof logs interface in Infof loglevel with formating string

func (*Logger) IsConsoleWriter

func (l *Logger) IsConsoleWriter() bool

IsConsoleWriter returns whether is consoleWriter or not.

func (*Logger) SetConsole

func (l *Logger) SetConsole()

SetConsole sets the logger with console writer.

func (*Logger) SetDayRoller

func (l *Logger) SetDayRoller(logpath string, num int) error

SetDayRoller sets the logger to rotate by day, with max num files.

func (*Logger) SetFileRoller

func (l *Logger) SetFileRoller(logpath string, num int, sizeMB int) error

SetFileRoller sets the file rolled by size in MB, with max num of files.

func (*Logger) SetHourRoller

func (l *Logger) SetHourRoller(logpath string, num int) error

SetHourRoller sets the logger to rotate by hour, with max num files.

func (*Logger) SetLogName

func (l *Logger) SetLogName(name string)

SetLogName sets the log name

func (*Logger) SetLogPrefix added in v1.3.7

func (l *Logger) SetLogPrefix(pre string)

SetLogPrefix sets the log line prefix

func (*Logger) SetWriter

func (l *Logger) SetWriter(w LogWriter)

SetWriter sets the writer to the logger.

func (*Logger) Trace added in v1.2.0

func (l *Logger) Trace(msg string)

Trace log

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

Warn logs interface in warning loglevel

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Warnf logs interface in warning loglevel with formating string

func (*Logger) WriteJsonF added in v1.3.3

func (l *Logger) WriteJsonF(depth int, level LogLevel, format string, v []interface{}) *logValue

func (*Logger) WriteLineF added in v1.3.3

func (l *Logger) WriteLineF(depth int, level LogLevel, format string, v []interface{}) *logValue

func (*Logger) WriteLog added in v1.1.2

func (l *Logger) WriteLog(msg []byte)

WriteLog write log into log files ignore the log level and log prefix

func (*Logger) Writef added in v1.1.2

func (l *Logger) Writef(depth int, level LogLevel, format string, v []interface{})

type RollFileWriter

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

RollFileWriter struct for rotate logs by file size.

func NewRollFileWriter

func NewRollFileWriter(logpath, name string, num, sizeMB int) *RollFileWriter

NewRollFileWriter returns a RollFileWriter, rotate logs in sizeMB , and num files are keeped.

func (*RollFileWriter) NeedPrefix

func (w *RollFileWriter) NeedPrefix() bool

NeedPrefix shows need prefix or not.

func (*RollFileWriter) Write

func (w *RollFileWriter) Write(v []byte)

Write for writing []byte to the writer.

Jump to

Keyboard shortcuts

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