Create log through Wiston, one file a day

Source: Internet
Author: User
/** * User access, app run and error log.
* * @module Logger * *//import var fs = require (' FS ');
var util = require (' util ');
var Winston = require (' Winston ');


var mkdirp = require (' mkdirp ');
var LogPath = "./logs";
    if (!fs.existssync (LogPath)) {Mkdirp.sync (LogPath);
Console.log (Util.format (' Log Path:%s ', LogPath));

}; function Createlogger (fileName) {/*var logger = Winston.add (Winston.transports.DailyRotateFile, {filename:util
    . Format ('%s/%s ', LogPath, FileName), Datepattern: '-yyyy-mm-dd.log '});
    Logger.remove (Winston.transports.Console); return logger;*/var logger = new (Winston. Logger) ({transports: [New (Winston.transports.DailyRotateFile) ({filename:util.format ('% 
          s/%s ', LogPath, FileName), Datepattern: '-yyyy-mm-dd.log ', maxsize:1024 * 1024 */10MB
    })
        ]
    });
return logger;
 /** * Create an logger. * * @class Logger * @constructor/FUnction Logger () {this.applog = Createlogger (' app ');
    This.errorlog = Createlogger (' error ');
This.accesslog = Createlogger (' access ');
 /** * Info Logger * * @method Info * @param {message} * Log info.

*/Logger.prototype.info = function (message) {this.appLog.info (message);
 /** * ERROR Logger * * @method Error * @param {message} * error message.
    */Logger.prototype.error = function (message) {var msg = ';
    if (typeof (message) = = ' string ') msg = message; else if (typeof (message) = = ' object ') {if (typeof (message.tostring) = = ' function ') msg = Message.tostrin
        g ();
    else msg = json.stringify (message);
This.errorLog.error (msg);

};
 Module.exports = new Logger ();

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.