@tsed/logger
Advanced tools
Comparing version 6.1.4 to 6.2.0
@@ -39,3 +39,2 @@ "use strict"; | ||
* | ||
* | ||
*/ | ||
@@ -46,3 +45,2 @@ class BaseAppender { | ||
_BaseAppender_layout.set(this, void 0); | ||
this.appenderOptions = { name: "" }; | ||
this.configure(config); | ||
@@ -54,4 +52,5 @@ if (this["build"]) { | ||
configure(config) { | ||
var _a; | ||
Object.assign(this.config, config); | ||
tslib_1.__classPrivateFieldSet(this, _BaseAppender_layout, Layouts_1.Layouts.get(this.appenderOptions.defaultLayout || "colored", this.config), "f"); | ||
tslib_1.__classPrivateFieldSet(this, _BaseAppender_layout, Layouts_1.Layouts.get(((_a = this.appenderOptions) === null || _a === void 0 ? void 0 : _a.defaultLayout) || "colored", this.config), "f"); | ||
if (this.config.layout) { | ||
@@ -58,0 +57,0 @@ tslib_1.__classPrivateFieldSet(this, _BaseAppender_layout, Layouts_1.Layouts.get(this.config.layout.type, this.config.layout), "f"); |
@@ -25,2 +25,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./layouts/components/MessagePassThroughLayout"), exports); | ||
tslib_1.__exportStar(require("./layouts/components/ObjectLayout"), exports); | ||
tslib_1.__exportStar(require("./layouts/components/PatternLayout"), exports); | ||
@@ -34,2 +35,3 @@ tslib_1.__exportStar(require("./layouts/constants/logColors"), exports); | ||
tslib_1.__exportStar(require("./layouts/utils/colorizeUtils"), exports); | ||
tslib_1.__exportStar(require("./layouts/utils/logEventToObject"), exports); | ||
tslib_1.__exportStar(require("./layouts/utils/timestampLevelAndCategory"), exports); | ||
@@ -36,0 +38,0 @@ tslib_1.__exportStar(require("./logger/exports"), exports); |
@@ -5,24 +5,8 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const Util = tslib_1.__importStar(require("util")); | ||
const BaseLayout_1 = require("../class/BaseLayout"); | ||
const layout_1 = require("../decorators/layout"); | ||
const colorizeUtils_1 = require("../utils/colorizeUtils"); | ||
const logEventToObject_1 = require("../utils/logEventToObject"); | ||
let JsonLayout = class JsonLayout extends BaseLayout_1.BaseLayout { | ||
transform(loggingEvent, timezoneOffset) { | ||
const log = { | ||
...loggingEvent.context.toJSON(), | ||
startTime: loggingEvent.startTime, | ||
categoryName: loggingEvent.categoryName, | ||
level: loggingEvent.level.toString() | ||
}; | ||
log.data = loggingEvent.data.reduce((data, current) => { | ||
if (typeof current === "object") { | ||
Object.assign(log, current); | ||
if (current.data) { | ||
return [].concat(data, current.data); | ||
} | ||
return data; | ||
} | ||
return [...data, (0, colorizeUtils_1.removeColors)(Util.format(current))]; | ||
}, []); | ||
const log = (0, logEventToObject_1.logEventToObject)(loggingEvent); | ||
return JSON.stringify(log) + (this.config["separator"] || ""); | ||
@@ -29,0 +13,0 @@ } |
@@ -83,3 +83,2 @@ "use strict"; | ||
* @param data | ||
* @param args | ||
* @returns {any} | ||
@@ -119,3 +118,3 @@ */ | ||
* | ||
* @returns {Promise<TAll[]>} | ||
* @returns {Promise<any[]>} | ||
*/ | ||
@@ -122,0 +121,0 @@ shutdown() { |
@@ -36,10 +36,18 @@ "use strict"; | ||
set(name, config) { | ||
if (!AppendersRegistry_1.AppendersRegistry.has(config.type)) { | ||
const error = new Error(`Appender ${config.type} doesn't exists. Check your configuration:\n${JSON.stringify(config)}\n`); | ||
var _a; | ||
const type = typeof config.type === "string" ? config.type : (_a = config.type) === null || _a === void 0 ? void 0 : _a.$name; | ||
const opts = { | ||
level: ["debug", "info", "trace", "error", "warn", "fatal"], | ||
...config, | ||
type, | ||
options: config.options || {} | ||
}; | ||
if (!AppendersRegistry_1.AppendersRegistry.has(opts.type)) { | ||
const error = new Error(`Appender ${opts.type} doesn't exists. Check your configuration:\n${JSON.stringify(opts)}\n`); | ||
error.name = "UNKNOW_APPENDER"; | ||
throw error; | ||
} | ||
const klass = AppendersRegistry_1.AppendersRegistry.get(config.type).provide; | ||
const instance = new klass(config); | ||
this._appenders.set(name, { name, instance, config }); | ||
const klass = AppendersRegistry_1.AppendersRegistry.get(opts.type).provide; | ||
const instance = new klass(opts); | ||
this._appenders.set(name, { name, instance, config: opts }); | ||
this._lvls.clear(); | ||
@@ -46,0 +54,0 @@ return this; |
@@ -36,3 +36,2 @@ var _BaseAppender_layout; | ||
* | ||
* | ||
*/ | ||
@@ -43,3 +42,2 @@ export class BaseAppender { | ||
_BaseAppender_layout.set(this, void 0); | ||
this.appenderOptions = { name: "" }; | ||
this.configure(config); | ||
@@ -51,4 +49,5 @@ if (this["build"]) { | ||
configure(config) { | ||
var _a; | ||
Object.assign(this.config, config); | ||
__classPrivateFieldSet(this, _BaseAppender_layout, Layouts.get(this.appenderOptions.defaultLayout || "colored", this.config), "f"); | ||
__classPrivateFieldSet(this, _BaseAppender_layout, Layouts.get(((_a = this.appenderOptions) === null || _a === void 0 ? void 0 : _a.defaultLayout) || "colored", this.config), "f"); | ||
if (this.config.layout) { | ||
@@ -55,0 +54,0 @@ __classPrivateFieldSet(this, _BaseAppender_layout, Layouts.get(this.config.layout.type, this.config.layout), "f"); |
@@ -22,2 +22,3 @@ /** | ||
export * from "./layouts/components/MessagePassThroughLayout.js"; | ||
export * from "./layouts/components/ObjectLayout.js"; | ||
export * from "./layouts/components/PatternLayout.js"; | ||
@@ -31,2 +32,3 @@ export * from "./layouts/constants/logColors.js"; | ||
export * from "./layouts/utils/colorizeUtils.js"; | ||
export * from "./layouts/utils/logEventToObject.js"; | ||
export * from "./layouts/utils/timestampLevelAndCategory.js"; | ||
@@ -33,0 +35,0 @@ export * from "./logger/exports.js"; |
import { __decorate } from "tslib"; | ||
import * as Util from "util"; | ||
import { BaseLayout } from "../class/BaseLayout.js"; | ||
import { Layout } from "../decorators/layout.js"; | ||
import { removeColors } from "../utils/colorizeUtils.js"; | ||
import { logEventToObject } from "../utils/logEventToObject.js"; | ||
let JsonLayout = class JsonLayout extends BaseLayout { | ||
transform(loggingEvent, timezoneOffset) { | ||
const log = { | ||
...loggingEvent.context.toJSON(), | ||
startTime: loggingEvent.startTime, | ||
categoryName: loggingEvent.categoryName, | ||
level: loggingEvent.level.toString() | ||
}; | ||
log.data = loggingEvent.data.reduce((data, current) => { | ||
if (typeof current === "object") { | ||
Object.assign(log, current); | ||
if (current.data) { | ||
return [].concat(data, current.data); | ||
} | ||
return data; | ||
} | ||
return [...data, removeColors(Util.format(current))]; | ||
}, []); | ||
const log = logEventToObject(loggingEvent); | ||
return JSON.stringify(log) + (this.config["separator"] || ""); | ||
@@ -25,0 +9,0 @@ } |
@@ -80,3 +80,2 @@ import { LoggerAppenders } from "./LoggerAppenders.js"; | ||
* @param data | ||
* @param args | ||
* @returns {any} | ||
@@ -116,3 +115,3 @@ */ | ||
* | ||
* @returns {Promise<TAll[]>} | ||
* @returns {Promise<any[]>} | ||
*/ | ||
@@ -119,0 +118,0 @@ shutdown() { |
@@ -33,10 +33,18 @@ import { AppendersRegistry } from "../../appenders/registries/AppendersRegistry.js"; | ||
set(name, config) { | ||
if (!AppendersRegistry.has(config.type)) { | ||
const error = new Error(`Appender ${config.type} doesn't exists. Check your configuration:\n${JSON.stringify(config)}\n`); | ||
var _a; | ||
const type = typeof config.type === "string" ? config.type : (_a = config.type) === null || _a === void 0 ? void 0 : _a.$name; | ||
const opts = { | ||
level: ["debug", "info", "trace", "error", "warn", "fatal"], | ||
...config, | ||
type, | ||
options: config.options || {} | ||
}; | ||
if (!AppendersRegistry.has(opts.type)) { | ||
const error = new Error(`Appender ${opts.type} doesn't exists. Check your configuration:\n${JSON.stringify(opts)}\n`); | ||
error.name = "UNKNOW_APPENDER"; | ||
throw error; | ||
} | ||
const klass = AppendersRegistry.get(config.type).provide; | ||
const instance = new klass(config); | ||
this._appenders.set(name, { name, instance, config }); | ||
const klass = AppendersRegistry.get(opts.type).provide; | ||
const instance = new klass(opts); | ||
this._appenders.set(name, { name, instance, config: opts }); | ||
this._lvls.clear(); | ||
@@ -43,0 +51,0 @@ return this; |
@@ -7,3 +7,3 @@ import { LogEvent } from "../../core/LogEvent"; | ||
} | ||
export interface IBaseAppender { | ||
export interface BaseAppenderMethods { | ||
write(loggingEvent: LogEvent): any; | ||
@@ -46,10 +46,9 @@ build?(): any; | ||
* | ||
* | ||
*/ | ||
export declare abstract class BaseAppender implements IBaseAppender { | ||
export declare abstract class BaseAppender<Opts = any> implements BaseAppenderMethods { | ||
#private; | ||
readonly config: AppenderConfiguration; | ||
readonly config: AppenderConfiguration<Opts>; | ||
appenderOptions: AppenderOptions; | ||
[key: string]: any; | ||
constructor(config: AppenderConfiguration); | ||
constructor(config: AppenderConfiguration<Opts>); | ||
configure(config: PartialAppenderConfiguration): this; | ||
@@ -56,0 +55,0 @@ /** |
import { BasicLayoutConfiguration } from "../../layouts/interfaces/BasicLayoutConfiguration"; | ||
export interface AppenderConfiguration { | ||
export interface AppenderConfiguration<Opts = any> { | ||
type: string; | ||
@@ -10,7 +10,5 @@ filename?: string; | ||
levels?: string[]; | ||
options: Opts; | ||
[key: string]: any; | ||
} | ||
export declare type Partial<T> = { | ||
[P in keyof T]?: T[P]; | ||
}; | ||
export declare type PartialAppenderConfiguration = Partial<AppenderConfiguration>; | ||
export declare type PartialAppenderConfiguration<Opts = any> = Partial<AppenderConfiguration<Opts>>; |
@@ -22,2 +22,3 @@ /** | ||
export * from "./layouts/components/MessagePassThroughLayout"; | ||
export * from "./layouts/components/ObjectLayout"; | ||
export * from "./layouts/components/PatternLayout"; | ||
@@ -31,2 +32,3 @@ export * from "./layouts/constants/logColors"; | ||
export * from "./layouts/utils/colorizeUtils"; | ||
export * from "./layouts/utils/logEventToObject"; | ||
export * from "./layouts/utils/timestampLevelAndCategory"; | ||
@@ -33,0 +35,0 @@ export * from "./logger/exports"; |
@@ -52,3 +52,2 @@ import { LoggerAppenders } from "./LoggerAppenders"; | ||
* @param data | ||
* @param args | ||
* @returns {any} | ||
@@ -74,3 +73,3 @@ */ | ||
* | ||
* @returns {Promise<TAll[]>} | ||
* @returns {Promise<any[]>} | ||
*/ | ||
@@ -77,0 +76,0 @@ shutdown(): Promise<any[]>; |
@@ -31,3 +31,6 @@ import { BaseAppender } from "../../appenders/class/BaseAppender"; | ||
*/ | ||
set(name: string, config: AppenderConfiguration): LoggerAppenders; | ||
set(name: string, config: Omit<AppenderConfiguration, "options"> & { | ||
type: string | any; | ||
options?: any; | ||
}): LoggerAppenders; | ||
/** | ||
@@ -34,0 +37,0 @@ * Remove all configuration that match with the `name`. |
{ | ||
"name": "@tsed/logger", | ||
"version": "6.1.4", | ||
"version": "6.2.0", | ||
"description": "A multi channel logger written in TypeScript.", | ||
@@ -5,0 +5,0 @@ "private": false, |
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
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
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
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
263192
175
3254