Added message cache to prevent error overflows.
This commit is contained in:
parent
909ef9d242
commit
54a1e74e27
@ -1,11 +1,17 @@
|
|||||||
let ipc = null
|
let ipc = null
|
||||||
|
let logMessages = new Set()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ipc = require('electron').ipcRenderer
|
ipc = require('electron').ipcRenderer
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
console.log("Cannot use electron logging.")
|
||||||
|
}
|
||||||
|
|
||||||
/** Basic class for app specific logging requirements.
|
/** Basic class for app specific logging requirements.
|
||||||
* Can be used to implement persistent logging in electron apps.
|
* Can be used to implement persistent logging in electron apps.
|
||||||
|
* Uses a logMessage cache to prevent error overflows. This is
|
||||||
|
* needed since errors may occur very frequently
|
||||||
|
* (e.g. display update loops at 60fps, programmatic loops, ...).
|
||||||
*/
|
*/
|
||||||
export default class Logging {
|
export default class Logging {
|
||||||
|
|
||||||
@ -21,15 +27,28 @@ export default class Logging {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static warn function.
|
||||||
|
* Emits each warning only once per session.
|
||||||
|
* @param {*} message
|
||||||
|
*/
|
||||||
static warn(message) {
|
static warn(message) {
|
||||||
|
if (!logMessages.has(message)) {
|
||||||
if (ipc) {
|
if (ipc) {
|
||||||
ipc.send('warn', message)
|
ipc.send('warn', message)
|
||||||
} else {
|
} else {
|
||||||
console.warn(message)
|
console.warn(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static error function.
|
||||||
|
* Emits each error message only once per session.
|
||||||
|
* @param {*} message
|
||||||
|
*/
|
||||||
static error(message) {
|
static error(message) {
|
||||||
|
if (!logMessages.has(message)) {
|
||||||
if (ipc) {
|
if (ipc) {
|
||||||
ipc.send('error', message)
|
ipc.send('error', message)
|
||||||
} else {
|
} else {
|
||||||
@ -37,3 +56,4 @@ export default class Logging {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user