This repository was archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (53 loc) · 1.45 KB
/
main.js
File metadata and controls
64 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*jshint node:true*/
/**
*
* Logger by Ståle Raknes
*
* Dependencies:
*
* morgan Copyright(c) 2010 Sencha Inc., (c) 2011 TJ Holowaychuk, (c) 2014 Jonathan Ong,
* (c) 2014 Douglas Christopher Wilson MIT Licensed
*
* dateFormat by felixge, is to be found here: https://github.com/felixge/node-dateformat
*
*/
"use strict";
var morgan = require( "morgan" );
var dateFormater = require( "dateformat" );
var uap = require( 'ua-parser' );
var colors = require( "colors" );
morgan.token( 'date', function ( req, res, format ) {
format = format || 'HH:MM:ss.l';
return dateFormater( format );
} );
morgan.token( 'os', function ( req ) {
return uap.parseOS( req.headers['user-agent'] ).toString();
} );
morgan.token( 'browser', function ( req ) {
return uap.parseUA( req.headers['user-agent'] ).toString();
} );
morgan.token( 'device', function ( req ) {
return uap.parseDevice( req.headers['user-agent'] ).toString();
} );
morgan.token( 'status', function ( req, res ) {
var status = res.statusCode;
var color = "green";
if ( status >= 404 ) {
color = "red";
}
else if ( status >= 400 ) {
color = "yellow";
}
return res.statusCode ? colors[color]( res.statusCode ) : null;
} );
morgan.format( "dev", [
'->'.yellow,
':date[HH:MM:ss.l]'.gray,
':method >',
':status >',
':url'.white,
'-',
':browser > :device > :os >',
':remote-addr'.gray
].join( " " ) );
module.exports = morgan;