Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "logplease", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Simple Javascript logger for Node.js and Browsers", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -15,2 +15,6 @@ 'use strict'; | ||
// Default log level | ||
let GlobalLogLevel = LogLevels.DEBUG; | ||
// ANSI colors | ||
let Colors = { | ||
@@ -29,2 +33,3 @@ 'Black': 0, | ||
// CSS colors | ||
if(!isNodejs) { | ||
@@ -45,2 +50,4 @@ Colors = { | ||
const loglevelColors = [Colors.Cyan, Colors.Green, Colors.Yellow, Colors.Red, Colors.Default]; | ||
const defaultOptions = { | ||
@@ -55,5 +62,2 @@ useColors: true, | ||
const loglevelColors = [Colors.Cyan, Colors.Green, Colors.Yellow, Colors.Red, Colors.Default]; | ||
let GlobalLogLevel = LogLevels.DEBUG; | ||
class Logger { | ||
@@ -123,21 +127,22 @@ constructor(category, options) { | ||
if(this.options.useColors) { | ||
if(isNodejs) { | ||
const levelColor = Object.keys(LogLevels).map((f) => LogLevels[f]).indexOf(level); | ||
const categoryColor = this.options.color; | ||
if(isNodejs) { | ||
if(this.options.showTimestamp) | ||
timestampFormat = '\u001b[3' + Colors.Grey + 'm'; | ||
// timestampFormat = '\u001b[3' + loglevelColors[levelColor] + 'm'; | ||
levelFormat = '\u001b[3' + loglevelColors[levelColor] + ';22m'; | ||
categoryFormat = '\u001b[3' + categoryColor + ';1m'; | ||
textFormat = '\u001b[0m: '; | ||
if(this.options.showLevel) | ||
levelFormat = '\u001b[3' + loglevelColors[levelColor] + ';22m'; | ||
categoryFormat = '\u001b[3' + categoryColor + ';1m'; | ||
textFormat = '\u001b[0m: '; | ||
} else { | ||
const levelColor = Object.keys(LogLevels).map((f) => LogLevels[f]).indexOf(level); | ||
const categoryColor = this.options.color; | ||
if(this.options.showTimestamp) | ||
timestampFormat = 'color:' + Colors.Grey; | ||
levelFormat = 'color:' + loglevelColors[levelColor]; | ||
categoryFormat = 'color:' + categoryColor + '; font-weight: bold'; | ||
if(this.options.showLevel) | ||
levelFormat = 'color:' + loglevelColors[levelColor]; | ||
categoryFormat = 'color:' + categoryColor + '; font-weight: bold'; | ||
} | ||
@@ -163,21 +168,23 @@ } | ||
timestampFormat = '%c'; | ||
levelFormat = '%c'; | ||
if(this.options.showLevel) | ||
levelFormat = '%c'; | ||
categoryFormat = '%c'; | ||
textFormat = ': %c'; | ||
textFormat = ': %c'; | ||
} | ||
let final = ''; | ||
let result = ''; | ||
if(this.options.showTimestamp) | ||
final += '' + new Date().toISOString() + ' '; | ||
result += '' + new Date().toISOString() + ' '; | ||
final = timestampFormat + final; | ||
result = timestampFormat + result; | ||
if(this.options.showLevel) | ||
final += levelFormat + '[' + level +']' + (level === LogLevels.INFO || level === LogLevels.WARN ? ' ' : '') + ' '; | ||
result += levelFormat + '[' + level +']' + (level === LogLevels.INFO || level === LogLevels.WARN ? ' ' : '') + ' '; | ||
final += categoryFormat + this.category; | ||
final += textFormat + text; | ||
final = final + ''; | ||
return final; | ||
result += categoryFormat + this.category; | ||
result += textFormat + text; | ||
return result; | ||
} | ||
@@ -194,12 +201,9 @@ | ||
/* Public API */ | ||
// exports.Colors = Colors; | ||
// exports.LogLevel = LogLevels; | ||
// exports.setLogLevel = (level) => GlobalLogLevel = level; | ||
// exports.create = (category, options) => new Logger(category, options); | ||
module.exports = { | ||
Colors: Colors, | ||
LogLevel: LogLevels, | ||
setLogLevel: (level) => GlobalLogLevel = level, | ||
setLogLevel: (level) => { | ||
GlobalLogLevel = level | ||
}, | ||
create: (category, options) => new Logger(category, options), | ||
}; |
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
306552