loggerhythm
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -30,7 +30,7 @@ define(["require", "exports", "chalk", "util", "./interfaces"], function (require, exports, chalk_1, util, interfaces_1) { | ||
} | ||
const namespaceColorFunction = chalk_1.default.cyan; | ||
const namespaceColorBaseHue = 180; | ||
const logSettings = { | ||
[interfaces_1.LogLevel.ERROR]: { colorFunction: chalk_1.default.red, logFunction: stderrWrite }, | ||
[interfaces_1.LogLevel.WARN]: { colorFunction: chalk_1.default.yellow, logFunction: stdoutWrite }, | ||
[interfaces_1.LogLevel.INFO]: { colorFunction: chalk_1.default.blue, logFunction: stdoutWrite }, | ||
[interfaces_1.LogLevel.INFO]: { colorFunction: chalk_1.default.rgb(0, 143, 219), logFunction: stdoutWrite }, | ||
[interfaces_1.LogLevel.VERBOSE]: { colorFunction: chalk_1.default.gray, logFunction: stdoutWrite }, | ||
@@ -40,8 +40,15 @@ }; | ||
class Logger { | ||
constructor(namespace = '') { | ||
constructor(namespace = '', parentNamespaces = []) { | ||
this.subscribers = []; | ||
this.namespaceStrings = {}; | ||
this.namespaces = parentNamespaces.concat(namespace); | ||
this._namespace = namespace; | ||
const coloredNamespaces = this.namespaces.map((namespace, index) => { | ||
return chalk_1.default.hwb(namespaceColorBaseHue - index * 30, 0, 0)(namespace); | ||
}); | ||
const openBracket = chalk_1.default.dim('['); | ||
const namespaces = coloredNamespaces.join(chalk_1.default.dim(':')); | ||
const closingBracket = chalk_1.default.dim(']'); | ||
const coloredNamespace = (`${openBracket}${namespaces}${closingBracket}`); | ||
for (const logLevel in logSettings) { | ||
const coloredNamespace = namespaceColorFunction(`[${namespace}]`); | ||
this.namespaceStrings[logLevel] = ` - ${logSettings[logLevel].colorFunction(logLevel)}: ${coloredNamespace} `; | ||
@@ -65,4 +72,4 @@ } | ||
} | ||
static createLogger(namespace) { | ||
return new Logger(namespace); | ||
static createLogger(namespace, parentNamespaces) { | ||
return new Logger(namespace, parentNamespaces); | ||
} | ||
@@ -82,3 +89,3 @@ subscribe(callback) { | ||
createChildLogger(namespace) { | ||
return Logger.createLogger(`${this.namespace}:${namespace}`); | ||
return Logger.createLogger(namespace, this.namespaces); | ||
} | ||
@@ -85,0 +92,0 @@ error(message, ...logObjects) { |
@@ -32,7 +32,7 @@ "use strict"; | ||
} | ||
const namespaceColorFunction = chalk_1.default.cyan; | ||
const namespaceColorBaseHue = 180; | ||
const logSettings = { | ||
[interfaces_1.LogLevel.ERROR]: { colorFunction: chalk_1.default.red, logFunction: stderrWrite }, | ||
[interfaces_1.LogLevel.WARN]: { colorFunction: chalk_1.default.yellow, logFunction: stdoutWrite }, | ||
[interfaces_1.LogLevel.INFO]: { colorFunction: chalk_1.default.blue, logFunction: stdoutWrite }, | ||
[interfaces_1.LogLevel.INFO]: { colorFunction: chalk_1.default.rgb(0, 143, 219), logFunction: stdoutWrite }, | ||
[interfaces_1.LogLevel.VERBOSE]: { colorFunction: chalk_1.default.gray, logFunction: stdoutWrite }, | ||
@@ -42,8 +42,15 @@ }; | ||
class Logger { | ||
constructor(namespace = '') { | ||
constructor(namespace = '', parentNamespaces = []) { | ||
this.subscribers = []; | ||
this.namespaceStrings = {}; | ||
this.namespaces = parentNamespaces.concat(namespace); | ||
this._namespace = namespace; | ||
const coloredNamespaces = this.namespaces.map((namespace, index) => { | ||
return chalk_1.default.hwb(namespaceColorBaseHue - index * 30, 0, 0)(namespace); | ||
}); | ||
const openBracket = chalk_1.default.dim('['); | ||
const namespaces = coloredNamespaces.join(chalk_1.default.dim(':')); | ||
const closingBracket = chalk_1.default.dim(']'); | ||
const coloredNamespace = (`${openBracket}${namespaces}${closingBracket}`); | ||
for (const logLevel in logSettings) { | ||
const coloredNamespace = namespaceColorFunction(`[${namespace}]`); | ||
this.namespaceStrings[logLevel] = ` - ${logSettings[logLevel].colorFunction(logLevel)}: ${coloredNamespace} `; | ||
@@ -67,4 +74,4 @@ } | ||
} | ||
static createLogger(namespace) { | ||
return new Logger(namespace); | ||
static createLogger(namespace, parentNamespaces) { | ||
return new Logger(namespace, parentNamespaces); | ||
} | ||
@@ -84,3 +91,3 @@ subscribe(callback) { | ||
createChildLogger(namespace) { | ||
return Logger.createLogger(`${this.namespace}:${namespace}`); | ||
return Logger.createLogger(namespace, this.namespaces); | ||
} | ||
@@ -87,0 +94,0 @@ error(message, ...logObjects) { |
@@ -5,7 +5,8 @@ import { ILoggerhythmHook, ILoggerSubscription } from './interfaces'; | ||
private subscribers; | ||
private namespaces; | ||
private namespaceStrings; | ||
readonly namespace: string; | ||
constructor(namespace?: string); | ||
constructor(namespace?: string, parentNamespaces?: Array<string>); | ||
static subscribe(callback: ILoggerhythmHook): ILoggerSubscription; | ||
static createLogger(namespace?: string): Logger; | ||
static createLogger(namespace?: string, parentNamespaces?: Array<string>): Logger; | ||
subscribe(callback: ILoggerhythmHook): ILoggerSubscription; | ||
@@ -12,0 +13,0 @@ createChildLogger(namespace?: string): Logger; |
{ | ||
"name": "loggerhythm", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "wrapper for winston to use it like debug with namespaces", | ||
@@ -5,0 +5,0 @@ "publicConfig": { |
@@ -48,7 +48,7 @@ import {Chalk, default as chalk} from 'chalk'; | ||
const namespaceColorFunction: Chalk = chalk.cyan; | ||
const namespaceColorBaseHue: number = 180; | ||
const logSettings: ILogSettings = { | ||
[LogLevel.ERROR]: {colorFunction: chalk.red, logFunction: stderrWrite}, | ||
[LogLevel.WARN]: {colorFunction: chalk.yellow, logFunction: stdoutWrite}, | ||
[LogLevel.INFO]: {colorFunction: chalk.blue, logFunction: stdoutWrite}, | ||
[LogLevel.INFO]: {colorFunction: chalk.rgb(0, 143, 219), logFunction: stdoutWrite}, | ||
[LogLevel.VERBOSE]: {colorFunction: chalk.gray, logFunction: stdoutWrite}, | ||
@@ -63,2 +63,3 @@ }; | ||
private subscribers: Array<ILoggerhythmHook> = []; | ||
private namespaces: Array<string>; | ||
private namespaceStrings: {[loglevel: string]: string} = {}; | ||
@@ -70,6 +71,15 @@ | ||
constructor(namespace: string = '') { | ||
constructor(namespace: string = '', parentNamespaces: Array<string> = []) { | ||
this.namespaces = parentNamespaces.concat(namespace); | ||
this._namespace = namespace; | ||
const coloredNamespaces = this.namespaces.map((namespace: string, index: number) => { | ||
return chalk.hwb(namespaceColorBaseHue - index * 30, 0, 0)(namespace); | ||
}); | ||
const openBracket = chalk.dim('['); | ||
const namespaces = coloredNamespaces.join(chalk.dim(':')); | ||
const closingBracket = chalk.dim(']'); | ||
const coloredNamespace = (`${openBracket}${namespaces}${closingBracket}`); | ||
for (const logLevel in logSettings) { | ||
const coloredNamespace: string = namespaceColorFunction(`[${namespace}]`); | ||
this.namespaceStrings[logLevel] = ` - ${logSettings[logLevel].colorFunction(logLevel)}: ${coloredNamespace} `; | ||
@@ -94,4 +104,4 @@ } | ||
public static createLogger(namespace?: string): Logger { | ||
return new Logger(namespace); | ||
public static createLogger(namespace?: string, parentNamespaces?: Array<string>): Logger { | ||
return new Logger(namespace, parentNamespaces); | ||
} | ||
@@ -115,3 +125,3 @@ | ||
public createChildLogger(namespace?: string): Logger { | ||
return Logger.createLogger(`${this.namespace}:${namespace}`); | ||
return Logger.createLogger(namespace, this.namespaces); | ||
} | ||
@@ -118,0 +128,0 @@ |
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
33349
429