NODEJS-LOG4JS Configuration __js

Source: Internet
Author: User

Brief Introduction:

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. Enter Express project root path, download Log4js library file

NPR Install LOG4JS


2. Configure LOG4JS Files

Logger.js

/**
 * LOG4JS log Output configuration file
 * @type {EXPORTS} * * *
var log4js = require (' Log4js ');

Logger Configure
Log4js.configure {
    appenders: [
        {type: ' console '}, {
            type: ' Datefile ',
            FileName: ' Logs/log ', pattern
            : "_yyyy-mm-dd",
            maxlogsize:1024,
            alwaysincludepattern:false,
            Backups:4,
            Category: ' Logger '
        }
    ],
    replaceconsole:true
});

Module.exports = Log4js.getlogger (' logger ');



Modular declaration of the Logger

When the project is started, log files are immediately generated under the Logs folder.

At the beginning of the document, the Datefile file updates the file in the daily midnight, and the file of the previous day is automatically added to the end of the date format.

eg

Modify Windows Time



Before the midnight of the day



The logs folder is then generated










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.