electron-log
Advanced tools
Comparing version 5.2.3 to 5.2.4
{ | ||
"name": "electron-log", | ||
"version": "5.2.3", | ||
"version": "5.2.4", | ||
"description": "Just a simple logging module for your Electron application", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -251,2 +251,26 @@ # electron-log | ||
### Buffering | ||
It's like a transaction, you may add some logs to the buffer and then decide | ||
whether to write these logs or not. It allows adding verbose logs only | ||
when some operations failed. | ||
```js | ||
import log from 'electron-log/main'; | ||
log.buffering.begin(); | ||
try { | ||
log.info('First silly message'); | ||
// do somethings complex | ||
log.info('Second silly message'); | ||
// do something else | ||
// Finished fine, we don't need these logs anymore | ||
log.buffering.reject(); | ||
} catch (e) { | ||
log.buffering.commit(); | ||
log.warn(e); | ||
} | ||
``` | ||
## Related | ||
@@ -253,0 +277,0 @@ |
'use strict'; | ||
const scopeFactory = require('./scope'); | ||
const Buffering = require('./Buffering'); | ||
@@ -47,2 +48,3 @@ /** | ||
this.allowUnknownLevel = allowUnknownLevel; | ||
this.buffering = new Buffering(this); | ||
this.dependencies = dependencies; | ||
@@ -53,5 +55,5 @@ this.initializeFn = initializeFn; | ||
this.logId = logId; | ||
this.scope = scopeFactory(this); | ||
this.transportFactories = transportFactories; | ||
this.variables = variables || {}; | ||
this.scope = scopeFactory(this); | ||
@@ -133,3 +135,7 @@ for (const name of this.levels) { | ||
logData(data, options = {}) { | ||
this.processMessage({ data, ...options }); | ||
if (this.buffering.enabled) { | ||
this.buffering.addMessage({ data, ...options }); | ||
} else { | ||
this.processMessage({ data, ...options }); | ||
} | ||
} | ||
@@ -136,0 +142,0 @@ |
@@ -369,2 +369,26 @@ import { ClientRequest, RequestOptions } from 'http'; | ||
interface Buffering { | ||
/** | ||
* Buffered log messages | ||
*/ | ||
buffer: LogMessage[]; | ||
enabled: boolean; | ||
/** | ||
* Start buffering log messages | ||
*/ | ||
begin(): void; | ||
/** | ||
* Stop buffering and process all buffered logs | ||
*/ | ||
commit(): void; | ||
/** | ||
* Stop buffering and discard all buffered logs | ||
*/ | ||
reject(): void; | ||
} | ||
interface Scope { | ||
@@ -558,2 +582,7 @@ (label: string): LogFunctions; | ||
/** | ||
* Buffering helper | ||
*/ | ||
buffering: Buffering; | ||
/** | ||
* Error handling helper | ||
@@ -560,0 +589,0 @@ */ |
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
93127
40
2967
279