modular-log
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -12,7 +12,9 @@ "use strict"; | ||
}); | ||
log.setupSummarizer(); | ||
log.setupSummarizer({ | ||
level: 'warn', | ||
allowed: { fatal: 0 } | ||
}); | ||
var cnt = 0; // Helper variable | ||
// First logger object | ||
var logger = log.createLogger('App'); | ||
logger.fatal('Testing', { cnt: cnt++ }); | ||
logger.error('Testing', { cnt: cnt++ }); | ||
@@ -23,4 +25,8 @@ logger.warn('Testing', { cnt: cnt++ }); | ||
logger.trace('Testing', { cnt: cnt++ }); | ||
logger.trace('canContinue', log.canContinue()); | ||
// Preparing delayed log | ||
setTimeout(function () { return logger.fatal('Testing', { cnt: cnt++ }); }, 1000); | ||
setTimeout(function () { | ||
logger.fatal('Testing', { cnt: cnt++ }); | ||
logger.warn('CanContinue', log.canContinue()); | ||
}, 1000); | ||
// Second logger object | ||
@@ -27,0 +33,0 @@ var logger2 = log.createLogger('Another'); |
@@ -14,3 +14,6 @@ import * as log from '../lib/index'; | ||
log.setupSummarizer(); | ||
log.setupSummarizer({ | ||
level: 'warn', | ||
allowed: { fatal: 0 } | ||
}); | ||
@@ -21,3 +24,2 @@ let cnt = 0; // Helper variable | ||
let logger = log.createLogger('App'); | ||
logger.fatal('Testing', { cnt: cnt++ }); | ||
logger.error('Testing', { cnt: cnt++ }); | ||
@@ -28,5 +30,9 @@ logger.warn('Testing', { cnt: cnt++ }); | ||
logger.trace('Testing', { cnt: cnt++ }); | ||
logger.trace('canContinue', log.canContinue()); | ||
// Preparing delayed log | ||
setTimeout(() => logger.fatal('Testing', { cnt: cnt++ }), 1000); | ||
setTimeout(() => { | ||
logger.fatal('Testing', { cnt: cnt++ }); | ||
logger.warn('CanContinue', log.canContinue()); | ||
}, 1000); | ||
@@ -33,0 +39,0 @@ // Second logger object |
import * as winston from 'winston'; | ||
import { SummarizerOptions } from './summarizer'; | ||
import { LogLevels } from './definitions.d'; | ||
export interface Logger extends winston.LoggerInstance { | ||
@@ -9,2 +11,3 @@ fatal(msg: string, meta?: any, callback?: () => void): Logger; | ||
trace(msg: string, meta?: any, callback?: () => void): Logger; | ||
log(level: LogLevels, msg: string, meta?: any, callback?: () => void): Logger; | ||
} | ||
@@ -21,6 +24,8 @@ export declare const levels: { | ||
export declare function setupFileLogger(options: any): void; | ||
export declare function setupSummarizer(): void; | ||
export declare function setupSummarizer(options?: SummarizerOptions): void; | ||
export declare function sumLog(): { | ||
[index: string]: number; | ||
[level: string]: number; | ||
}; | ||
export declare function canContinue(): boolean; | ||
export declare function tryContinue(): void; | ||
export declare function createLogger(module: string): Logger; |
@@ -19,2 +19,3 @@ "use strict"; | ||
return function (options) { | ||
console.log(options); | ||
var atStr = moment(options.meta.at).format('YYYY-MM-DD hh:mm:ss'); | ||
@@ -47,4 +48,4 @@ useColors && (atStr = colors.gray(atStr)); | ||
exports.setupFileLogger = setupFileLogger; | ||
function setupSummarizer() { | ||
summarizer = new summarizer_1.Summarizer(); | ||
function setupSummarizer(options) { | ||
summarizer = new summarizer_1.Summarizer(options || {}); | ||
transports.push(summarizer); | ||
@@ -55,2 +56,6 @@ } | ||
exports.sumLog = sumLog; | ||
function canContinue() { return summarizer ? summarizer.canContinue() : true; } | ||
exports.canContinue = canContinue; | ||
function tryContinue() { return summarizer && summarizer.tryContinue(); } | ||
exports.tryContinue = tryContinue; | ||
function createLogger(module) { | ||
@@ -57,0 +62,0 @@ return new winston.Logger({ |
import * as winston from 'winston'; | ||
export interface SummarizerOptions { | ||
level?: string; | ||
allowed?: { | ||
[level: string]: number; | ||
}; | ||
[param: string]: any; | ||
} | ||
export declare class Summarizer extends winston.Transport { | ||
name: string; | ||
level: string; | ||
allowed: { | ||
[level: string]: number; | ||
}; | ||
cnt: { | ||
[index: string]: number; | ||
[level: string]: number; | ||
}; | ||
constructor(options?: any); | ||
constructor(options: SummarizerOptions); | ||
log(level: any, msg: any, meta: any, callback: any): void; | ||
canContinue(): boolean; | ||
tryContinue(): void; | ||
} |
@@ -11,7 +11,7 @@ "use strict"; | ||
function Summarizer(options) { | ||
if (options === void 0) { options = {}; } | ||
_super.call(this, options); | ||
this.name = 'summarizer'; | ||
this.level = options.level || 'warn'; | ||
this.allowed = options.allowed || {}; | ||
this.cnt = {}; | ||
this.level = options.level || 'warn'; | ||
} | ||
@@ -25,2 +25,13 @@ Summarizer.prototype.log = function (level, msg, meta, callback) { | ||
}; | ||
Summarizer.prototype.canContinue = function () { | ||
for (var key in this.allowed) { | ||
if (this.allowed[key] >= 0 && this.allowed[key] < this.cnt[key]) | ||
return false; | ||
} | ||
return true; | ||
}; | ||
Summarizer.prototype.tryContinue = function () { | ||
if (!this.canContinue()) | ||
throw new Error('Too many erroreous logs'); | ||
}; | ||
return Summarizer; | ||
@@ -27,0 +38,0 @@ }(winston.Transport)); |
{ | ||
"name": "modular-log", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Modular components based on Winston logger", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14592
240