go logger logging library


logger package introduced

logger support

  • logger support custom time format;
  • logger supports different log level output, can effectively improve the output performance and the log retrieval;
  • Support console + + logger network file output in three ways, and may be any combination thereof;
  • logger supports console output color discrimination;
  • logger supports customized text output;
  • logger logs support network transmission, such as direct connection logstash transmission;
  • logger supports output file name and line number, time and so on;

logger log level

grade Configuration DEFINITIONS Console Color
0  NAME  System-level emergency, such as disk errors, memory exception, the network is unavailable, etc.  Red bottom
1 ALRT Level warning system, such as database access exceptions, such as the configuration file error purple
2 CRIT System-level hazards, such as permissions error, such as access exceptions blue
3 error User-level error red
4 WARN User-level warning yellow
5 INFO User-level important sky blue
6 DEBG User-level debugging green
TRAC The basic user-level output, such as member information, the value of the structure and the like green

logger installation

go get github.com/wonderivan/logger

  

Simple to use

main Package Penalty for 
Import "Logger" 
 
FUNC main () { 
	logger.Trace ( "the this IS Trace") // Because the default output, only output Debug log in and above the console, so the article does not output 
	logger.Debug ( " IS Debug the this ") 
	logger.info (" the this IS Info ") 
	logger.Warn (" Warn the this IS ") 
	logger.Error (" the this IS Error ") 
	logger.Crit (" the this IS Critical ") 
	logger.Alert (" IS the Alert the this ") 
	logger.Emer (" Emergency the this IS ") 
}

  

Configuration parameters

parameter

{ 
    "TimeFormat": "2006-01-02 15:04:05", the beginning of the // output log time format 
    "Console": {// console logging configuration 
        "level": "TRAC", // console log output level 
        "color": true // color switch console log 
    }, 
    "file": {// log configuration file 
        "filename": "app.log", // initial log file name 
        "level": "TRAC", / / log log file output level 
        "daily": true, // whether to create a new log file across days, effective as append = true when 
        "maxlines": 1000000, maximum number of rows // log files, append = true when effective when 
        "maxsize ": 1, // maximum log file size, when the effective time append = true 
        " maxdays ": -1,// valid log file 
        "append": true, // whether to support additional log 
        "permit": "0660" log file permissions attributes // newly created 
    },
    "Conn": {// log the network configuration 
        "net": "tcp", // log transmission mode 
        "addr": "10.1.55.10:1024", // the server receives log 
        "level": "Warn", // web log output level 
        "reconnect": true, // if disconnected from the network after reconnection 
        "reconnectOnMsg": false, // End after each message sent if the network is disconnected 
    } 
}

How to configure parameters

Arranged from two
setting parameters by calling logger.SetLogger (config string) method, support json config configuration, also supports the contents of the specified file path json configuration, for example:

  • Direct configuration by configuration parameters
logger.SetLogger(`{"Console": {"level": "DEBG"}}`)
  • By profile configuration
logger.SetLogger("/home/log.json")

 

Guess you like

Origin www.cnblogs.com/-wenli/p/12328839.html