log

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte     = 1.0
	Kilobyte = 1024 * Byte
	Megabyte = 1024 * Kilobyte
	Gigabyte = 1024 * Megabyte
	Terabyte = 1024 * Gigabyte
)
View Source
const (
	Prefix          = "logging_"
	Writers         = "writers"
	URL             = "url"
	CallerLevelSkip = "caller_level_skip"
	LogLevel        = "log_level"
	LogFile         = "log_file"
	MaxSize         = "max_size"
	Format          = "format"
	Daily           = "daily"
	ExpireDays      = "expire_days"
	Compress        = "compress"
	Separator       = "_"
)
View Source
const (
	DebugFlag = false

	DefaultFile       = ""
	DefaultWriter     = "CONSOLE"
	DefaultURL        = "http://127.0.0.1:8000"
	DefaultLevel      = "INFO"
	DefaultFormat     = "LONG"
	DefaultMaxSize    = 104857600
	DefaultDaily      = true
	DefaultExpireDays = uint(30)
	DefaultCompress   = true
)
View Source
const (
	LogFormat            = "%s - %s(%s) -- %s"
	InvokeRecursiveLevel = 3
)
View Source
const (
	DateFormatDay = "2006-01-02"
	OneDay        = 24 * time.Hour
)
View Source
const (
	SizeRotate = iota
	DailyRotate
)
View Source
const (
	HTTPPost         = "POST"
	UserAgent        = "User-Agent"
	ContentType      = "Content-Type"
	ContentTypeValue = "application/x-www-form-urlencoded; param=value"
)
View Source
const (
	LongLogFormat    = "%s %s [%s] - %s\n"
	ShortLogFormat   = "%s %s - %s\n"
	PlainLogFormat   = "%s %s\n"
	DateFormat       = "2006-01-02 15:04:05.000"
	FileWriterTag    = "FILE"
	ConsoleWriterTag = "CONSOLE"
	HTTPWriterTag    = "HTTP"
)
View Source
const (
	FATAL = iota
	ERROR
	WARN
	INFO
	DEBUG
)
View Source
const (
	ROOT = "root"
)

Variables

View Source
var (
	RootLogger = newRootLogger()
)

Functions

func Btoi

func Btoi(s string) (uint64, error)

ToMegabyte parses a string formatted by ByteSize as megabytes

func Debug

func Debug(content interface{}, args ...interface{})

func Error

func Error(content interface{}, args ...interface{})

func Fatal

func Fatal(content string, args ...interface{})

func Info

func Info(content interface{}, args ...interface{})

func IsDebugEnable

func IsDebugEnable() bool

func IsErrorEnable

func IsErrorEnable() bool

func IsInfoEnable

func IsInfoEnable() bool

func IsWarnEnable

func IsWarnEnable() bool

func Itob

func Itob(b uint64) string

ByteSize returns a human readable byte string, of the format 10M, 12.5K, etc. The following units are available:

T Terabyte
G Gigabyte
M Megabyte
K Kilobyte

the unit that would result in printing the smallest whole number is always chosen

func LoadFromFile

func LoadFromFile(configFile string) error

func Registry

func Registry(configFile string)

func RegistryFromConfig

func RegistryFromConfig(tag string, config *Config)

func RegistryLoggerImplement

func RegistryLoggerImplement(name string, factory LoggerFactory)

func Warn

func Warn(content interface{}, args ...interface{})

Types

type Appender

type Appender interface {
	AddWriter(name string, writer LogWriter)

	Log(level Level, name string, content interface{}, args ...interface{})

	Close()
}

type Config

type Config struct {
	Writers         string
	CallerLevelSkip uint
	URL             string
	Level           string
	File            string
	MaxSize         uint64
	Format          string
	Daily           bool
	ExpireDays      uint
	Compress        bool
}

type ConsoleWriter

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

func (*ConsoleWriter) Close

func (w *ConsoleWriter) Close()

func (*ConsoleWriter) GetCallerLevelSkip

func (w *ConsoleWriter) GetCallerLevelSkip() uint

func (*ConsoleWriter) Log

func (w *ConsoleWriter) Log(r LogRecord)

func (*ConsoleWriter) Open

func (w *ConsoleWriter) Open() error

type DefaultLogRecord

type DefaultLogRecord struct {
	Level      Level
	RecordTime time.Time
	Source     string
	LogName    string
	Content    string
}

func (*DefaultLogRecord) Format

func (r *DefaultLogRecord) Format(format string) string

func (*DefaultLogRecord) GetCreated

func (r *DefaultLogRecord) GetCreated() time.Time

func (*DefaultLogRecord) GetLevel

func (r *DefaultLogRecord) GetLevel() Level

type DefaultLogger

type DefaultLogger struct{}

func (*DefaultLogger) Close

func (logger *DefaultLogger) Close()

func (*DefaultLogger) Debug

func (logger *DefaultLogger) Debug(content interface{}, args ...interface{})

func (*DefaultLogger) Error

func (logger *DefaultLogger) Error(content interface{}, args ...interface{})

func (*DefaultLogger) Fatal

func (logger *DefaultLogger) Fatal(content interface{}, args ...interface{})

func (*DefaultLogger) Info

func (logger *DefaultLogger) Info(content interface{}, args ...interface{})

func (*DefaultLogger) IsDebugEnable

