1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var VERSION = '1.8.6';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var LOG_VERSION = 0;
|
19 |
|
20 |
|
21 | var xxx = function xxx(s) {
|
22 | var args = ['XX' + 'X: '+s].concat(
|
23 | Array.prototype.slice.call(arguments, 1));
|
24 | console.error.apply(this, args);
|
25 | };
|
26 | var xxx = function xxx() {};
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | var runtimeEnv;
|
50 | if (typeof (process) !== 'undefined' && process.versions) {
|
51 | if (process.versions.nw) {
|
52 | runtimeEnv = 'nw';
|
53 | } else if (process.versions.node) {
|
54 | runtimeEnv = 'node';
|
55 | }
|
56 | }
|
57 | if (!runtimeEnv && typeof (window) !== 'undefined' &&
|
58 | window.window === window) {
|
59 | runtimeEnv = 'browser';
|
60 | }
|
61 | if (!runtimeEnv) {
|
62 | throw new Error('unknown runtime environment');
|
63 | }
|
64 |
|
65 |
|
66 | var os, fs, dtrace;
|
67 | if (runtimeEnv === 'browser') {
|
68 | os = {
|
69 | hostname: function () {
|
70 | return window.location.host;
|
71 | }
|
72 | };
|
73 | fs = {};
|
74 | dtrace = null;
|
75 | } else {
|
76 | os = require('os');
|
77 | fs = require('fs');
|
78 | try {
|
79 | dtrace = require('dtrace-provider' + '');
|
80 | } catch (e) {
|
81 | dtrace = null;
|
82 | }
|
83 | }
|
84 | var util = require('util');
|
85 | var assert = require('assert');
|
86 | var EventEmitter = require('events').EventEmitter;
|
87 | var stream = require('stream');
|
88 |
|
89 | try {
|
90 | var safeJsonStringify = require('safe-json-stringify');
|
91 | } catch (e) {
|
92 | safeJsonStringify = null;
|
93 | }
|
94 | if (process.env.BUNYAN_TEST_NO_SAFE_JSON_STRINGIFY) {
|
95 | safeJsonStringify = null;
|
96 | }
|
97 |
|
98 |
|
99 | try {
|
100 | var mv = require('mv' + '');
|
101 | } catch (e) {
|
102 | mv = null;
|
103 | }
|
104 |
|
105 | try {
|
106 | var sourceMapSupport = require('source-map-support' + '');
|
107 | } catch (_) {
|
108 | sourceMapSupport = null;
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | function objCopy(obj) {
|
119 | if (obj == null) {
|
120 | return obj;
|
121 | } else if (Array.isArray(obj)) {
|
122 | return obj.slice();
|
123 | } else if (typeof (obj) === 'object') {
|
124 | var copy = {};
|
125 | Object.keys(obj).forEach(function (k) {
|
126 | copy[k] = obj[k];
|
127 | });
|
128 | return copy;
|
129 | } else {
|
130 | return obj;
|
131 | }
|
132 | }
|
133 |
|
134 | var format = util.format;
|
135 | if (!format) {
|
136 |
|
137 |
|
138 | var inspect = util.inspect;
|
139 | var formatRegExp = /%[sdj%]/g;
|
140 | format = function format(f) {
|
141 | if (typeof (f) !== 'string') {
|
142 | var objects = [];
|
143 | for (var i = 0; i < arguments.length; i++) {
|
144 | objects.push(inspect(arguments[i]));
|
145 | }
|
146 | return objects.join(' ');
|
147 | }
|
148 |
|
149 | var i = 1;
|
150 | var args = arguments;
|
151 | var len = args.length;
|
152 | var str = String(f).replace(formatRegExp, function (x) {
|
153 | if (i >= len)
|
154 | return x;
|
155 | switch (x) {
|
156 | case '%s': return String(args[i++]);
|
157 | case '%d': return Number(args[i++]);
|
158 | case '%j': return fastAndSafeJsonStringify(args[i++]);
|
159 | case '%%': return '%';
|
160 | default:
|
161 | return x;
|
162 | }
|
163 | });
|
164 | for (var x = args[i]; i < len; x = args[++i]) {
|
165 | if (x === null || typeof (x) !== 'object') {
|
166 | str += ' ' + x;
|
167 | } else {
|
168 | str += ' ' + inspect(x);
|
169 | }
|
170 | }
|
171 | return str;
|
172 | };
|
173 | }
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | function getCaller3Info() {
|
181 | if (this === undefined) {
|
182 |
|
183 | return;
|
184 | }
|
185 | var obj = {};
|
186 | var saveLimit = Error.stackTraceLimit;
|
187 | var savePrepare = Error.prepareStackTrace;
|
188 | Error.stackTraceLimit = 3;
|
189 |
|
190 | Error.prepareStackTrace = function (_, stack) {
|
191 | var caller = stack[2];
|
192 | if (sourceMapSupport) {
|
193 | caller = sourceMapSupport.wrapCallSite(caller);
|
194 | }
|
195 | obj.file = caller.getFileName();
|
196 | obj.line = caller.getLineNumber();
|
197 | var func = caller.getFunctionName();
|
198 | if (func)
|
199 | obj.func = func;
|
200 | };
|
201 | Error.captureStackTrace(this, getCaller3Info);
|
202 | this.stack;
|
203 |
|
204 | Error.stackTraceLimit = saveLimit;
|
205 | Error.prepareStackTrace = savePrepare;
|
206 | return obj;
|
207 | }
|
208 |
|
209 |
|
210 | function _indent(s, indent) {
|
211 | if (!indent) indent = ' ';
|
212 | var lines = s.split(/\r?\n/g);
|
213 | return indent + lines.join('\n' + indent);
|
214 | }
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | function _warn(msg, dedupKey) {
|
225 | assert.ok(msg);
|
226 | if (dedupKey) {
|
227 | if (_warned[dedupKey]) {
|
228 | return;
|
229 | }
|
230 | _warned[dedupKey] = true;
|
231 | }
|
232 | process.stderr.write(msg + '\n');
|
233 | }
|
234 | function _haveWarned(dedupKey) {
|
235 | return _warned[dedupKey];
|
236 | }
|
237 | var _warned = {};
|
238 |
|
239 |
|
240 | function ConsoleRawStream() {}
|
241 | ConsoleRawStream.prototype.write = function (rec) {
|
242 | if (rec.level < INFO) {
|
243 | console.log(rec);
|
244 | } else if (rec.level < WARN) {
|
245 | console.info(rec);
|
246 | } else if (rec.level < ERROR) {
|
247 | console.warn(rec);
|
248 | } else {
|
249 | console.error(rec);
|
250 | }
|
251 | };
|
252 |
|
253 |
|
254 |
|
255 |
|
256 | var TRACE = 10;
|
257 | var DEBUG = 20;
|
258 | var INFO = 30;
|
259 | var WARN = 40;
|
260 | var ERROR = 50;
|
261 | var FATAL = 60;
|
262 |
|
263 | var levelFromName = {
|
264 | 'trace': TRACE,
|
265 | 'debug': DEBUG,
|
266 | 'info': INFO,
|
267 | 'warn': WARN,
|
268 | 'error': ERROR,
|
269 | 'fatal': FATAL
|
270 | };
|
271 | var nameFromLevel = {};
|
272 | Object.keys(levelFromName).forEach(function (name) {
|
273 | nameFromLevel[levelFromName[name]] = name;
|
274 | });
|
275 |
|
276 |
|
277 | var dtp = undefined;
|
278 | var probes = dtrace && {};
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | function resolveLevel(nameOrNum) {
|
288 | var level;
|
289 | var type = typeof (nameOrNum);
|
290 | if (type === 'string') {
|
291 | level = levelFromName[nameOrNum.toLowerCase()];
|
292 | if (!level) {
|
293 | throw new Error(format('unknown level name: "%s"', nameOrNum));
|
294 | }
|
295 | } else if (type !== 'number') {
|
296 | throw new TypeError(format('cannot resolve level: invalid arg (%s):',
|
297 | type, nameOrNum));
|
298 | } else if (nameOrNum < 0 || Math.floor(nameOrNum) !== nameOrNum) {
|
299 | throw new TypeError(format('level is not a positive integer: %s',
|
300 | nameOrNum));
|
301 | } else {
|
302 | level = nameOrNum;
|
303 | }
|
304 | return level;
|
305 | }
|
306 |
|
307 |
|
308 | function isWritable(obj) {
|
309 | if (obj instanceof stream.Writable) {
|
310 | return true;
|
311 | }
|
312 | return typeof (obj.write) === 'function';
|
313 | }
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 | function Logger(options, _childOptions, _childSimple) {
|
354 | xxx('Logger start:', options)
|
355 | if (!(this instanceof Logger)) {
|
356 | return new Logger(options, _childOptions);
|
357 | }
|
358 |
|
359 |
|
360 | var parent;
|
361 | if (_childOptions !== undefined) {
|
362 | parent = options;
|
363 | options = _childOptions;
|
364 | if (!(parent instanceof Logger)) {
|
365 | throw new TypeError(
|
366 | 'invalid Logger creation: do not pass a second arg');
|
367 | }
|
368 | }
|
369 | if (!options) {
|
370 | throw new TypeError('options (object) is required');
|
371 | }
|
372 | if (!parent) {
|
373 | if (!options.name) {
|
374 | throw new TypeError('options.name (string) is required');
|
375 | }
|
376 | } else {
|
377 | if (options.name) {
|
378 | throw new TypeError(
|
379 | 'invalid options.name: child cannot set logger name');
|
380 | }
|
381 | }
|
382 | if (options.stream && options.streams) {
|
383 | throw new TypeError('cannot mix "streams" and "stream" options');
|
384 | }
|
385 | if (options.streams && !Array.isArray(options.streams)) {
|
386 | throw new TypeError('invalid options.streams: must be an array')
|
387 | }
|
388 | if (options.serializers && (typeof (options.serializers) !== 'object' ||
|
389 | Array.isArray(options.serializers))) {
|
390 | throw new TypeError('invalid options.serializers: must be an object')
|
391 | }
|
392 |
|
393 | EventEmitter.call(this);
|
394 |
|
395 |
|
396 | if (parent && _childSimple) {
|
397 |
|
398 |
|
399 | this._isSimpleChild = true;
|
400 |
|
401 | this._level = parent._level;
|
402 | this.streams = parent.streams;
|
403 | this.serializers = parent.serializers;
|
404 | this.src = parent.src;
|
405 | var fields = this.fields = {};
|
406 | var parentFieldNames = Object.keys(parent.fields);
|
407 | for (var i = 0; i < parentFieldNames.length; i++) {
|
408 | var name = parentFieldNames[i];
|
409 | fields[name] = parent.fields[name];
|
410 | }
|
411 | var names = Object.keys(options);
|
412 | for (var i = 0; i < names.length; i++) {
|
413 | var name = names[i];
|
414 | fields[name] = options[name];
|
415 | }
|
416 | return;
|
417 | }
|
418 |
|
419 |
|
420 | var self = this;
|
421 | if (parent) {
|
422 | this._level = parent._level;
|
423 | this.streams = [];
|
424 | for (var i = 0; i < parent.streams.length; i++) {
|
425 | var s = objCopy(parent.streams[i]);
|
426 | s.closeOnExit = false;
|
427 | this.streams.push(s);
|
428 | }
|
429 | this.serializers = objCopy(parent.serializers);
|
430 | this.src = parent.src;
|
431 | this.fields = objCopy(parent.fields);
|
432 | if (options.level) {
|
433 | this.level(options.level);
|
434 | }
|
435 | } else {
|
436 | this._level = Number.POSITIVE_INFINITY;
|
437 | this.streams = [];
|
438 | this.serializers = null;
|
439 | this.src = false;
|
440 | this.fields = {};
|
441 | }
|
442 |
|
443 | if (!dtp && dtrace) {
|
444 | dtp = dtrace.createDTraceProvider('bunyan');
|
445 |
|
446 | for (var level in levelFromName) {
|
447 | var probe;
|
448 |
|
449 | probes[levelFromName[level]] = probe =
|
450 | dtp.addProbe('log-' + level, 'char *');
|
451 |
|
452 |
|
453 | probe.dtp = dtp;
|
454 | }
|
455 |
|
456 | dtp.enable();
|
457 | }
|
458 |
|
459 |
|
460 |
|
461 | if (options.stream) {
|
462 | self.addStream({
|
463 | type: 'stream',
|
464 | stream: options.stream,
|
465 | closeOnExit: false,
|
466 | level: options.level
|
467 | });
|
468 | } else if (options.streams) {
|
469 | options.streams.forEach(function (s) {
|
470 | self.addStream(s, options.level);
|
471 | });
|
472 | } else if (parent && options.level) {
|
473 | this.level(options.level);
|
474 | } else if (!parent) {
|
475 | if (runtimeEnv === 'browser') {
|
476 | |
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 | self.addStream({
|
484 | type: 'raw',
|
485 | stream: new ConsoleRawStream(),
|
486 | closeOnExit: false,
|
487 | level: options.level
|
488 | });
|
489 | } else {
|
490 | self.addStream({
|
491 | type: 'stream',
|
492 | stream: process.stdout,
|
493 | closeOnExit: false,
|
494 | level: options.level
|
495 | });
|
496 | }
|
497 | }
|
498 | if (options.serializers) {
|
499 | self.addSerializers(options.serializers);
|
500 | }
|
501 | if (options.src) {
|
502 | this.src = true;
|
503 | }
|
504 | xxx('Logger: ', self)
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 | var fields = objCopy(options);
|
512 | delete fields.stream;
|
513 | delete fields.level;
|
514 | delete fields.streams;
|
515 | delete fields.serializers;
|
516 | delete fields.src;
|
517 | if (this.serializers) {
|
518 | this._applySerializers(fields);
|
519 | }
|
520 | if (!fields.hostname && !self.fields.hostname) {
|
521 | fields.hostname = os.hostname();
|
522 | }
|
523 | if (!fields.pid) {
|
524 | fields.pid = process.pid;
|
525 | }
|
526 | Object.keys(fields).forEach(function (k) {
|
527 | self.fields[k] = fields[k];
|
528 | });
|
529 | }
|
530 |
|
531 | util.inherits(Logger, EventEmitter);
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | Logger.prototype.addStream = function addStream(s, defaultLevel) {
|
552 | var self = this;
|
553 | if (defaultLevel === null || defaultLevel === undefined) {
|
554 | defaultLevel = INFO;
|
555 | }
|
556 |
|
557 | s = objCopy(s);
|
558 |
|
559 |
|
560 | if (!s.type) {
|
561 | if (s.stream) {
|
562 | s.type = 'stream';
|
563 | } else if (s.path) {
|
564 | s.type = 'file'
|
565 | }
|
566 | }
|
567 | s.raw = (s.type === 'raw');
|
568 |
|
569 | if (s.level !== undefined) {
|
570 | s.level = resolveLevel(s.level);
|
571 | } else {
|
572 | s.level = resolveLevel(defaultLevel);
|
573 | }
|
574 | if (s.level < self._level) {
|
575 | self._level = s.level;
|
576 | }
|
577 |
|
578 | switch (s.type) {
|
579 | case 'stream':
|
580 | assert.ok(isWritable(s.stream),
|
581 | '"stream" stream is not writable: ' + util.inspect(s.stream));
|
582 |
|
583 | if (!s.closeOnExit) {
|
584 | s.closeOnExit = false;
|
585 | }
|
586 | break;
|
587 | case 'file':
|
588 | if (s.reemitErrorEvents === undefined) {
|
589 | s.reemitErrorEvents = true;
|
590 | }
|
591 | if (!s.stream) {
|
592 | s.stream = fs.createWriteStream(s.path,
|
593 | {flags: 'a', encoding: 'utf8'});
|
594 | if (!s.closeOnExit) {
|
595 | s.closeOnExit = true;
|
596 | }
|
597 | } else {
|
598 | if (!s.closeOnExit) {
|
599 | s.closeOnExit = false;
|
600 | }
|
601 | }
|
602 | break;
|
603 | case 'rotating-file':
|
604 | assert.ok(!s.stream,
|
605 | '"rotating-file" stream should not give a "stream"');
|
606 | assert.ok(s.path);
|
607 | assert.ok(mv, '"rotating-file" stream type is not supported: '
|
608 | + 'missing "mv" module');
|
609 | s.stream = new RotatingFileStream(s);
|
610 | if (!s.closeOnExit) {
|
611 | s.closeOnExit = true;
|
612 | }
|
613 | break;
|
614 | case 'raw':
|
615 | if (!s.closeOnExit) {
|
616 | s.closeOnExit = false;
|
617 | }
|
618 | break;
|
619 | default:
|
620 | throw new TypeError('unknown stream type "' + s.type + '"');
|
621 | }
|
622 |
|
623 | if (s.reemitErrorEvents && typeof (s.stream.on) === 'function') {
|
624 |
|
625 |
|
626 | s.stream.on('error', function onStreamError(err) {
|
627 | self.emit('error', err, s);
|
628 | });
|
629 | }
|
630 |
|
631 | self.streams.push(s);
|
632 | delete self.haveNonRawStreams;
|
633 | }
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 | Logger.prototype.addSerializers = function addSerializers(serializers) {
|
643 | var self = this;
|
644 |
|
645 | if (!self.serializers) {
|
646 | self.serializers = {};
|
647 | }
|
648 | Object.keys(serializers).forEach(function (field) {
|
649 | var serializer = serializers[field];
|
650 | if (typeof (serializer) !== 'function') {
|
651 | throw new TypeError(format(
|
652 | 'invalid serializer for "%s" field: must be a function',
|
653 | field));
|
654 | } else {
|
655 | self.serializers[field] = serializer;
|
656 | }
|
657 | });
|
658 | }
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 | Logger.prototype.child = function (options, simple) {
|
689 | return new (this.constructor)(this, options || {}, simple);
|
690 | }
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 | Logger.prototype.reopenFileStreams = function () {
|
711 | var self = this;
|
712 | self.streams.forEach(function (s) {
|
713 | if (s.type === 'file') {
|
714 | if (s.stream) {
|
715 |
|
716 |
|
717 | s.stream.end();
|
718 | s.stream.destroySoon();
|
719 | delete s.stream;
|
720 | }
|
721 | s.stream = fs.createWriteStream(s.path,
|
722 | {flags: 'a', encoding: 'utf8'});
|
723 | s.stream.on('error', function (err) {
|
724 | self.emit('error', err, s);
|
725 | });
|
726 | }
|
727 | });
|
728 | };
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 | Logger.prototype.level = function level(value) {
|
768 | if (value === undefined) {
|
769 | return this._level;
|
770 | }
|
771 | var newLevel = resolveLevel(value);
|
772 | var len = this.streams.length;
|
773 | for (var i = 0; i < len; i++) {
|
774 | this.streams[i].level = newLevel;
|
775 | }
|
776 | this._level = newLevel;
|
777 | }
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 | Logger.prototype.levels = function levels(name, value) {
|
813 | if (name === undefined) {
|
814 | assert.equal(value, undefined);
|
815 | return this.streams.map(
|
816 | function (s) { return s.level });
|
817 | }
|
818 | var stream;
|
819 | if (typeof (name) === 'number') {
|
820 | stream = this.streams[name];
|
821 | if (stream === undefined) {
|
822 | throw new Error('invalid stream index: ' + name);
|
823 | }
|
824 | } else {
|
825 | var len = this.streams.length;
|
826 | for (var i = 0; i < len; i++) {
|
827 | var s = this.streams[i];
|
828 | if (s.name === name) {
|
829 | stream = s;
|
830 | break;
|
831 | }
|
832 | }
|
833 | if (!stream) {
|
834 | throw new Error(format('no stream with name "%s"', name));
|
835 | }
|
836 | }
|
837 | if (value === undefined) {
|
838 | return stream.level;
|
839 | } else {
|
840 | var newLevel = resolveLevel(value);
|
841 | stream.level = newLevel;
|
842 | if (newLevel < this._level) {
|
843 | this._level = newLevel;
|
844 | }
|
845 | }
|
846 | }
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 | Logger.prototype._applySerializers = function (fields, excludeFields) {
|
859 | var self = this;
|
860 |
|
861 | xxx('_applySerializers: excludeFields', excludeFields);
|
862 |
|
863 |
|
864 |
|
865 | Object.keys(this.serializers).forEach(function (name) {
|
866 | if (fields[name] === undefined ||
|
867 | (excludeFields && excludeFields[name]))
|
868 | {
|
869 | return;
|
870 | }
|
871 | xxx('_applySerializers; apply to "%s" key', name)
|
872 | try {
|
873 | fields[name] = self.serializers[name](fields[name]);
|
874 | } catch (err) {
|
875 | _warn(format('bunyan: ERROR: Exception thrown from the "%s" '
|
876 | + 'Bunyan serializer. This should never happen. This is a bug'
|
877 | + 'in that serializer function.\n%s',
|
878 | name, err.stack || err));
|
879 | fields[name] = format('(Error in Bunyan log "%s" serializer '
|
880 | + 'broke field. See stderr for details.)', name);
|
881 | }
|
882 | });
|
883 | }
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 | Logger.prototype._emit = function (rec, noemit) {
|
894 | var i;
|
895 |
|
896 |
|
897 |
|
898 | if (this.haveNonRawStreams === undefined) {
|
899 | this.haveNonRawStreams = false;
|
900 | for (i = 0; i < this.streams.length; i++) {
|
901 | if (!this.streams[i].raw) {
|
902 | this.haveNonRawStreams = true;
|
903 | break;
|
904 | }
|
905 | }
|
906 | }
|
907 |
|
908 |
|
909 | var str;
|
910 | if (noemit || this.haveNonRawStreams) {
|
911 | str = fastAndSafeJsonStringify(rec) + '\n';
|
912 | }
|
913 |
|
914 | if (noemit)
|
915 | return str;
|
916 |
|
917 | var level = rec.level;
|
918 | for (i = 0; i < this.streams.length; i++) {
|
919 | var s = this.streams[i];
|
920 | if (s.level <= level) {
|
921 | xxx('writing log rec "%s" to "%s" stream (%d <= %d): %j',
|
922 | rec.msg, s.type, s.level, level, rec);
|
923 | s.stream.write(s.raw ? rec : str);
|
924 | }
|
925 | };
|
926 |
|
927 | return str;
|
928 | }
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 | function mkRecord(log, minLevel, args) {
|
936 | var excludeFields, fields, msgArgs;
|
937 | if (args[0] instanceof Error) {
|
938 |
|
939 | fields = {
|
940 |
|
941 | err: (log.serializers && log.serializers.err
|
942 | ? log.serializers.err(args[0])
|
943 | : Logger.stdSerializers.err(args[0]))
|
944 | };
|
945 | excludeFields = {err: true};
|
946 | if (args.length === 1) {
|
947 | msgArgs = [fields.err.message];
|
948 | } else {
|
949 | msgArgs = args.slice(1);
|
950 | }
|
951 | } else if (typeof (args[0]) !== 'object' || Array.isArray(args[0])) {
|
952 |
|
953 | fields = null;
|
954 | msgArgs = args.slice();
|
955 | } else if (Buffer.isBuffer(args[0])) {
|
956 |
|
957 |
|
958 | fields = null;
|
959 | msgArgs = args.slice();
|
960 | msgArgs[0] = util.inspect(msgArgs[0]);
|
961 | } else {
|
962 | fields = args[0];
|
963 | if (fields && args.length === 1 && fields.err &&
|
964 | fields.err instanceof Error)
|
965 | {
|
966 | msgArgs = [fields.err.message];
|
967 | } else {
|
968 | msgArgs = args.slice(1);
|
969 | }
|
970 | }
|
971 |
|
972 |
|
973 | var rec = objCopy(log.fields);
|
974 | var level = rec.level = minLevel;
|
975 | var recFields = (fields ? objCopy(fields) : null);
|
976 | if (recFields) {
|
977 | if (log.serializers) {
|
978 | log._applySerializers(recFields, excludeFields);
|
979 | }
|
980 | Object.keys(recFields).forEach(function (k) {
|
981 | rec[k] = recFields[k];
|
982 | });
|
983 | }
|
984 | rec.msg = format.apply(log, msgArgs);
|
985 | if (!rec.time) {
|
986 | rec.time = (new Date());
|
987 | }
|
988 |
|
989 | if (log.src && !rec.src) {
|
990 | rec.src = getCaller3Info()
|
991 | }
|
992 | rec.v = LOG_VERSION;
|
993 |
|
994 | return rec;
|
995 | };
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 | function mkProbeArgs(str, log, minLevel, msgArgs) {
|
1004 | return [ str || log._emit(mkRecord(log, minLevel, msgArgs), true) ];
|
1005 | }
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 | function mkLogEmitter(minLevel) {
|
1013 | return function () {
|
1014 | var log = this;
|
1015 | var str = null;
|
1016 | var rec = null;
|
1017 |
|
1018 | if (!this._emit) {
|
1019 | |
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 | var dedupKey = 'unbound';
|
1026 | if (!_haveWarned[dedupKey]) {
|
1027 | var caller = getCaller3Info();
|
1028 | _warn(format('bunyan usage error: %s:%s: attempt to log '
|
1029 | + 'with an unbound log method: `this` is: %s',
|
1030 | caller.file, caller.line, util.inspect(this)),
|
1031 | dedupKey);
|
1032 | }
|
1033 | return;
|
1034 | } else if (arguments.length === 0) {
|
1035 | return (this._level <= minLevel);
|
1036 | }
|
1037 |
|
1038 | var msgArgs = new Array(arguments.length);
|
1039 | for (var i = 0; i < msgArgs.length; ++i) {
|
1040 | msgArgs[i] = arguments[i];
|
1041 | }
|
1042 |
|
1043 | if (this._level <= minLevel) {
|
1044 | rec = mkRecord(log, minLevel, msgArgs);
|
1045 | str = this._emit(rec);
|
1046 | }
|
1047 |
|
1048 | if (probes) {
|
1049 | probes[minLevel].fire(mkProbeArgs, str, log, minLevel, msgArgs);
|
1050 | }
|
1051 | }
|
1052 | }
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 | Logger.prototype.trace = mkLogEmitter(TRACE);
|
1074 | Logger.prototype.debug = mkLogEmitter(DEBUG);
|
1075 | Logger.prototype.info = mkLogEmitter(INFO);
|
1076 | Logger.prototype.warn = mkLogEmitter(WARN);
|
1077 | Logger.prototype.error = mkLogEmitter(ERROR);
|
1078 | Logger.prototype.fatal = mkLogEmitter(FATAL);
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 | Logger.stdSerializers = {};
|
1088 |
|
1089 |
|
1090 | Logger.stdSerializers.req = function req(req) {
|
1091 | if (!req || !req.connection)
|
1092 | return req;
|
1093 | return {
|
1094 | method: req.method,
|
1095 | url: req.url,
|
1096 | headers: req.headers,
|
1097 | remoteAddress: req.connection.remoteAddress,
|
1098 | remotePort: req.connection.remotePort
|
1099 | };
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 | };
|
1106 |
|
1107 |
|
1108 | Logger.stdSerializers.res = function res(res) {
|
1109 | if (!res || !res.statusCode)
|
1110 | return res;
|
1111 | return {
|
1112 | statusCode: res.statusCode,
|
1113 | header: res._header
|
1114 | }
|
1115 | };
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 | function getFullErrorStack(ex)
|
1128 | {
|
1129 | var ret = ex.stack || ex.toString();
|
1130 | if (ex.cause && typeof (ex.cause) === 'function') {
|
1131 | var cex = ex.cause();
|
1132 | if (cex) {
|
1133 | ret += '\nCaused by: ' + getFullErrorStack(cex);
|
1134 | }
|
1135 | }
|
1136 | return (ret);
|
1137 | }
|
1138 |
|
1139 |
|
1140 |
|
1141 | var errSerializer = Logger.stdSerializers.err = function err(err) {
|
1142 | if (!err || !err.stack)
|
1143 | return err;
|
1144 | var obj = {
|
1145 | message: err.message,
|
1146 | name: err.name,
|
1147 | stack: getFullErrorStack(err),
|
1148 | code: err.code,
|
1149 | signal: err.signal
|
1150 | }
|
1151 | return obj;
|
1152 | };
|
1153 |
|
1154 |
|
1155 |
|
1156 | function safeCyclesSet() {
|
1157 | var seen = new Set();
|
1158 | return function (key, val) {
|
1159 | if (!val || typeof (val) !== 'object') {
|
1160 | return val;
|
1161 | }
|
1162 | if (seen.has(val)) {
|
1163 | return '[Circular]';
|
1164 | }
|
1165 | seen.add(val);
|
1166 | return val;
|
1167 | };
|
1168 | }
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 | function safeCyclesArray() {
|
1179 | var seen = [];
|
1180 | return function (key, val) {
|
1181 | if (!val || typeof (val) !== 'object') {
|
1182 | return val;
|
1183 | }
|
1184 | if (seen.indexOf(val) !== -1) {
|
1185 | return '[Circular]';
|
1186 | }
|
1187 | seen.push(val);
|
1188 | return val;
|
1189 | };
|
1190 | }
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 | var safeCycles = Set ? safeCyclesSet : safeCyclesArray;
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 | function fastAndSafeJsonStringify(rec) {
|
1211 | try {
|
1212 | return JSON.stringify(rec);
|
1213 | } catch (ex) {
|
1214 | try {
|
1215 | return JSON.stringify(rec, safeCycles());
|
1216 | } catch (e) {
|
1217 | if (safeJsonStringify) {
|
1218 | return safeJsonStringify(rec);
|
1219 | } else {
|
1220 | var dedupKey = e.stack.split(/\n/g, 3).join('\n');
|
1221 | _warn('bunyan: ERROR: Exception in '
|
1222 | + '`JSON.stringify(rec)`. You can install the '
|
1223 | + '"safe-json-stringify" module to have Bunyan fallback '
|
1224 | + 'to safer stringification. Record:\n'
|
1225 | + _indent(format('%s\n%s', util.inspect(rec), e.stack)),
|
1226 | dedupKey);
|
1227 | return format('(Exception in JSON.stringify(rec): %j. '
|
1228 | + 'See stderr for details.)', e.message);
|
1229 | }
|
1230 | }
|
1231 | }
|
1232 | }
|
1233 |
|
1234 |
|
1235 | var RotatingFileStream = null;
|
1236 | if (mv) {
|
1237 |
|
1238 | RotatingFileStream = function RotatingFileStream(options) {
|
1239 | this.path = options.path;
|
1240 |
|
1241 | this.count = (options.count == null ? 10 : options.count);
|
1242 | assert.equal(typeof (this.count), 'number',
|
1243 | format('rotating-file stream "count" is not a number: %j (%s) in %j',
|
1244 | this.count, typeof (this.count), this));
|
1245 | assert.ok(this.count >= 0,
|
1246 | format('rotating-file stream "count" is not >= 0: %j in %j',
|
1247 | this.count, this));
|
1248 |
|
1249 |
|
1250 | if (options.period) {
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 | var period = {
|
1260 | 'hourly': '1h',
|
1261 | 'daily': '1d',
|
1262 | 'weekly': '1w',
|
1263 | 'monthly': '1m',
|
1264 | 'yearly': '1y'
|
1265 | }[options.period] || options.period;
|
1266 | var m = /^([1-9][0-9]*)([hdwmy]|ms)$/.exec(period);
|
1267 | if (!m) {
|
1268 | throw new Error(format('invalid period: "%s"', options.period));
|
1269 | }
|
1270 | this.periodNum = Number(m[1]);
|
1271 | this.periodScope = m[2];
|
1272 | } else {
|
1273 | this.periodNum = 1;
|
1274 | this.periodScope = 'd';
|
1275 | }
|
1276 |
|
1277 | var lastModified = null;
|
1278 | try {
|
1279 | var fileInfo = fs.statSync(this.path);
|
1280 | lastModified = fileInfo.mtime.getTime();
|
1281 | }
|
1282 | catch (err) {
|
1283 |
|
1284 | }
|
1285 | var rotateAfterOpen = false;
|
1286 | if (lastModified) {
|
1287 | var lastRotTime = this._calcRotTime(0);
|
1288 | if (lastModified < lastRotTime) {
|
1289 | rotateAfterOpen = true;
|
1290 | }
|
1291 | }
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 | this.stream = fs.createWriteStream(this.path,
|
1310 | {flags: 'a', encoding: 'utf8'});
|
1311 |
|
1312 | this.rotQueue = [];
|
1313 | this.rotating = false;
|
1314 | if (rotateAfterOpen) {
|
1315 | this._debug('rotateAfterOpen -> call rotate()');
|
1316 | this.rotate();
|
1317 | } else {
|
1318 | this._setupNextRot();
|
1319 | }
|
1320 | }
|
1321 |
|
1322 | util.inherits(RotatingFileStream, EventEmitter);
|
1323 |
|
1324 | RotatingFileStream.prototype._debug = function () {
|
1325 |
|
1326 | if (false) {
|
1327 | if (arguments.length === 0) {
|
1328 | return true;
|
1329 | }
|
1330 | var args = Array.prototype.slice.call(arguments);
|
1331 | args[0] = '[' + (new Date().toISOString()) + ', '
|
1332 | + this.path + '] ' + args[0];
|
1333 | console.log.apply(this, args);
|
1334 | } else {
|
1335 | return false;
|
1336 | }
|
1337 | };
|
1338 |
|
1339 | RotatingFileStream.prototype._setupNextRot = function () {
|
1340 | this.rotAt = this._calcRotTime(1);
|
1341 | this._setRotationTimer();
|
1342 | }
|
1343 |
|
1344 | RotatingFileStream.prototype._setRotationTimer = function () {
|
1345 | var self = this;
|
1346 | var delay = this.rotAt - Date.now();
|
1347 |
|
1348 |
|
1349 | var TIMEOUT_MAX = 2147483647;
|
1350 | if (delay > TIMEOUT_MAX) {
|
1351 | delay = TIMEOUT_MAX;
|
1352 | }
|
1353 | this.timeout = setTimeout(
|
1354 | function () {
|
1355 | self._debug('_setRotationTimer timeout -> call rotate()');
|
1356 | self.rotate();
|
1357 | },
|
1358 | delay);
|
1359 | if (typeof (this.timeout.unref) === 'function') {
|
1360 | this.timeout.unref();
|
1361 | }
|
1362 | }
|
1363 |
|
1364 | RotatingFileStream.prototype._calcRotTime =
|
1365 | function _calcRotTime(periodOffset) {
|
1366 | this._debug('_calcRotTime: %s%s', this.periodNum, this.periodScope);
|
1367 | var d = new Date();
|
1368 |
|
1369 | this._debug(' now local: %s', d);
|
1370 | this._debug(' now utc: %s', d.toISOString());
|
1371 | var rotAt;
|
1372 | switch (this.periodScope) {
|
1373 | case 'ms':
|
1374 |
|
1375 | if (this.rotAt) {
|
1376 | rotAt = this.rotAt + this.periodNum * periodOffset;
|
1377 | } else {
|
1378 | rotAt = Date.now() + this.periodNum * periodOffset;
|
1379 | }
|
1380 | break;
|
1381 | case 'h':
|
1382 | if (this.rotAt) {
|
1383 | rotAt = this.rotAt + this.periodNum * 60 * 60 * 1000 * periodOffset;
|
1384 | } else {
|
1385 |
|
1386 | rotAt = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(),
|
1387 | d.getUTCDate(), d.getUTCHours() + periodOffset);
|
1388 | }
|
1389 | break;
|
1390 | case 'd':
|
1391 | if (this.rotAt) {
|
1392 | rotAt = this.rotAt + this.periodNum * 24 * 60 * 60 * 1000
|
1393 | * periodOffset;
|
1394 | } else {
|
1395 |
|
1396 | rotAt = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(),
|
1397 | d.getUTCDate() + periodOffset);
|
1398 | }
|
1399 | break;
|
1400 | case 'w':
|
1401 |
|
1402 | if (this.rotAt) {
|
1403 | rotAt = this.rotAt + this.periodNum * 7 * 24 * 60 * 60 * 1000
|
1404 | * periodOffset;
|
1405 | } else {
|
1406 |
|
1407 | var dayOffset = (7 - d.getUTCDay());
|
1408 | if (periodOffset < 1) {
|
1409 | dayOffset = -d.getUTCDay();
|
1410 | }
|
1411 | if (periodOffset > 1 || periodOffset < -1) {
|
1412 | dayOffset += 7 * periodOffset;
|
1413 | }
|
1414 | rotAt = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(),
|
1415 | d.getUTCDate() + dayOffset);
|
1416 | }
|
1417 | break;
|
1418 | case 'm':
|
1419 | if (this.rotAt) {
|
1420 | rotAt = Date.UTC(d.getUTCFullYear(),
|
1421 | d.getUTCMonth() + this.periodNum * periodOffset, 1);
|
1422 | } else {
|
1423 |
|
1424 | rotAt = Date.UTC(d.getUTCFullYear(),
|
1425 | d.getUTCMonth() + periodOffset, 1);
|
1426 | }
|
1427 | break;
|
1428 | case 'y':
|
1429 | if (this.rotAt) {
|
1430 | rotAt = Date.UTC(d.getUTCFullYear() + this.periodNum * periodOffset,
|
1431 | 0, 1);
|
1432 | } else {
|
1433 |
|
1434 | rotAt = Date.UTC(d.getUTCFullYear() + periodOffset, 0, 1);
|
1435 | }
|
1436 | break;
|
1437 | default:
|
1438 | assert.fail(format('invalid period scope: "%s"', this.periodScope));
|
1439 | }
|
1440 |
|
1441 | if (this._debug()) {
|
1442 | this._debug(' **rotAt**: %s (utc: %s)', rotAt,
|
1443 | new Date(rotAt).toUTCString());
|
1444 | var now = Date.now();
|
1445 | this._debug(' now: %s (%sms == %smin == %sh to go)',
|
1446 | now,
|
1447 | rotAt - now,
|
1448 | (rotAt-now)/1000/60,
|
1449 | (rotAt-now)/1000/60/60);
|
1450 | }
|
1451 | return rotAt;
|
1452 | };
|
1453 |
|
1454 | RotatingFileStream.prototype.rotate = function rotate() {
|
1455 |
|
1456 | var self = this;
|
1457 |
|
1458 |
|
1459 |
|
1460 | if (self.rotAt && self.rotAt > Date.now()) {
|
1461 | return self._setRotationTimer();
|
1462 | }
|
1463 |
|
1464 | this._debug('rotate');
|
1465 | if (self.rotating) {
|
1466 | throw new TypeError('cannot start a rotation when already rotating');
|
1467 | }
|
1468 | self.rotating = true;
|
1469 |
|
1470 | self.stream.end();
|
1471 |
|
1472 | function del() {
|
1473 | var toDel = self.path + '.' + String(n - 1);
|
1474 | if (n === 0) {
|
1475 | toDel = self.path;
|
1476 | }
|
1477 | n -= 1;
|
1478 | self._debug(' rm %s', toDel);
|
1479 | fs.unlink(toDel, function (delErr) {
|
1480 |
|
1481 | moves();
|
1482 | });
|
1483 | }
|
1484 |
|
1485 | function moves() {
|
1486 | if (self.count === 0 || n < 0) {
|
1487 | return finish();
|
1488 | }
|
1489 | var before = self.path;
|
1490 | var after = self.path + '.' + String(n);
|
1491 | if (n > 0) {
|
1492 | before += '.' + String(n - 1);
|
1493 | }
|
1494 | n -= 1;
|
1495 | fs.exists(before, function (exists) {
|
1496 | if (!exists) {
|
1497 | moves();
|
1498 | } else {
|
1499 | self._debug(' mv %s %s', before, after);
|
1500 | mv(before, after, function (mvErr) {
|
1501 | if (mvErr) {
|
1502 | self.emit('error', mvErr);
|
1503 | finish();
|
1504 | } else {
|
1505 | moves();
|
1506 | }
|
1507 | });
|
1508 | }
|
1509 | })
|
1510 | }
|
1511 |
|
1512 | function finish() {
|
1513 | self._debug(' open %s', self.path);
|
1514 | self.stream = fs.createWriteStream(self.path,
|
1515 | {flags: 'a', encoding: 'utf8'});
|
1516 | var q = self.rotQueue, len = q.length;
|
1517 | for (var i = 0; i < len; i++) {
|
1518 | self.stream.write(q[i]);
|
1519 | }
|
1520 | self.rotQueue = [];
|
1521 | self.rotating = false;
|
1522 | self.emit('drain');
|
1523 | self._setupNextRot();
|
1524 | }
|
1525 |
|
1526 | var n = this.count;
|
1527 | del();
|
1528 | };
|
1529 |
|
1530 | RotatingFileStream.prototype.write = function write(s) {
|
1531 | if (this.rotating) {
|
1532 | this.rotQueue.push(s);
|
1533 | return false;
|
1534 | } else {
|
1535 | return this.stream.write(s);
|
1536 | }
|
1537 | };
|
1538 |
|
1539 | RotatingFileStream.prototype.end = function end(s) {
|
1540 | this.stream.end();
|
1541 | };
|
1542 |
|
1543 | RotatingFileStream.prototype.destroy = function destroy(s) {
|
1544 | this.stream.destroy();
|
1545 | };
|
1546 |
|
1547 | RotatingFileStream.prototype.destroySoon = function destroySoon(s) {
|
1548 | this.stream.destroySoon();
|
1549 | };
|
1550 |
|
1551 | }
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 | function RingBuffer(options) {
|
1564 | this.limit = options && options.limit ? options.limit : 100;
|
1565 | this.writable = true;
|
1566 | this.records = [];
|
1567 | EventEmitter.call(this);
|
1568 | }
|
1569 |
|
1570 | util.inherits(RingBuffer, EventEmitter);
|
1571 |
|
1572 | RingBuffer.prototype.write = function (record) {
|
1573 | if (!this.writable)
|
1574 | throw (new Error('RingBuffer has been ended already'));
|
1575 |
|
1576 | this.records.push(record);
|
1577 |
|
1578 | if (this.records.length > this.limit)
|
1579 | this.records.shift();
|
1580 |
|
1581 | return (true);
|
1582 | };
|
1583 |
|
1584 | RingBuffer.prototype.end = function () {
|
1585 | if (arguments.length > 0)
|
1586 | this.write.apply(this, Array.prototype.slice.call(arguments));
|
1587 | this.writable = false;
|
1588 | };
|
1589 |
|
1590 | RingBuffer.prototype.destroy = function () {
|
1591 | this.writable = false;
|
1592 | this.emit('close');
|
1593 | };
|
1594 |
|
1595 | RingBuffer.prototype.destroySoon = function () {
|
1596 | this.destroy();
|
1597 | };
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 | module.exports = Logger;
|
1603 |
|
1604 | module.exports.TRACE = TRACE;
|
1605 | module.exports.DEBUG = DEBUG;
|
1606 | module.exports.INFO = INFO;
|
1607 | module.exports.WARN = WARN;
|
1608 | module.exports.ERROR = ERROR;
|
1609 | module.exports.FATAL = FATAL;
|
1610 | module.exports.resolveLevel = resolveLevel;
|
1611 | module.exports.levelFromName = levelFromName;
|
1612 | module.exports.nameFromLevel = nameFromLevel;
|
1613 |
|
1614 | module.exports.VERSION = VERSION;
|
1615 | module.exports.LOG_VERSION = LOG_VERSION;
|
1616 |
|
1617 | module.exports.createLogger = function createLogger(options) {
|
1618 | return new Logger(options);
|
1619 | };
|
1620 |
|
1621 | module.exports.RingBuffer = RingBuffer;
|
1622 | module.exports.RotatingFileStream = RotatingFileStream;
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 | module.exports.safeCycles = safeCycles;
|