Documentation
¶
Index ¶
- Constants
- Variables
- func Assert(check bool, msg string, args ...interface{})
- func Fatal(msg string, args ...interface{})
- func Format(msg string, args ...interface{}) string
- func FormatLogfmtInt64(n int64) string
- func FormatLogfmtUint64(n uint64) string
- func GetStackInfo(omitCalls int) string
- func Init(config *LogConfig)
- func Jsonify(v interface{}) _Jsonify
- func SetLevel(target Level)
- func SimpleFormat(value interface{}) string
- func StackInfo(omitCalls int, msg string, args ...interface{}) string
- func Stringify(value interface{}) string
- func Verbosify(v interface{}) _Verbosify
- type FileWriter
- type Float
- type Handle
- type HandleIf
- type Hex
- type Level
- type LogConfig
- type Logger
- func (l *Logger) Assert(check bool, msg string, args ...interface{})
- func (l *Logger) Dump(level Level, arg interface{})
- func (l *Logger) Fatal(msg string, args ...interface{})
- func (l *Logger) Json(level Level, arg interface{})
- func (l *Logger) Level() Level
- func (l *Logger) Log(level Level, msg string, args ...interface{})
- func (l *Logger) Logf(level Level, msg string, args ...interface{})
- func (l *Logger) Output(level Level, msg string)
- func (l *Logger) Outputf(level Level, msg string, args ...interface{})
- func (l *Logger) Println(level Level, args ...interface{})
- func (l *Logger) SetLevel(target Level)
- func (l *Logger) Write(bytes []byte, newline bool)
Constants ¶
const TimeFormat = "06-01-02MST15:04:05.000"
Time format used in loggers
Variables ¶
var ( // Log levels as string Levels = [6]string{"TRACE", "DEBUG", "VERBO", "INFO", "WARN", "ERROR"} FormatValue func(interface{}) string = SimpleFormat )
var ( // Global handles and root logger Root *Logger // Output raw strings Output func(Level, string) // Output any variables, like fmt.Println Println func(Level, ...interface{}) // Output common logs in key=value format or string with args Log, Logf, Outputf func(Level, string, ...interface{}) // Dump args details as json string, Dump with indent Json, Dump func(Level, interface{}) JsonIf, DumpIf (func(bool, Level, interface{})) // Global handles for different levels Trace, Debug, Verbose, Info, Warn, Error Handle // Global handleIfs for different levels TraceIf, DebugIf, VerboseIf, InfoIf, WarnIf, ErrorIf HandleIf )
Default log file flag
Functions ¶
func Fatal ¶
func Fatal(msg string, args ...interface{})
Fatal will exit the process after the log message is printed with stack info attached
func FormatLogfmtInt64 ¶
FormatLogfmtInt64 formats n with thousand separators.
func FormatLogfmtUint64 ¶
FormatLogfmtUint64 formats n with thousand separators.
func GetStackInfo ¶
Dump stack info with hiding logger internal calls
func Init ¶
func Init(config *LogConfig)
Initialize global logger Read default log level from config or global env variable LOG_LEVEL
func Jsonify ¶ added in v0.0.9
func Jsonify(v interface{}) _Jsonify
Jsonify turns a value into Lazy Jsonify
func SimpleFormat ¶ added in v0.0.10
func SimpleFormat(value interface{}) string
Types ¶
type FileWriter ¶
type FileWriter struct { LogConfig // Embed the config // contains filtered or unexported fields }
FileWriter defines a file writer instance
func NewFileWriter ¶
func NewFileWriter(c LogConfig) (w *FileWriter, err error)
Create a file writer instance with a log config
func (*FileWriter) Close ¶ added in v0.0.3
func (w *FileWriter) Close() (err error)
Close will try to close the file object
type LogConfig ¶
type LogConfig struct { // Logger level to use Level Level MaxSize uint // max bytes in MB MaxFiles uint // max log files Path string // main log file path }
Logger config
type Logger ¶
type Logger struct { // Logger writer lock to avoid race conditions sync.Mutex // Logger handles Trace, Debug, Verbose, Info, Warn, Error Handle // Logger handleIfs TraceIf, DebugIf, VerboseIf, InfoIf, WarnIf, ErrorIf HandleIf JsonIf, DumpIf func(bool, Level, interface{}) // contains filtered or unexported fields }
Logger defines the logger instance
func (*Logger) Outputf ¶ added in v0.0.6
Output a raw string in format with a custom level, just like fmt.Printf with newline appended