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