-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
vingester-log.js
63 lines (57 loc) · 2.23 KB
/
vingester-log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
** Vingester ~ Ingest Web Contents as Video Streams
** Copyright (c) 2021-2022 Dr. Ralf S. Engelschall <rse@engelschall.com>
** Licensed under GPL 3.0 <https://spdx.org/licenses/GPL-3.0-only>
*/
/* fetch original Electron-Log API */
const electronLog = require("electron-log")
/* determine context */
const isRenderer =
( ( typeof window !== "undefined"
&& typeof window.process === "object"
&& window.process.type === "renderer" )
|| ( typeof navigator === "object"
&& typeof navigator.userAgent === "string"
&& navigator.userAgent.indexOf("Electron") >= 0))
const isMain =
!isRenderer
&& ( typeof process !== "undefined"
&& typeof process.versions === "object"
&& process.versions.electron !== undefined )
/* pre-configure logging environment */
electronLog.transports.console.format = "{h}:{i}:{s}.{ms} > [{level}] {scope} {text}"
electronLog.transports.file.format = "[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {scope} {text}"
electronLog.transports.remote.level = false
if (isMain) {
if (typeof process.env.DEBUG !== "undefined") {
/* main process, debugging */
electronLog.transports.file.level = "debug"
electronLog.transports.console.level = "debug"
electronLog.transports.ipc.level = false
}
else {
/* main process, production */
electronLog.transports.file.level = "info"
electronLog.transports.console.level = false
electronLog.transports.ipc.level = false
}
}
else if (isRenderer) {
if (typeof process.env.DEBUG !== "undefined") {
/* renderer process, debugging */
electronLog.transports.file.level = false
electronLog.transports.console.level = false
electronLog.transports.ipc.level = "debug"
}
else {
/* renderer process, production */
electronLog.transports.file.level = false
electronLog.transports.console.level = false
electronLog.transports.ipc.level = "info"
}
}
/* show initial hint */
if (isMain)
electronLog.scope("global").debug(`(persistent log: ${electronLog.transports.file.getFile()})`)
/* export adjusted Electron-Log API */
module.exports = electronLog