Beego framework of the log module

Source: Internet
Author: User

Reference Beego Development Documentation: HTTP://BEEGO.ME/DOCS/MODULE/LOGS.MD

The log module of the Beego framework supports 4 recording methods by default:
1. Terminal output (Console): This method is generally used under the development environment, easy to debug.
2. Local file: This method is typically used to save regular logs for common use in a production environment.
3. Network mode: This method can be used to send logs to the specified server, which can generally be used to trigger events based on logs.
4. Send mail (email): This is generally the production environment of the more important logs sent to the appropriate managers, in order to find and solve problems in a timely manner.

Beego framework of the log module level defined in Github.com/astaxie/beego/logs/log.go: (level with this decrement)
Const (
Levelemergency = iota//Emergency level
Levelalert//Alarm level
Levelcritical//Critical Error level
Levelerror//Error level
Levelwarning//Warning level
Levelnotice//Note level
Levelinformational//reporting level
Leveldebug//debug level
)

1. Example of terminal output (console) recording:

1 Package Main2 3 Import (4     "Github.com/astaxie/beego/logs"5 )6 7 Func Main () {8LOG: = logs. Newlogger (10000)//create a logger with parameters of buffer size9Log. Setlogger ("Console","")//Setting up logging: Console loggingTenLog. SetLevel (logs. Leveldebug)//set the level of log write buffers: Debug level (lowest level, so all logs are entered into the buffer) OneLog. Enablefunccalldepth (true)//Output file name and line number (not required) can be displayed when output log A  -Log. Emergency ("Emergency") -Log. Alert ("Alert") theLog. Critical ("Critical") -Log. Error ("Error") -Log. Warning ("Warning") -Log. Notice ("Notice") +Log.informational ("Informational") -Log. Debug ("Debug") +  A log. Close () at } -  - Program output: -      -/ ./ in  A: on: -[Main.go: -] [M] Emergency -      -/ ./ in  A: on: -[Main.go: -] [A] Alert -      -/ ./ in  A: on: -[Main.go: the] [C] Critical in      -/ ./ in  A: on: -[Main.go: -] [E] Error -      -/ ./ in  A: on: -[Main.go: -] [W] Warning to      -/ ./ in  A: on: -[Main.go: -] [N] Notice +      -/ ./ in  A: on: -[Main.go: +] [I] Informational -      -/ ./ in  A: on: -[Main.go: -] [D] Debug the  *Note: if log. SetLevel (logs. Leveldebug) is modified to log. SetLevel (logs. Levelemergency), only the emergency level of log is output, and the other levels of log are not output.

2. Example of local file record:

Package Mainimport ("Github.com/astaxie/beego/logs") Func main () {log:= Logs. Newlogger (10000)//create a logger with parameters of buffer size//setting up the configuration fileJsonconfig: = `{        "filename":"Test.log",//file name        "Maxlines": +,//Maximum Row        "maxsize":10240       //Maximum size} ' log. Setlogger ("file", Jsonconfig)//Setting Logging: Local File LoggingLog. SetLevel (logs. Leveldebug)//to set the level of log write buffersLog. Enablefunccalldepth (true)//Output file name and line number (not required) can be displayed when output loglog. Emergency ("Emergency") log. Alert ("Alert") log. Critical ("Critical") log. Error ("Error") log. Warning ("Warning") log. Notice ("Notice") log.informational ("Informational") log. Debug ("Debug") log. Flush ()//reads the log from the buffer, writes to the filelog. Close ()} output result: Test.log -/ ./ in  A: -: in[Main.go: +] [M] Emergency -/ ./ in  A: -: in[Main.go: -] [A] Alert -/ ./ in  A: -: in[Main.go: +] [C] Critical -/ ./ in  A: -: in[Main.go: A] [E] Error -/ ./ in  A: -: in[Main.go: at] [W] Warning -/ ./ in  A: -: in[Main.go: -] [N] Notice -/ ./ in  A: -: in[Main.go: -] [I] Informational -/ ./ in  A: -: in[Main.go: -] [D] Debug

Beego framework of the log module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.