logger

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

README

package logger

package logger setup log configuration before application starts, It is usually used in function init().

Usage:

import "github.com/infavor/gox/logger"

func init() {
	logger.Init()
}

Documentation

Overview

Copyright (C) 2019 tisnyo <tisnyo@gmail.com>.

package logger is used for initializing logrus.

Index

Constants

View Source
const (
	HOUR int = iota
	DAY
	MONTH
	YEAR
	MB64
	MB128
	MB256
	MB512
	MB1024
	SIZE_NO_LIMIT = 0
)

Variables

View Source
var (
	LogFileName string

	EnableCache = false
)

Functions

func Debug

func Debug(args ...interface{})

Debug log.

func Error

func Error(args ...interface{})

Error log.

func FakeWriteLen

func FakeWriteLen(len1 int64)

FakeWriteLen for test.

func Fatal

func Fatal(args ...interface{})

Fatal log.

func Info

func Info(args ...interface{})

Info log.

func Infof

func Infof(format string, args ...interface{})

func Init

func Init(config *Config)

Init initialize logrus logger.

func IsInitialized

func IsInitialized() bool

IsInitialized return if logger was initialized before.

func Panic

func Panic(args ...interface{})

Panic log.

func PrintColor

func PrintColor(p []byte)

PrintColor pints colorable output to console.

func Sync

func Sync()

Sync synchronizes log buffer to log file.

It is usually called before the process shutdown.

func Trace

func Trace(args ...interface{})

Trace log.

func Warn

func Warn(args ...interface{})

Warn log.

Types

type Config

type Config struct {
	Formatter          logrus.Formatter
	Level              Level
	Write2File         bool
	AlwaysWriteConsole bool // 是否总是将日志写入控制台
	EnableCache        bool
	RollingFileDir     string
	RollingFileName    string
	RollingPolicy      []int
}

Config is config for initializing logger.

type DefaultTextFormatter

type DefaultTextFormatter struct {
}

SimpleTextFormatter is default text formatter.

[I] 2019-12-12 12:12:12,221 [xxx.go] xxx

func (*DefaultTextFormatter) Format

func (f *DefaultTextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats logs.

type Level

type Level uint32

Level type

const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.

func GetLogLevel

func GetLogLevel() Level

type NoneTextFormatter

type NoneTextFormatter struct {
}

NoneTextFormatter is the simple version of log format.

xxx

func (*NoneTextFormatter) Format

func (f *NoneTextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats logs.

type ShortTextFormatter

type ShortTextFormatter struct {
}

ShortTextFormatter is the simple version of log format.

[I] xxx

func (*ShortTextFormatter) Format

func (f *ShortTextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats logs.

type SimpleTextFormatter

type SimpleTextFormatter struct {
}

SimpleTextFormatter is the simple version of log format.

[I] 12:12:12 xxx

func (*SimpleTextFormatter) Format

func (f *SimpleTextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats logs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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