How to use Morgan logger?

后端 未结 10 1627
囚心锁ツ
囚心锁ツ 2020-12-07 11:19

I cannot log with Morgan. It doesn\'t log info to console. The documentation doesn\'t tell how to use it.

I want to see what a variable is. This is a code from

10条回答
  •  眼角桃花
    2020-12-07 12:18

    You might want to try using mongo-morgan-ext

    The usage is:

    var logger = require('mongo-morgan-ext');
    
    var db = 'mongodb://localhost:27017/MyDB';
    
    var collection = 'Logs'
    
    var skipfunction = function(req, res) {
    
    return res.statusCode > 399;
    } //Thiw would skip if HTTP request response is less than 399 i.e no errors.
    
    app.use(logger(db,collection,skipfunction)); //In your express-application
    

    The expected output is

    {
        "RequestID": "",
        "status": "",
        "method": "",
        "Remote-user": "",
        "Remote-address": "",
        "URL": "",
        "HTTPversion": "",
        "Response-time": "",
        "date":"",
        "Referrer": "",
        "REQUEST": { //10
            "Accept": "",
            "Accept-Charset": "",
            "Accept-Encoding": "",
            "Accept-Language": "",
            "Authorization": "",
            "Cache-Control": "",
            "Connection": "",
            "Cookie": "",
            "Content-Length": "",
            "Content-MD5": "",
            "Content-Type": "",
            "Expect": "",
            "Forwarded": "",
            "From": "",
            "Host": "",
            "Max-Forwards": "",
            "Origin": "",
            "Pragma": "",
            "Proxy-Authorization": "",
            "Range": "",
            "TE": "",
            "User-Agent": "",
            "Via": "",
            "Warning": "",
            "Upgrade": "",
            "Referer": "",
            "Date": "",
            "X-requested-with": "",
            "X-Csrf-Token": "",
            "X-UIDH": "",
            "Proxy-Connection": "",
            "X-Wap-Profile": "",
            "X-ATT-DeviceId": "",
            "X-Http-Method-Override":"",
            "Front-End-Https": "",
            "X-Forwarded-Proto": "",
            "X-Forwarded-Host": "",
            "X-Forwarded-For": "",
            "DNT": "",
            "Accept-Datetime": "",
            "If-Match": "",
            "If-Modified-Since": "",
            "If-None-Match": "",
            "If-Range": "",
            "If-Unmodified-Since": ""
        },
        "RESPONSE": {
            "Status": "",
            "Content-MD5":"",
            "X-Frame-Options": "",
            "Accept-Ranges": "",
            "Age": "",
            "Allow": "",
            "Cache-Control": "",
            "Connection": "",
            "Content-Disposition": "",
            "Content-Encoding": "",
            "Content-Language": "",
            "Content-Length": "",
            "Content-Location": "",
            "Content-Range": "",
            "Content-Type":"",
            "Date":"",
            "Last-Modified": "",
            "Link": "",
            "Location": "",
            "P3P": "",
            "Pragma": "",
            "Proxy-Authenticate": "",
            "Public-Key-Pins": "",
            "Retry-After": "",
            "Server": "",
            "Trailer": "",
            "Transfer-Encoding": "",
            "TSV": "",
            "Upgrade": "",
            "Vary": "",
            "Via": "",
            "Warning": "",
            "WWW-Authenticate": "",
            "Expires": "",
            "Set-Cookie": "",
            "Strict-Transport-Security": "",
            "Refresh":"",
            "Access-Control-Allow-Origin": "",
            "X-XSS-Protection": "",
            "X-WebKit-CSP":"",
            "X-Content-Security-Policy": "",
            "Content-Security-Policy": "",
            "X-Content-Type-Options": "",
            "X-Powered-By": "",
            "X-UA-Compatible": "",
            "X-Content-Duration": "",
            "Upgrade-Insecure-Requests": "",
            "X-Request-ID": "",
            "ETag": "",
            "Accept-Patch": ""
        }
    
    }
    

提交回复
热议问题