append-fs-logger
Advanced tools
Comparing version 1.0.2 to 1.1.0
31
index.js
@@ -26,5 +26,2 @@ 'use strict' | ||
const RENDER_PREFIX = '\u001b[35mrend\u001b[39m ' | ||
const MAIN_PREFIX = '\u001b[32mmain\u001b[39m ' | ||
class OpenFailError extends WError { | ||
@@ -408,2 +405,4 @@ constructor (message, cause, info) { | ||
assert(options.fileName, 'options.fileName required') | ||
assert(!options.shortName || options.shortName.length <= 7, | ||
'options.shortName must be 7 char or less') | ||
@@ -413,5 +412,15 @@ this.fsLogger = new AppendOnlyFSLogger(productName, options) | ||
this.console = options.console || false | ||
this.prefix = options.prefix || ( | ||
options.isMain ? MAIN_PREFIX : '' | ||
) | ||
this.shortName = options.shortName | ||
? options.shortName.padStart(7, ' ') : '' | ||
this.prefix = options.prefix || '' | ||
if (options.isMain) { | ||
const mainPrefix = this.shortName | ||
? `${this.shortName}:main` : 'main' | ||
this.prefix = green(mainPrefix) + ' ' | ||
} | ||
const renderPrefix = this.shortName | ||
? `${this.shortName}:rend` : 'rend' | ||
this.renderPrefix = magenta(renderPrefix) + ' ' | ||
} | ||
@@ -428,3 +437,3 @@ | ||
logIPC (level, msg, info, timestamp) { | ||
this._log(level, msg, info, timestamp, RENDER_PREFIX) | ||
this._log(level, msg, info, timestamp, this.renderPrefix) | ||
} | ||
@@ -579,1 +588,9 @@ | ||
} | ||
function green (text) { | ||
return '\u001b[32m' + text + '\u001b[39m' | ||
} | ||
function magenta (text) { | ||
return '\u001b[35m' + text + '\u001b[39m' | ||
} |
{ | ||
"name": "append-fs-logger", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Straight forward zero-dependency disk logger", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
55890
1659