tongmingleee / yellowHughRichard

0 stars 3 forks source link

Log format #88

Open tongmingleee opened 7 years ago

tongmingleee commented 7 years ago

JSON format log is very for log analysis, and we should format all our log in

in code when you log: logger.info( { timestamp: Date(), ip: req.ip, message: "send index.ejs", elapsed_time: hrend[1] / 1000000 });

resulting log: {"timestamp":"Fri Dec 02 2016 19:45:31 GMT+0000 (UTC)","ip":"::ffff:74.103.160.63","message":"send login.ejs","elapsed_time":0.276783}

! more important, we need add necessary field in log so we can analyze them easily

for page request: [level, timestamp, ip, username, requestType,message, statusCode, responseSize, executetion_time] level: info, warn, error timestamp: current time ip: ip of request username: username requestType: page request, or API request message: "request index.ejs page" statusCode: 200 or whatever responseSize: executetion_time: time take to send back response

for API request: [level, timestamp, ip, username, requestType, message, executetion_time] level: info, warn, error timestamp: current time ip: ip of request username: username requestType: "API request“ message: "request index.ejs page" responseSize: executetion_time: time take to response to request

for DB log: [level, timestamp, ip, username, APIType, message, executetion_time]

level: info, warn, error timestamp: current time ip: ip of request username: username APIType: login/debit/deposit... query: query_result: fail or what query return executetion_time: time take to response to request