Skip to content

Commit

Permalink
Perf optimization, fix #130
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Feb 8, 2022
1 parent 690457b commit 130a7be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/LoggerWithoutCallSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class LoggerWithoutCallSite {
public constructor(settings?: ISettingsParam, parentSettings?: ISettings) {
this._parentOrDefaultSettings = {
type: "pretty",
instanceName: hostname(),
instanceName: undefined,
hostname: parentSettings?.hostname ?? hostname(),
name: undefined,
setCallerAsLoggerName: false,
requestId: undefined,
Expand Down Expand Up @@ -163,6 +164,9 @@ export class LoggerWithoutCallSite {
this.settings.colorizePrettyLogs;
}

this._mySettings.instanceName =
this._mySettings.instanceName ?? this._mySettings.hostname;

this._mySettings.name =
this._mySettings.name ??
(this._mySettings.setCallerAsLoggerName
Expand Down Expand Up @@ -396,7 +400,7 @@ export class LoggerWithoutCallSite {
const logObject: ILogObject = {
instanceName: this.settings.instanceName,
loggerName: this.settings.name,
hostname: hostname(),
hostname: this.settings.hostname,
requestId,
date: new Date(),
logLevel: logLevel,
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export interface ISettingsParam {
/** Name of the instance name, default: _host name_ */
instanceName?: string;

/** Name of the host, default: _host name_ */
hostname?: string;

/** Use the name of the caller type as the name of the logger, default: `false` */
setCallerAsLoggerName?: boolean;

Expand Down Expand Up @@ -164,6 +167,7 @@ export interface ISettingsParam {
export interface ISettings extends ISettingsParam {
type: "json" | "pretty" | "hidden";
instanceName?: string;
hostname: string;
setCallerAsLoggerName: boolean;
name?: string;
requestId?: string | TRequestIdFunction;
Expand Down

0 comments on commit 130a7be

Please sign in to comment.