Reformat project into workspaces
This commit is contained in:
1 parent
20bb10114b
commit
c3e2cf5ed3
38 files changed
+4863
-4186
No files matched your search
+22
-5
@@ -47,6 +47,8 @@ var CLF_MONTH = [
|
||||
|
||||
var DEFAULT_BUFFER_DURATION = 1000
|
||||
|
||||
var NO_COLOR = Boolean(process.env.NO_COLOR)
|
||||
|
||||
/**
|
||||
* Escape control characters and backslashes so a value is safe for
|
||||
* line-oriented logs.
|
||||
@@ -59,7 +61,7 @@ function escapeLogField (value) {
|
||||
if (value == null) return undefined
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
return String(value).replace(/[\u0000-\u001f\u007f\\]/g, function (ch) {
|
||||
return String(value).replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\\]/g, function (ch) {
|
||||
switch (ch) {
|
||||
case '\\': return '\\\\'
|
||||
case '\b': return '\\b'
|
||||
@@ -153,7 +155,11 @@ function morgan (format, options) {
|
||||
}
|
||||
|
||||
debug('log request')
|
||||
stream.write(line + '\n')
|
||||
if (stream.writableObjectMode && typeof line === 'object') {
|
||||
stream.write(line)
|
||||
} else {
|
||||
stream.write(line + '\n')
|
||||
}
|
||||
};
|
||||
|
||||
if (immediate) {
|
||||
@@ -231,6 +237,12 @@ morgan.format('dev', function developmentFormatLine (tokens, req, res) {
|
||||
return fn(tokens, req, res)
|
||||
})
|
||||
|
||||
// NO_COLOR (https://no-color.org): when set and not an empty string, the dev
|
||||
// format is replaced at load time with a variant free of escape sequences
|
||||
if (NO_COLOR) {
|
||||
morgan.format('dev', compile(':method :url :status :response-time ms - :res[content-length]'))
|
||||
}
|
||||
|
||||
/**
|
||||
* request url
|
||||
*/
|
||||
@@ -334,9 +346,9 @@ morgan.token('remote-user', function getRemoteUserToken (req) {
|
||||
// parse basic credentials
|
||||
var credentials = auth(req)
|
||||
|
||||
// return username
|
||||
// return username (escaping is applied by the token() wrapper)
|
||||
return credentials
|
||||
? escapeLogField(credentials.name)
|
||||
? credentials.name
|
||||
: undefined
|
||||
})
|
||||
|
||||
@@ -573,6 +585,11 @@ function recordStartTime () {
|
||||
*/
|
||||
|
||||
function token (name, fn) {
|
||||
morgan[name] = fn
|
||||
// wrap the token so its string output is always escaped for line-oriented
|
||||
// logs, regardless of whether the format is a string or a function
|
||||
morgan[name] = function tokenValue () {
|
||||
var value = fn.apply(this, arguments)
|
||||
return typeof value === 'string' ? escapeLogField(value) : value
|
||||
}
|
||||
return this
|
||||
}
|
||||
Reference in new issue
Block a user