@studio/log
Advanced tools
+4
-0
| # Changes | ||
| ## 1.0.2 | ||
| 🐛 Make it work with local symlinks | ||
| ## 1.0.1 | ||
@@ -4,0 +8,0 @@ |
+30
-24
@@ -23,14 +23,20 @@ /* | ||
| const loggers = {}; | ||
| let transform = createDefaultTransform(); | ||
| let stream = null; | ||
| let muted = {}; | ||
| let muted_all = null; | ||
| // Make it work with local symlinks: | ||
| let state = global['@studio/log']; | ||
| if (!state) { | ||
| state = global['@studio/log'] = { | ||
| loggers: {}, | ||
| transform: createDefaultTransform(), | ||
| stream: null, | ||
| muted: {}, | ||
| muted_all: null | ||
| }; | ||
| } | ||
| function write(ns, topic, msg, data, error) { | ||
| const mutes = muted[ns]; | ||
| const mutes = state.muted[ns]; | ||
| if (mutes && (!mutes.length || mutes.indexOf(topic) !== -1)) { | ||
| return; | ||
| } | ||
| if (muted_all && muted_all.indexOf(topic) !== -1) { | ||
| if (state.muted_all && state.muted_all.indexOf(topic) !== -1) { | ||
| return; | ||
@@ -55,3 +61,3 @@ } | ||
| } | ||
| transform.write(entry); | ||
| state.transform.write(entry); | ||
| } | ||
@@ -74,10 +80,10 @@ | ||
| function logger(ns) { | ||
| return loggers[ns] || (loggers[ns] = new Logger(ns)); | ||
| return state.loggers[ns] || (state.loggers[ns] = new Logger(ns)); | ||
| } | ||
| logger.out = function (out_stream) { | ||
| transform.unpipe(stream); | ||
| stream = out_stream; | ||
| if (stream) { | ||
| transform.pipe(stream); | ||
| state.transform.unpipe(state.stream); | ||
| state.stream = out_stream; | ||
| if (state.stream) { | ||
| state.transform.pipe(state.stream); | ||
| } | ||
@@ -88,6 +94,6 @@ return this; | ||
| logger.transform = function (transform_stream) { | ||
| transform.unpipe(stream); | ||
| transform = transform_stream; | ||
| if (stream) { | ||
| transform.pipe(stream); | ||
| state.transform.unpipe(state.stream); | ||
| state.transform = transform_stream; | ||
| if (state.stream) { | ||
| state.transform.pipe(state.stream); | ||
| } | ||
@@ -98,3 +104,3 @@ return this; | ||
| logger.mute = function (ns, ...topics) { | ||
| muted[ns] = topics; | ||
| state.muted[ns] = topics; | ||
| return this; | ||
@@ -104,3 +110,3 @@ }; | ||
| logger.muteAll = function (...topics) { | ||
| muted_all = topics; | ||
| state.muted_all = topics; | ||
| return this; | ||
@@ -110,9 +116,9 @@ }; | ||
| logger.reset = function () { | ||
| transform.unpipe(stream); | ||
| transform = createDefaultTransform(); | ||
| stream = null; | ||
| muted = {}; | ||
| muted_all = null; | ||
| state.transform.unpipe(state.stream); | ||
| state.transform = createDefaultTransform(); | ||
| state.stream = null; | ||
| state.muted = {}; | ||
| state.muted_all = null; | ||
| }; | ||
| module.exports = logger; |
+1
-1
| { | ||
| "name": "@studio/log", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "A tiny JSON logger with emoji support", | ||
@@ -5,0 +5,0 @@ "bin": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
16971
1.96%391
1.56%