Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(1.2.0) add dev+ format #19

Closed
wants to merge 1 commit into from
Closed

(1.2.0) add dev+ format #19

wants to merge 1 commit into from

Conversation

c0d3rman
Copy link

Added dev+ logging format (dev with more information)

I used dev for easy logging in my server. I decided it needed to give IP addresses, etc.
Please add this as an optional way to get more information during development.
Will not be useful to everyone, but it definitely can't hurt.

Added dev+ logging format (dev with more information)
@Fishrock123
Copy link
Contributor

@c0d3rman please, do not bump versions in pull requests. ever.

@Fishrock123 Fishrock123 changed the title 1.2.0 (1.2.0) add dev+ format Jun 11, 2014
@dougwilson
Copy link
Contributor

This pull request is extremely rude, dictating our release schedule and version numbers. "dev" is only only intended for using on your console for local development, not for when random people are connection, which is why the IP is not in "dev" format.

If you want your own special format, you can define it yourself:

var express = require('express')
var morgan = require('morgan')

morgan.format('dev+', function(tokens, req, res){
  var color = 32; // green
  var status = res.statusCode;

  if (status >= 500) color = 31; // red
  else if (status >= 400) color = 33; // yellow
  else if (status >= 300) color = 36; // cyan

  var fn = compile('\x1b[90m:remote-addr \x1b[32m:method \x1b[35m:url \x1b[/' + color + 'm:status \x1b[97m:response-time ms\x1b[0m');

  return fn(tokens, req, res);
})

var app = express()
app.use(morgan('dev+'))

@c0d3rman
Copy link
Author

Sorry! I didn't mean to offend.
I was using the example @dougwilson provided, but it doesn't seem the compile function is public, so I had to copy it from morgan's source code.
Clearly I shouldn't have submitted a pull request. Sorry again.

@dougwilson
Copy link
Contributor

compile function is public

ah, yea. you'll want to concat strings anyway, like the old version of the "dev" format did. compile is slower, i just switched dev to use it to make it more readable.

@Fishrock123
Copy link
Contributor

Is compile something we should be making public?

Clearly I shouldn't have submitted a pull request. Sorry again.

Maybe you should have, but about the compile function. I hope you don't feel too offed by this.

@c0d3rman
Copy link
Author

I guess compile isn't the best thing to do and tokens would be optimal.
It did make it easier to include tokens, but only slightly, and also had the problem of not allowing : in the output (for time).
The reason I wanted dev+ is because I keep two parallel logs on my server - one is an info dump file that uses default, and the other is a more readable file that uses dev (and now dev+). Since I am continually developing my server and it helps to see a pretty colored version when struggling with a bug.

@dougwilson
Copy link
Contributor

The reason I wanted dev+ is because I keep two parallel logs on my server

That's perfectly fine, and you're free to define your own formats here. It just doesn't fit into something we're going to add to this module's default list (which is just samples/standard formats that like Apache uses).

Is compile something we should be making public?

No, it's just an internal utility and not very extendable, which is why it is not exposed for people to use. It makes typing out the long string-concatenating things in core easy and non-redundant. If we exposed it, it would need to actually be full-featured and tested. @c0d3rman noticed already that you cannot use : characters in compile, for example.

@dougwilson
Copy link
Contributor

Anyway, the real issue here, i.m.o., is that you cannot specify a format as a string that has conditional coloring. I'm working to add that feature now, then you can specify your custom colored format as a string instead of a function.

@c0d3rman
Copy link
Author

Okay. Thanks for your help!

@expressjs expressjs locked and limited conversation to collaborators Jul 17, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants