Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(v ...interface{}) error
- func Error(v ...interface{}) error
- func Fatal(v ...interface{}) error
- func FormatLog(level int32, v ...interface{}) string
- func GetStack(all bool) string
- func Info(v ...interface{}) error
- func InitLogger(conf *Config)
- func PrintStack(all bool)
- func Run(s *LogModule)
- func Trace(v ...interface{}) error
- func TraceCost(msg string) func()
- func Warning(v ...interface{}) error
- func WriteLog(level int32, v ...interface{}) error
- type Config
- type ConsoleLog
- func (c *ConsoleLog) CanLog(msgSize int32, count int32) bool
- func (c *ConsoleLog) Close() error
- func (c *ConsoleLog) Debug(v ...interface{}) error
- func (c *ConsoleLog) Error(v ...interface{}) error
- func (c *ConsoleLog) Fatal(v ...interface{}) error
- func (c *ConsoleLog) GetLevel() int32
- func (c *ConsoleLog) Info(v ...interface{}) error
- func (c *ConsoleLog) InitLogger(conf *Config) error
- func (c *ConsoleLog) ParseConfig(conf *Config) error
- func (c *ConsoleLog) PushLog(level int32, v ...interface{}) error
- func (c *ConsoleLog) SetLevel(level int32) error
- func (c *ConsoleLog) Warning(v ...interface{}) error
- func (c *ConsoleLog) WriteLog(msg []byte, count int32) error
- type FileLog
- func (l *FileLog) CanLog(msgSize int32, count int32) bool
- func (l *FileLog) Close() error
- func (l *FileLog) Debug(v ...interface{}) error
- func (l *FileLog) Error(v ...interface{}) error
- func (l *FileLog) Fatal(v ...interface{}) error
- func (l *FileLog) GetLevel() int32
- func (l *FileLog) Info(v ...interface{}) error
- func (l *FileLog) InitLogger(conf *Config) error
- func (l *FileLog) ParseConfig(conf *Config) error
- func (l *FileLog) PushLog(level int32, v ...interface{}) error
- func (l *FileLog) SetLevel(level int32) error
- func (l *FileLog) Warning(v ...interface{}) error
- func (l *FileLog) WriteLog(msg []byte, count int32) error
- type ILog
- type LogModule
- func (s *LogModule) CanExit(doneFlag bool) (bool, bool)
- func (s *LogModule) Close()
- func (s *LogModule) Context() context.Context
- func (s *LogModule) IdleTimes() uint32
- func (s *LogModule) IdleTimesAdd()
- func (s *LogModule) IdleTimesReset()
- func (s *LogModule) MQ() queue.Queue
- func (s *LogModule) OnRun(dt time.Duration)
- func (s *LogModule) PushBytes(option int32, buf []byte) error
- func (s *LogModule) Reload(conf *Config) error
- func (s *LogModule) Setup(conf *Config) (*LogModule, error)
- func (s *LogModule) Stop() error
- func (s *LogModule) UserData() int32
Constants ¶
const ( FATAL = iota ERROR TRACE WARNING INFO DEBUG )
Log Levels Define 0 Fatal: system is unusable 1 Error: error conditions 2 Trace: trace conditions 3 Warning: warning conditions 4 Info: informational messages 5 Debug: debug-level messages
const BATCH_LOG_SIZE = 1
Variables ¶
var LogLevelPrefix = [DEBUG + 1]string{" [FATAL] ", " [ERROR] ", " [TRACE] ", " [WARNING] ", " [INFO] ", " [DEBUG] "}
LogLevelPrefix level format to string
Functions ¶
Types ¶
type Config ¶
type Config struct { Filename string `mapstructure:"filename"` Level int32 `mapstructure:"level"` MaxSize int32 `mapstructure:"max_size"` MaxLines int32 `mapstructure:"max_lines"` HourEnabled bool `mapstructure:"hour_enabled"` DailyEnabled bool `mapstructure:"daily_enabled"` QueueSize int `mapstructure:"queue_size"` }
Config log attributes in config file
func (*Config) GetQueueSize ¶
GetQueueSize get module queue size
type ConsoleLog ¶
type ConsoleLog struct { Conf *Config // contains filtered or unexported fields }
ConsoleLog writes messages to terminal.
func (*ConsoleLog) CanLog ¶
func (c *ConsoleLog) CanLog(msgSize int32, count int32) bool
CanLog check log status
func (*ConsoleLog) Debug ¶
func (c *ConsoleLog) Debug(v ...interface{}) error
Debug debug-level messages
func (*ConsoleLog) Error ¶
func (c *ConsoleLog) Error(v ...interface{}) error
Error error conditions
func (*ConsoleLog) Fatal ¶
func (c *ConsoleLog) Fatal(v ...interface{}) error
Fatal system is unusable
func (*ConsoleLog) Info ¶
func (c *ConsoleLog) Info(v ...interface{}) error
Info informational messages
func (*ConsoleLog) InitLogger ¶
func (c *ConsoleLog) InitLogger(conf *Config) error
InitLogger init logger
func (*ConsoleLog) ParseConfig ¶
func (c *ConsoleLog) ParseConfig(conf *Config) error
ParseConfig read config from map[string]interface{} config key map level default 7
func (*ConsoleLog) PushLog ¶
func (c *ConsoleLog) PushLog(level int32, v ...interface{}) error
PushLog push log to queue
func (*ConsoleLog) SetLevel ¶
func (c *ConsoleLog) SetLevel(level int32) error
SetLevel atomic set level
func (*ConsoleLog) Warning ¶
func (c *ConsoleLog) Warning(v ...interface{}) error
Warning warning conditions
type FileLog ¶
type FileLog struct { Conf *Config // contains filtered or unexported fields }
FileLog implements Log interface, not goruntine safety write log to file,if file reached limit,rename file match format filename support filesize limit / time frequency / lines limit filename read from config like server.log and the real filename like server_20190101-01.log or server_20190101.log hourEnabled if enabled , filename like server_20190101-01.log dailyEnabled if enabled, filename like server_20190101.log else filename like server.log filename format = filename_ymd-h_num.suffix
func (*FileLog) InitLogger ¶
InitLogger init logger
func (*FileLog) ParseConfig ¶
ParseConfig read config from map[string]interface{} config key map filename default server.log level default 7 maxSize default 1024 maxLines default 100000 hourEnabled default false dailyEnabled default true
type ILog ¶
type ILog interface { // ParseConfig read config from conf object ParseConfig(conf *Config) error // InitLogger init logger InitLogger(conf *Config) error // SetLevel atomic set level value SetLevel(level int32) error // GetLevel atomic get level value GetLevel() int32 // Fatal system is unusable Fatal(v ...interface{}) error // Error error conditions Error(v ...interface{}) error // Warning warning conditions Warning(v ...interface{}) error // Info informational messages Info(v ...interface{}) error // Debug debug-level messages Debug(v ...interface{}) error // WriteLog write log to file, return immediately if not meet the conditions WriteLog(msg []byte, count int32) error // CanLog check log status CanLog(msgSize int32, count int32) bool // Close and flush Close() error }
ILog log Interface
func NewConsoleLogger ¶
NewConsoleLogger create FileLog instance
func NewFileLogger ¶
NewFileLogger create FileLog instance
type LogModule ¶
type LogModule struct {
// contains filtered or unexported fields
}
LogModule struct implements the interface Module
var GLoggerModule *LogModule
GLoggerModule global log module
func (*LogModule) Close ¶
func (s *LogModule) Close()
Close call context cancel ,self and all child module will receive context.Done()
func (*LogModule) IdleTimesReset ¶
func (s *LogModule) IdleTimesReset()
IdleTimesReset reset idle times
func (*LogModule) OnRun ¶
OnRun goruntine run and call OnRun , always use ModuleRun to call this function