@tinkoff/logger
Advanced tools
Comparing version 0.10.168 to 0.10.169
@@ -123,6 +123,6 @@ import toLower from '@tinkoff/utils/string/toLower'; | ||
addBeforeReporter(reporter) { | ||
this.beforeReporters = this.beforeReporters.concat(reporter); | ||
this.reporters = this.reporters.concat(reporter); | ||
} | ||
setBeforeReporters(reporters) { | ||
this.beforeReporters = toArray(reporters); | ||
this.reporters = toArray(reporters); | ||
} | ||
@@ -172,17 +172,4 @@ addReporter(reporter) { | ||
log(level, args) { | ||
var _a; | ||
let logObj; | ||
if (this.beforeReporters.length) { | ||
logObj = this.createLogObj(level, args); | ||
} | ||
for (const reporter of this.beforeReporters) { | ||
reporter.log(logObj); | ||
} | ||
if (typeof this.level === 'undefined') { | ||
if (level > Logger.level) { | ||
return false; | ||
} | ||
} | ||
else if (level > this.level) { | ||
return false; | ||
} | ||
if (!logObj) { | ||
@@ -199,4 +186,13 @@ logObj = this.createLogObj(level, args); | ||
} | ||
const emitLevelCheckFailed = level > ((_a = this.level) !== null && _a !== void 0 ? _a : Logger.level); | ||
for (const reporter of this.reporters) { | ||
reporter.log(logObj); | ||
if (emitLevelCheckFailed) { | ||
// send logs to reporters with emitLevels without filter by level | ||
if (reporter.emitLevels) { | ||
reporter.log(logObj); | ||
} | ||
} | ||
else { | ||
reporter.log(logObj); | ||
} | ||
} | ||
@@ -203,0 +199,0 @@ return true; |
@@ -123,6 +123,6 @@ import toLower from '@tinkoff/utils/string/toLower'; | ||
addBeforeReporter(reporter) { | ||
this.beforeReporters = this.beforeReporters.concat(reporter); | ||
this.reporters = this.reporters.concat(reporter); | ||
} | ||
setBeforeReporters(reporters) { | ||
this.beforeReporters = toArray(reporters); | ||
this.reporters = toArray(reporters); | ||
} | ||
@@ -172,17 +172,4 @@ addReporter(reporter) { | ||
log(level, args) { | ||
var _a; | ||
let logObj; | ||
if (this.beforeReporters.length) { | ||
logObj = this.createLogObj(level, args); | ||
} | ||
for (const reporter of this.beforeReporters) { | ||
reporter.log(logObj); | ||
} | ||
if (typeof this.level === 'undefined') { | ||
if (level > Logger.level) { | ||
return false; | ||
} | ||
} | ||
else if (level > this.level) { | ||
return false; | ||
} | ||
if (!logObj) { | ||
@@ -199,4 +186,13 @@ logObj = this.createLogObj(level, args); | ||
} | ||
const emitLevelCheckFailed = level > ((_a = this.level) !== null && _a !== void 0 ? _a : Logger.level); | ||
for (const reporter of this.reporters) { | ||
reporter.log(logObj); | ||
if (emitLevelCheckFailed) { | ||
// send logs to reporters with emitLevels without filter by level | ||
if (reporter.emitLevels) { | ||
reporter.log(logObj); | ||
} | ||
} | ||
else { | ||
reporter.log(logObj); | ||
} | ||
} | ||
@@ -203,0 +199,0 @@ return true; |
@@ -7,2 +7,5 @@ import type { LEVELS } from './constants'; | ||
level?: LogLevel; | ||
/** | ||
* @deprecated use reporters | ||
*/ | ||
beforeReporters?: Reporter[]; | ||
@@ -34,3 +37,9 @@ reporters?: Reporter[]; | ||
child(options: Options | string): Logger; | ||
/** | ||
* @deprecated use addReporter | ||
*/ | ||
addBeforeReporter(reporter: Reporter): void; | ||
/** | ||
* @deprecated use setReporters | ||
*/ | ||
setBeforeReporters(reporters: Reporter | Reporter[]): void; | ||
@@ -58,2 +67,3 @@ addReporter(reporter: Reporter): void; | ||
export type LogLevel = keyof typeof LEVELS; | ||
export type EmitLevels = Partial<Record<keyof typeof LEVELS, boolean>>; | ||
export interface LogObj { | ||
@@ -68,2 +78,3 @@ name: string; | ||
export interface Reporter { | ||
emitLevels?: EmitLevels; | ||
log(logObj: LogObj): void; | ||
@@ -70,0 +81,0 @@ } |
@@ -133,6 +133,6 @@ 'use strict'; | ||
addBeforeReporter(reporter) { | ||
this.beforeReporters = this.beforeReporters.concat(reporter); | ||
this.reporters = this.reporters.concat(reporter); | ||
} | ||
setBeforeReporters(reporters) { | ||
this.beforeReporters = toArray__default["default"](reporters); | ||
this.reporters = toArray__default["default"](reporters); | ||
} | ||
@@ -182,17 +182,4 @@ addReporter(reporter) { | ||
log(level, args) { | ||
var _a; | ||
let logObj; | ||
if (this.beforeReporters.length) { | ||
logObj = this.createLogObj(level, args); | ||
} | ||
for (const reporter of this.beforeReporters) { | ||
reporter.log(logObj); | ||
} | ||
if (typeof this.level === 'undefined') { | ||
if (level > Logger.level) { | ||
return false; | ||
} | ||
} | ||
else if (level > this.level) { | ||
return false; | ||
} | ||
if (!logObj) { | ||
@@ -209,4 +196,13 @@ logObj = this.createLogObj(level, args); | ||
} | ||
const emitLevelCheckFailed = level > ((_a = this.level) !== null && _a !== void 0 ? _a : Logger.level); | ||
for (const reporter of this.reporters) { | ||
reporter.log(logObj); | ||
if (emitLevelCheckFailed) { | ||
// send logs to reporters with emitLevels without filter by level | ||
if (reporter.emitLevels) { | ||
reporter.log(logObj); | ||
} | ||
} | ||
else { | ||
reporter.log(logObj); | ||
} | ||
} | ||
@@ -213,0 +209,0 @@ return true; |
@@ -1,9 +0,7 @@ | ||
import type { Reporter, LogObj } from '../logger.h'; | ||
import type { LEVELS } from '../constants'; | ||
type EmitLevels = Partial<Record<keyof typeof LEVELS, boolean>>; | ||
import type { Reporter, LogObj, EmitLevels } from '../logger.h'; | ||
type MakeRequest = (logObj: Record<string, any>) => Promise<any>; | ||
export declare class RemoteReporter implements Reporter { | ||
readonly emitLevels: EmitLevels; | ||
private requestCount; | ||
private makeRequest; | ||
private emitLevels; | ||
private reqCount; | ||
@@ -10,0 +8,0 @@ private queue; |
{ | ||
"name": "@tinkoff/logger", | ||
"version": "0.10.168", | ||
"version": "0.10.169", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -158,3 +158,3 @@ # Logger | ||
Reporters are depends of logger level settings as reporters will not be called if level of the current log are lower than display logs setting | ||
Reporters are depends of logger level settings as reporters will not be called if level of the current log are lower than display logs setting (except reporters with [emitLevels](#emitLevels) property). | ||
@@ -166,2 +166,11 @@ ```tsx | ||
log(logObj: LogObj): void; | ||
emitLevels?: { | ||
trace?: boolean; | ||
debug?: boolean; | ||
info?: boolean; | ||
warn?: boolean; | ||
error?: boolean; | ||
fatal?: boolean; | ||
} | ||
} | ||
@@ -173,17 +182,8 @@ | ||
#### BeforeReporter | ||
##### emitLevels | ||
Same as usual `Reporter` but `BeforeReporter` are called unconditionally for every log and get called before any other extension. | ||
Reporters with `emitLevels` property will be called independently of display logs settings. | ||
```tsx | ||
import { logger } from '@tinkoff/logger'; | ||
By default, bundled [RemoteReporter](#RemoteReporter) use this property for logs filter. | ||
interface Reporter { | ||
log(logObj: LogObj): void; | ||
} | ||
logger.addBeforeReporter(reporter as Reporter); // add new beforeReporter to list of previously added beforeReporter | ||
logger.setBeforeReporters([reporter1, reporter2]); // replace current beforeReporters with passed list. that allows to override default settings | ||
``` | ||
### Bundled Reporters | ||
@@ -232,3 +232,3 @@ | ||
const remoteLog = logger({ name: 'remote-for-all', remote: true }); // `remote` allows to override settings from RemoteReporter and send logs unconditionally | ||
const remoteLog = logger({ name: 'remote-for-all', defaults: { remote: true } }); // `remote` allows to override settings from RemoteReporter and send logs unconditionally | ||
@@ -238,3 +238,3 @@ remoteLog.info('test'); // will be sent to api | ||
const traceLog = logger({ name: 'log-trace', emitLevels: { trace: true } }); // override RemoteReporter settings | ||
const traceLog = logger({ name: 'log-trace', defaults: { remote: { emitLevels: { trace: true } }}}); // override RemoteReporter settings | ||
@@ -241,0 +241,0 @@ traceLog.trace('test'); // will be sent to api |
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
83511
2135