Git Product home page Git Product logo

Comments (5)

dougwilson avatar dougwilson commented on May 6, 2024

Not with the string syntax, but you can do this if you use a custom function for the formatting:

var morgan = require('morgan')

app.use(morgan(function (tokens, req, res) {
  return tokens.method(req, res)
    + ' ' + tokens.status(req, res)
    + ' ' + tokens.url(req, res)
    + ' ' + tokens['response-time'](req, res) + 'ms'
    + ' ' + tokens['content-length'](req, res)
}))

from morgan.

bchr02 avatar bchr02 commented on May 6, 2024

That works! Thank you.

from morgan.

denisu avatar denisu commented on May 6, 2024
app.use(logger(':method :status :url :response-time\\ms :res[content-length]'));

works too

from morgan.

dougwilson avatar dougwilson commented on May 6, 2024

@denisu that only works because '\m' is not an escape in JavaScript. If, perhaps, he wanted the end to me "ns" (with an n instead of m), then your solution wouldn't work, since '\n' would translate to a newline character.

from morgan.

denisu avatar denisu commented on May 6, 2024

You are right, its a little hacky, you could also squeeze a valid escape character in there, but it might produce dirty logfiles.

app.use(logger(':method :status :url :response-time\0ms :res[content-length]'));
app.use(logger(':method :status :url :response-time\bms :res[content-length]'));

from morgan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.