Nodejs Log Management Log4js

Source: Internet
Author: User

Briefly:

Logging Configuration Nodejs-log4js Log output

Reference: HTTP://CNODEJS.ORG/TOPIC/521EE22ABEE8D3CB12FC1F02

Https://github.com/nomiddlename/log4js-node/wiki/Date%20rolling%20file%20appender


Steps:

1. Go to the Express project root path and download the LOG4JS library file

[Plain]View Plaincopy
    1. NPR Install LOG4JS


2. Configuring the Log4js File

Logger.js

[JavaScript]View Plaincopy
  1. /**  
  2.  * log4js  Log output configuration file  
  3.  *  @type  {exports}  
  4.  */   
  5. var  log4js = require (
  6. //Logger Configure   
  7. Log4js.configure ({
  8. Appenders: [
  9.         { type:  ' console '  }, {  
  10.             type: < Span class= "string" style= "margin:0px; padding:0px; border:0px; Color:blue; Background-color:inherit "> ' datefile ' ,&NBSP;&NBSP;
  11.             filename:   ,  
  12.             pattern:   ,  
  13.             maxlogsize:  1024,  
  14.              Alwaysincludepattern: false ,&NBSP;&NBSP;
  15.             backups:  4,  
  16.             category:   &NBSP;&NBSP;
  17. }
  18. ],
  19.     replaceconsole: true &NBSP;&NBSP;
  20. });
  21. Module.exports = Log4js.getlogger (' logger ');



Modular Declaration of the Logger

After you start the project, a log file is generated immediately under the Logs folder.

At the beginning of the document, the Datefile file updates the file in the daily Midnight, and the previous day's file is automatically appended with the end of the date format.

eg

Modify Windows Time



Before the midnight of the day



The logs folder is then generated



Nodejs Log Management Log4js

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.