func (logger *DefaultLogger) IsDebugEnable() bool

func (*DefaultLogger) IsErrorEnable

func (logger *DefaultLogger) IsErrorEnable() bool

func (*DefaultLogger) IsInfoEnable

func (logger *DefaultLogger) IsInfoEnable() bool

func (*DefaultLogger) IsWarnEnable

func (logger *DefaultLogger) IsWarnEnable() bool

func (*DefaultLogger) Log

func (logger *DefaultLogger) Log(content interface{}, args ...interface{})

func (*DefaultLogger) Warn

func (logger *DefaultLogger) Warn(content interface{}, args ...interface{})

type FileLogWriter

type FileLogWriter struct {
	MaxSize    uint64
	Daily      bool
	ExpireDays uint
	Compress   bool
	// contains filtered or unexported fields
}

func (*FileLogWriter) Close

func (w *FileLogWriter) Close()

func (*FileLogWriter) GetCallerLevelSkip

func (w *FileLogWriter) GetCallerLevelSkip() uint

func (*FileLogWriter) Log

func (w *FileLogWriter) Log(r LogRecord)

func (*FileLogWriter) Open

func (w *FileLogWriter) Open() error

type HTTPLogWriter

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

func (*HTTPLogWriter) Close

func (w *HTTPLogWriter) Close()

func (*HTTPLogWriter) GetCallerLevelSkip

func (w *HTTPLogWriter) GetCallerLevelSkip() uint

func (*HTTPLogWriter) Log

func (w *HTTPLogWriter) Log(r LogRecord)

func (*HTTPLogWriter) Open

func (w *HTTPLogWriter) Open() error

type JLogger

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

func (*JLogger) Close

func (l *JLogger) Close()

func (*JLogger) Debug

func (l *JLogger) Debug(content interface{}, args ...interface{})

func (*JLogger) Error

func (l *JLogger) Error(content interface{}, args ...interface{})

func (*JLogger) Fatal

func (l *JLogger) Fatal(content interface{}, args ...interface{})

func (*JLogger) Info

func (l *JLogger) Info(content interface{}, args ...interface{})

func (*JLogger) IsDebugEnable

func (l *JLogger) IsDebugEnable() bool

func (*JLogger) IsErrorEnable

func (l *JLogger) IsErrorEnable() bool

func (*JLogger) IsInfoEnable

func (l *JLogger) IsInfoEnable() bool

func (*JLogger) IsWarnEnable

func (l *JLogger) IsWarnEnable() bool

func (*JLogger) Log

func (l *JLogger) Log(content interface{}, args ...interface{})

func (*JLogger) Warn

func (l *JLogger) Warn(content interface{}, args ...interface{})

type Level

type Level int8

func (Level) String

func (l Level) String() string

type Log

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

func GetLogger

func GetLogger(name string) *Log

func (*Log) Close

func (l *Log) Close()

func (*Log) Debug

func (l *Log) Debug(content interface{}, args ...interface{})

func (*Log) Error

func (l *Log) Error(content interface{}, args ...interface{})

func (*Log) Fatal

func (l *Log) Fatal(content interface{}, args ...interface{})

func (*Log) Info

func (l *Log) Info(content interface{}, args ...interface{})

func (*Log) IsDebugEnable

func (l *Log) IsDebugEnable() bool

func (*Log) IsErrorEnable

func (l *Log) IsErrorEnable() bool

func (*Log) IsInfoEnable

func (l *Log) IsInfoEnable() bool

func (*Log) IsWarnEnable

func (l *Log) IsWarnEnable() bool

func (*Log) Log

func (l *Log) Log(content interface{}, args ...interface{})

func (*Log) Warn

func (l *Log) Warn(content interface{}, args ...interface{})

type LogRecord

type LogRecord interface {
	Format(format string) string

	GetLevel() Level

	GetCreated() time.Time
}

type LogWriter

type LogWriter interface {
	Log(record LogRecord)

	Open() error

	Close()

	GetCallerLevelSkip() uint
}

func NewConsoleLogWriter

func NewConsoleLogWriter(tag string) (LogWriter, error)

func NewFileLogWriter

func NewFileLogWriter(tag string) (LogWriter, error)

func NewHTTPLogWriter

func NewHTTPLogWriter(tag string) (LogWriter, error)

type Logger

type Logger interface {
	Fatal(content interface{}, args ...interface{})

	IsErrorEnable() bool

	Error(content interface{}, args ...interface{})

	IsWarnEnable() bool

	Warn(content interface{}, args ...interface{})

	IsInfoEnable() bool

	Info(content interface{}, args ...interface{})

	IsDebugEnable() bool

	Debug(content interface{}, args ...interface{})

	Log(content interface{}, args ...interface{})

	Close()
}

func CreateDefaultLogger

func CreateDefaultLogger(name string) Logger

func CreateJLogger

func CreateJLogger(name string) Logger

type LoggerFactory

type LoggerFactory func(string) Logger

type SyncAppender

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

func (*SyncAppender) AddWriter

func (s *SyncAppender) AddWriter(name string, writer LogWriter)

func (*SyncAppender) Close

func (s *SyncAppender) Close()

func (*SyncAppender) Log

func (s *SyncAppender) Log(level Level, name string, content interface{}, args ...interface{})

Jump to

Keyboard shortcuts

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