1, the use of Express self-band module
var logFile = Fs.createwritestream ('./apkanalysis.log ', {
"flags": "A"
});
App.configure (function () {
App.use (Express.logger ({stream:logfile}));
};
This code is added to the app.js, but I found a problem, this log it only records other client access to the server information, the following figure is I use chrom access to my server
2. Use Winston module
before using it, we have to install it in the project first:
first go to the project folder, then NPM install
Winston
Here we can quote it, I was introduced in the App.js:
var winston=require (' Winston ');
var logger = new (Winston. Logger) ({
transports: [
New (Winston.transports.Console) (),
New (Winston.transports.File) ({
FileName: './apkanalysis.log ',
timestamp: ' True ',
maxsize:10485760,//log file size
maxfiles:10}
]});
when we need to log files, we can write this:
logger.log (' info ', ' Test logmessage ', {anything: ' This is metadata '});
when we runapp.js, we'll be there.
ApkAnalysis.log See the following figure:
to make it easier for me to create a new config folder under the project directory, and then create a new file in the Config folder//logger.js
var winston=require (' Winston ');
var logger = new (Winston. Logger) ({
transports: [
New (Winston.transports.Console) (),
New (Winston.transports.File) ({
FileName: './apkanalysis.log ',
timestamp: ' True ',
maxsize:10485760,
maxfiles:10}
]});
Exports.logger=logger;
It is convenient to call it later in other JS files, such as I call it in App.js, I will introduce it first:
var logs=require ('./config/logger.js ');
It's handy when you use it:
logs.logger.log (' info ', "Express server Listeningon Port 3000");