Remove all instances of moment

This commit is contained in:
Jonatan Nilsson 2018-07-22 08:30:10 +00:00
parent fe31b83e42
commit 4a50ed39c2
5 changed files with 2 additions and 62 deletions

View file

@ -26,12 +26,6 @@ var assert = require('assert');
var exeunt = require('exeunt'); var exeunt = require('exeunt');
try {
var moment = require('moment');
} catch (e) {
moment = null;
}
//---- globals and constants //---- globals and constants
@ -97,16 +91,6 @@ Object.keys(levelFromName).forEach(function (name) {
var TIME_UTC = 1; // the default, bunyan's native format var TIME_UTC = 1; // the default, bunyan's native format
var TIME_LOCAL = 2; var TIME_LOCAL = 2;
// Timezone formats: output format -> momentjs format string
var TIMEZONE_UTC_FORMATS = {
long: '[[]YYYY-MM-DD[T]HH:mm:ss.SSS[Z][]]',
short: 'HH:mm:ss.SSS[Z]'
};
var TIMEZONE_LOCAL_FORMATS = {
long: '[[]YYYY-MM-DD[T]HH:mm:ss.SSSZ[]]',
short: 'HH:mm:ss.SSS'
};
// Boolean set to true when we are in the process of exiting. We don't always // Boolean set to true when we are in the process of exiting. We don't always
// hard-exit (e.g. when staying alive while the pager completes). // hard-exit (e.g. when staying alive while the pager completes).
@ -258,8 +242,6 @@ function printHelp() {
p(' simple: level, followed by "-" and then the message'); p(' simple: level, followed by "-" and then the message');
p(' -j shortcut for `-o json`'); p(' -j shortcut for `-o json`');
p(' -0 shortcut for `-o bunyan`'); p(' -0 shortcut for `-o bunyan`');
p(' -L, --time local');
p(' Display time field in local time, rather than UTC.');
p(''); p('');
p('Environment Variables:'); p('Environment Variables:');
p(' BUNYAN_NO_COLOR Set to a non-empty value to force no output '); p(' BUNYAN_NO_COLOR Set to a non-empty value to force no output ');
@ -523,26 +505,12 @@ function parseArgv(argv) {
case '-0': case '-0':
parsed.outputMode = OM_BUNYAN; parsed.outputMode = OM_BUNYAN;
break; break;
case '-L':
parsed.timeFormat = TIME_LOCAL;
if (!moment) {
throw new Error(
'could not find moment package required for "-L"');
}
break;
case '--time': case '--time':
var timeArg = args.shift(); var timeArg = args.shift();
switch (timeArg) { switch (timeArg) {
case 'utc': case 'utc':
parsed.timeFormat = TIME_UTC; parsed.timeFormat = TIME_UTC;
break break
case 'local':
parsed.timeFormat = TIME_LOCAL;
if (!moment) {
throw new Error('could not find moment package '
+ 'required for "--time=local"');
}
break
case undefined: case undefined:
throw new Error('missing argument to "--time"'); throw new Error('missing argument to "--time"');
default: default:
@ -795,24 +763,8 @@ function emitRecord(rec, line, opts, stylize) {
// Fast default path: We assume the raw `rec.time` is a UTC time // Fast default path: We assume the raw `rec.time` is a UTC time
// in ISO 8601 format (per spec). // in ISO 8601 format (per spec).
time = '[' + rec.time + ']'; time = '[' + rec.time + ']';
} else if (!moment && opts.timeFormat === TIME_UTC) { } else if (opts.timeFormat === TIME_UTC) {
// Don't require momentjs install, as long as not using TIME_LOCAL.
time = rec.time.substr(11); time = rec.time.substr(11);
} else {
var tzFormat;
var moTime = moment(rec.time);
switch (opts.timeFormat) {
case TIME_UTC:
tzFormat = TIMEZONE_UTC_FORMATS[short ? 'short' : 'long'];
moTime.utc();
break;
case TIME_LOCAL:
tzFormat = TIMEZONE_LOCAL_FORMATS[short ? 'short' : 'long'];
break;
default:
throw new Error('unexpected timeFormat: ' + opts.timeFormat);
};
time = moTime.format(tzFormat);
} }
time = stylize(time, 'none'); time = stylize(time, 'none');
delete rec.time; delete rec.time;

View file

@ -142,10 +142,6 @@ Specify an output format\. One of \fBlong\fR (the default), \fBshort\fR, \fBjson
\fB\-j\fR \fB\-j\fR
Shortcut for \fB\-o json\fR\. Shortcut for \fB\-o json\fR\.
. .
.TP
\fB\-L\fR, \fB\-\-time local\fR
Display the time field in \fIlocal\fR time, rather than the default UTC time\.
.
.SH "LOG LEVELS" .SH "LOG LEVELS"
In Bunyan log records, then \fBlevel\fR field is a number\. For the \fB\-l|\-\-level\fR argument the level \fBnames\fR are supported as shortcuts\. In \fB\-c|\-\-condition\fR scripts, uppercase symbols like "DEBUG" are defined for convenience\. In Bunyan log records, then \fBlevel\fR field is a number\. For the \fB\-l|\-\-level\fR argument the level \fBnames\fR are supported as shortcuts\. In \fB\-c|\-\-condition\fR scripts, uppercase symbols like "DEBUG" are defined for convenience\.
. .

View file

@ -182,8 +182,6 @@ non-Bunyan lines are passed through.</p></dd>
<dt><code>-o FORMAT</code>, <code>--output FORMAT</code></dt><dd><p>Specify an output format. One of <code>long</code> (the default), <code>short</code>, <code>json</code>, <dt><code>-o FORMAT</code>, <code>--output FORMAT</code></dt><dd><p>Specify an output format. One of <code>long</code> (the default), <code>short</code>, <code>json</code>,
<code>json-N</code>, <code>bunyan</code> (the native bunyan 0-indent JSON output) or <code>inspect</code>.</p></dd> <code>json-N</code>, <code>bunyan</code> (the native bunyan 0-indent JSON output) or <code>inspect</code>.</p></dd>
<dt class="flush"><code>-j</code></dt><dd><p>Shortcut for <code>-o json</code>.</p></dd> <dt class="flush"><code>-j</code></dt><dd><p>Shortcut for <code>-o json</code>.</p></dd>
<dt><code>-L</code>, <code>--time local</code></dt><dd><p>Display the time field in <em>local</em> time, rather than the default UTC
time.</p></dd>
</dl> </dl>

View file

@ -109,10 +109,6 @@ Output options:
* `-j`: * `-j`:
Shortcut for `-o json`. Shortcut for `-o json`.
* `-L`, `--time local`:
Display the time field in *local* time, rather than the default UTC
time.
## LOG LEVELS ## LOG LEVELS

View file

@ -21,12 +21,10 @@
}, },
"// dtrace-provider": "required for dtrace features", "// dtrace-provider": "required for dtrace features",
"// mv": "required for RotatingFileStream", "// mv": "required for RotatingFileStream",
"// moment": "required for local time with CLI",
"optionalDependencies": { "optionalDependencies": {
"dtrace-provider": "~0.8", "dtrace-provider": "~0.8",
"mv": "~2", "mv": "~2",
"safe-json-stringify": "~1", "safe-json-stringify": "~1"
"moment": "^2.10.6"
}, },
"devDependencies": { "devDependencies": {
"nodeunit": "0.9", "nodeunit": "0.9",