@arnob-b/observability 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/observability-1.0.0.tgz +0 -0
- package/package.json +24 -0
- package/src/formats/index.js +6 -0
- package/src/formats/traceContext.format.js +12 -0
- package/src/helper/index.js +17 -0
- package/src/helper/instrumentBuilder.otel.js +24 -0
- package/src/helper/transport.builder.js +25 -0
- package/src/index.js +12 -0
- package/src/logger.js +45 -0
- package/src/observability.js +34 -0
- package/src/otel/context.otel.js +74 -0
- package/src/otel/index.js +10 -0
- package/src/otel/init.otel.js +48 -0
- package/src/transports/file.rotation.transport.js +40 -0
- package/src/transports/index.js +9 -0
- package/src/transports/stream.transport.js +30 -0
- package/src/transports/watcher.transport.js +33 -0
- package/src/wrappers/backend.wrapper.js +10 -0
- package/src/wrappers/electron.wrapper.js +19 -0
- package/src/wrappers/factory.js +28 -0
- package/src/wrappers/index.js +4 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Observability
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arnob-b/observability",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "observability for nodejs application using winston and opentelemetry",
|
|
5
|
+
"keywords": ["observability", "nodejs", "winston", "opentelemetry", "electron", "desktop application"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Arnob Bhakta",
|
|
8
|
+
"main": "./src/index.js",
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@opentelemetry/api": "^1.9.0",
|
|
15
|
+
"@opentelemetry/instrumentation-undici": "^0.21.0",
|
|
16
|
+
"@opentelemetry/sdk-node": "^0.212.0",
|
|
17
|
+
"winston": "^3.19.0",
|
|
18
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@opentelemetry/instrumentation-express": "^0.59.0",
|
|
22
|
+
"@opentelemetry/instrumentation-http": "^0.212.0"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const winston = require('winston');
|
|
2
|
+
const {getActiveIds} = require('./../otel');
|
|
3
|
+
|
|
4
|
+
const traceContextFormat = winston.format((info) => {
|
|
5
|
+
const context = getActiveIds();
|
|
6
|
+
if (context) {
|
|
7
|
+
info.context = context
|
|
8
|
+
}
|
|
9
|
+
return info;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
module.exports = {traceContextFormat};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function normalizeData(data){
|
|
2
|
+
if (data === null || data === undefined) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
if (data instanceof Error) {
|
|
6
|
+
data = {
|
|
7
|
+
name: data.name,
|
|
8
|
+
message: data.message,
|
|
9
|
+
stack: data.stack
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
normalizeData
|
|
17
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { HttpInstrumentation } = require("@opentelemetry/instrumentation-http");
|
|
2
|
+
const { ExpressInstrumentation } = require("@opentelemetry/instrumentation-express");
|
|
3
|
+
|
|
4
|
+
const { UndiciInstrumentation } = require('@opentelemetry/instrumentation-undici');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function buildInstrumentations(INSTRUMENT_CONFIG = {}) {
|
|
8
|
+
const list = [];
|
|
9
|
+
|
|
10
|
+
if (INSTRUMENT_CONFIG.HTTP) {
|
|
11
|
+
list.push(new HttpInstrumentation());
|
|
12
|
+
}
|
|
13
|
+
if (INSTRUMENT_CONFIG.EXPRESS) {
|
|
14
|
+
list.push(new ExpressInstrumentation());
|
|
15
|
+
}
|
|
16
|
+
if (INSTRUMENT_CONFIG.UNDICI) {
|
|
17
|
+
list.push(new UndiciInstrumentation());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return list;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
module.exports = { buildInstrumentations };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const winston = require('winston')
|
|
2
|
+
const { WatcherTransport, StreamTransport, FileRotationTransport } = require("../transports");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function buildTransports(CONFIG = {}) {
|
|
6
|
+
const list = {};
|
|
7
|
+
|
|
8
|
+
if (CONFIG.CONSOLE && CONFIG.CONSOLE.ENABLED) {
|
|
9
|
+
list[CONFIG.CONSOLE.NAME] = new winston.transports.Console(CONFIG.CONSOLE);
|
|
10
|
+
}
|
|
11
|
+
if (CONFIG.WATCHER && CONFIG.WATCHER.ENABLED) {
|
|
12
|
+
list[CONFIG.WATCHER.NAME] = new WatcherTransport(CONFIG.WATCHER);
|
|
13
|
+
}
|
|
14
|
+
if (CONFIG.FILE && CONFIG.FILE.ENABLED) {
|
|
15
|
+
list[CONFIG.FILE.NAME] = FileRotationTransport(CONFIG.FILE)
|
|
16
|
+
}
|
|
17
|
+
if (CONFIG.STREAM && CONFIG.STREAM.ENABLED) {
|
|
18
|
+
list[CONFIG.STREAM.NAME] = new StreamTransport(CONFIG.STREAM);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return list;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
module.exports = { buildTransports };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { traceExecution, traceAsyncExecution, startTracedExecution } = require("./otel");
|
|
2
|
+
const {attachHooksOnTransport} = require("./logger");
|
|
3
|
+
const Observability = require("./observability");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
Observability,
|
|
8
|
+
traceExecution,
|
|
9
|
+
traceAsyncExecution,
|
|
10
|
+
startTracedExecution,
|
|
11
|
+
attachHooksOnTransport
|
|
12
|
+
}
|
package/src/logger.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const winston = require("winston");
|
|
2
|
+
const {traceContextFormat} = require("./formats");
|
|
3
|
+
const { buildTransports } = require("./helper/transport.builder");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
let logger = null;
|
|
7
|
+
let transports = null;
|
|
8
|
+
|
|
9
|
+
function initLogger(LOG_CONFIG){
|
|
10
|
+
if (logger) {
|
|
11
|
+
console.warn("Logger already initialized. Returning existing instance.");
|
|
12
|
+
return logger;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
transports = buildTransports(LOG_CONFIG.TRANSPORTS);
|
|
16
|
+
logger = winston.createLogger({
|
|
17
|
+
level: LOG_CONFIG.LEVEL,
|
|
18
|
+
format: winston.format.combine(
|
|
19
|
+
traceContextFormat(),
|
|
20
|
+
winston.format.timestamp(),
|
|
21
|
+
winston.format.json()
|
|
22
|
+
),
|
|
23
|
+
transports: Object.values(transports)
|
|
24
|
+
})
|
|
25
|
+
console.log("Logger initialized");
|
|
26
|
+
return logger
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function attachHooksOnTransport(transportName, hooks = {}){
|
|
31
|
+
if (!transports || !transports[transportName]) {
|
|
32
|
+
console.warn(`Transport ${transportName} not found. Cannot attach hooks.`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const transport = transports[transportName];
|
|
36
|
+
for(const event of Object.keys(hooks)){
|
|
37
|
+
transport.on(event, hooks[event]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
initLogger,
|
|
44
|
+
attachHooksOnTransport
|
|
45
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const {initOtel} = require("./otel");
|
|
2
|
+
const {initLogger} = require("./logger");
|
|
3
|
+
const { LoggerFactory } = require("./wrappers");
|
|
4
|
+
class Observability {The
|
|
5
|
+
constructor() {
|
|
6
|
+
if (Observability.instance) {
|
|
7
|
+
console.warn("Observability instance already exists. Returning existing instance.");
|
|
8
|
+
return Observability.instance;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
this.initialized = false;
|
|
12
|
+
Observability.instance = this;
|
|
13
|
+
}
|
|
14
|
+
async init(config){
|
|
15
|
+
if (this.initialized) {
|
|
16
|
+
console.warn("Observability already initialized");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
initOtel(config.OTEL);
|
|
20
|
+
this.logger = initLogger(config.LOG);
|
|
21
|
+
|
|
22
|
+
this.initialized = true;
|
|
23
|
+
}
|
|
24
|
+
getLogger(loggerName){
|
|
25
|
+
if (!this.initialized) {
|
|
26
|
+
console.warn("Observability not initialized. Call init() first.");
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return LoggerFactory(loggerName, this.logger);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
module.exports = new Observability;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const api = require('@opentelemetry/api');
|
|
2
|
+
const {getTracer, getActiveSpan} = require('./init.otel');
|
|
3
|
+
|
|
4
|
+
function startTracedExecution(name, fn) {
|
|
5
|
+
const tracer = getTracer();
|
|
6
|
+
return tracer.startActiveSpan(name, async span => {
|
|
7
|
+
try {
|
|
8
|
+
return await fn();
|
|
9
|
+
} finally {
|
|
10
|
+
span.end();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function traceExecution(name, fn) {
|
|
16
|
+
const tracer = getTracer();
|
|
17
|
+
return function(...args) {
|
|
18
|
+
return tracer.startActiveSpan(name, (span) => {
|
|
19
|
+
try{
|
|
20
|
+
const result = fn.apply(this, args);
|
|
21
|
+
return result;
|
|
22
|
+
}catch(err){
|
|
23
|
+
// span.recordException(err);
|
|
24
|
+
// span.setStatus({ code: api.SpanStatusCode.ERROR, message: err.message });
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
finally{
|
|
28
|
+
span.end()
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function traceAsyncExecution(name, fn) {
|
|
34
|
+
const tracer = getTracer();
|
|
35
|
+
return async function(...args) {
|
|
36
|
+
return tracer.startActiveSpan(name, async (span) => {
|
|
37
|
+
try{
|
|
38
|
+
const result = await fn.apply(this, args);
|
|
39
|
+
return result;
|
|
40
|
+
}catch(err){
|
|
41
|
+
// span.recordException(err);
|
|
42
|
+
// span.setStatus({ code: api.SpanStatusCode.ERROR, message: err.message });
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
finally{
|
|
46
|
+
span.end()
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getActiveIds() {
|
|
53
|
+
const span = getActiveSpan();
|
|
54
|
+
if (!span) return {};
|
|
55
|
+
|
|
56
|
+
const ctx = span.spanContext();
|
|
57
|
+
const parent = span.parentSpanContext;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
name:span.name,
|
|
61
|
+
executionId: ctx.traceId,
|
|
62
|
+
operationId: ctx.spanId,
|
|
63
|
+
parentExecutionId: parent?.traceId || null,
|
|
64
|
+
parentOperationId: parent?.spanId || null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
startTracedExecution,
|
|
71
|
+
traceExecution,
|
|
72
|
+
traceAsyncExecution,
|
|
73
|
+
getActiveIds
|
|
74
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { initOtel, getTracer , getActiveSpan, shutdownOtel } = require("./init.otel");
|
|
2
|
+
const { startTracedExecution, traceExecution, traceAsyncExecution, getActiveIds } = require("./context.otel");
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
initOtel, getTracer , getActiveSpan, shutdownOtel,
|
|
6
|
+
startTracedExecution,
|
|
7
|
+
traceExecution,
|
|
8
|
+
traceAsyncExecution,
|
|
9
|
+
getActiveIds
|
|
10
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
|
2
|
+
const { trace } = require('@opentelemetry/api');
|
|
3
|
+
const { resourceFromAttributes } = require('@opentelemetry/resources');
|
|
4
|
+
const {
|
|
5
|
+
ATTR_SERVICE_NAME,
|
|
6
|
+
ATTR_SERVICE_VERSION,
|
|
7
|
+
} = require('@opentelemetry/semantic-conventions');
|
|
8
|
+
const { UndiciInstrumentation } = require('@opentelemetry/instrumentation-undici');
|
|
9
|
+
const { buildInstrumentations } = require('../helper/instrumentBuilder.otel');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
let sdk;
|
|
13
|
+
let tracer;
|
|
14
|
+
|
|
15
|
+
function initOtel(CONFIG) {
|
|
16
|
+
if (sdk) return;
|
|
17
|
+
|
|
18
|
+
const instruments = buildInstrumentations(CONFIG.INSTRUMENTS);
|
|
19
|
+
sdk = new NodeSDK({
|
|
20
|
+
resource: resourceFromAttributes({
|
|
21
|
+
[ATTR_SERVICE_NAME]: CONFIG.SERVICE_NAME,
|
|
22
|
+
[ATTR_SERVICE_VERSION]: CONFIG.SERVICE_VERSION,
|
|
23
|
+
}),
|
|
24
|
+
instrumentations:instruments
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
sdk.start();
|
|
28
|
+
console.log("Otel initialized for service:", CONFIG.SERVICE_NAME);
|
|
29
|
+
tracer = trace.getTracer(CONFIG.SERVICE_NAME);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function shutdownOtel() {
|
|
33
|
+
if (sdk) { sdk.shutdown(); }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getTracer() {
|
|
37
|
+
if (!tracer) {
|
|
38
|
+
throw new Error("Otel not initialized");
|
|
39
|
+
}
|
|
40
|
+
return tracer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getActiveSpan(){
|
|
44
|
+
return trace.getActiveSpan()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
module.exports = {initOtel, getTracer , getActiveSpan, shutdownOtel};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const DailyRotateFile = require('winston-daily-rotate-file');
|
|
4
|
+
|
|
5
|
+
const FileRotationTransport = (CONFIG) =>{
|
|
6
|
+
const transport = new DailyRotateFile({
|
|
7
|
+
dirname: CONFIG.DIR,
|
|
8
|
+
filename: CONFIG.PATH,
|
|
9
|
+
maxSize: CONFIG.SIZE,
|
|
10
|
+
maxFiles: '14d',
|
|
11
|
+
zippedArchive: CONFIG.ZIP_ARCHIVE
|
|
12
|
+
});
|
|
13
|
+
transport.on('archive', (oldFilename, newFilename) => {
|
|
14
|
+
const logPath = oldFilename;
|
|
15
|
+
const info = path.parse(logPath);
|
|
16
|
+
|
|
17
|
+
const date = new Date();
|
|
18
|
+
const timestamp = [
|
|
19
|
+
date.getUTCHours(),
|
|
20
|
+
date.getUTCMinutes(),
|
|
21
|
+
date.getUTCSeconds(),
|
|
22
|
+
date.getUTCDate(),
|
|
23
|
+
date.getUTCMonth() + 1,
|
|
24
|
+
date.getUTCFullYear()
|
|
25
|
+
]
|
|
26
|
+
.map(n => String(n).padStart(2, '0'))
|
|
27
|
+
.join('-');
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const fileName = path.join(info.dir, timestamp);
|
|
31
|
+
const finalPath = fileName + '.log' + info.ext;
|
|
32
|
+
fs.renameSync(oldFilename, finalPath);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
// logger object avoided o prevent recursive logging
|
|
35
|
+
console.error('Error during log file archiving:', e);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return transport
|
|
39
|
+
}
|
|
40
|
+
module.exports = FileRotationTransport;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const WatcherTransport = require("./watcher.transport");
|
|
2
|
+
const FileRotationTransport = require("./file.rotation.transport");
|
|
3
|
+
const StreamTransport = require("./stream.transport");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
WatcherTransport,
|
|
7
|
+
StreamTransport,
|
|
8
|
+
FileRotationTransport,
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const Transport = require("winston-transport");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
|
|
4
|
+
class StreamTransport extends Transport {
|
|
5
|
+
constructor(opts = {}) {
|
|
6
|
+
super(opts);
|
|
7
|
+
this.url = opts.URL;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
log(info, callback) {
|
|
11
|
+
setImmediate(() => this.emit("logged", info));
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
fetch(this.url, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(info),
|
|
20
|
+
})
|
|
21
|
+
} catch (e) {
|
|
22
|
+
// swallow errors to avoid recursive logging
|
|
23
|
+
console.error("Failed to stream logs", e);[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = StreamTransport;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const Transport = require("winston-transport");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
|
|
4
|
+
class WatcherTransport extends Transport {
|
|
5
|
+
constructor(opts = {}) {
|
|
6
|
+
super(opts);
|
|
7
|
+
this.file = opts.PATH;
|
|
8
|
+
this.maxSize = opts.SIZE ?? 2 * 1024 * 1024; // 2MB
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
log(info, callback) {
|
|
12
|
+
setImmediate(() => this.emit("logged", info));
|
|
13
|
+
|
|
14
|
+
const line = JSON.stringify(info) + "\n";
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
if (fs.existsSync(this.file)) {
|
|
18
|
+
const { size } = fs.statSync(this.file);
|
|
19
|
+
if (size > this.maxSize) {
|
|
20
|
+
fs.truncateSync(this.file, 0); // reset
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fs.appendFileSync(this.file, line);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
// swallow errors to avoid recursive logging
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
callback();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = WatcherTransport;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { normalizeData } = require('../helper');
|
|
2
|
+
|
|
3
|
+
const log = (logFunction)=> {return {
|
|
4
|
+
info: (msg, data = null) => logFunction('info', msg, {data:normalizeData(data)}),
|
|
5
|
+
warn: (msg, data = null) => logFunction('warn', msg, {data:normalizeData(data)}),
|
|
6
|
+
error: (msg, data = null) => logFunction('error', msg, {data:normalizeData(data)}),
|
|
7
|
+
debug: (msg, data = null) => logFunction('debug', msg, {data:normalizeData(data)}),
|
|
8
|
+
}};
|
|
9
|
+
|
|
10
|
+
module.exports = log;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const {normalizeData} = require('../helper');
|
|
2
|
+
|
|
3
|
+
const log = (logFunction)=>{
|
|
4
|
+
return {
|
|
5
|
+
info: (msg, data = null) => logFunction('info', msg, {process:'main', data:normalizeData(data)}),
|
|
6
|
+
error: (msg, data = null) => logFunction('warn', msg, {process:'main', data:normalizeData(data)}),
|
|
7
|
+
debug: (msg, data = null) => logFunction('debug', msg, {process:'main', data:normalizeData(data)}),
|
|
8
|
+
warn: (msg, data = null) => logFunction('warn', msg, {process:'main', data:normalizeData(data)}),
|
|
9
|
+
|
|
10
|
+
renderer: {
|
|
11
|
+
info: (msg, data) => logFunction('info', msg, {process:'renderer', data:normalizeData(data)}),
|
|
12
|
+
error: (msg, data) => logFunction('error', msg, {process:'renderer', data:normalizeData(data)}),
|
|
13
|
+
warn: (msg, data) => logFunction('warn', msg, {process:'renderer', data:normalizeData(data)}),
|
|
14
|
+
debug: (msg, data) => logFunction('debug', msg, {process:'renderer', data:normalizeData(data)}),
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = log;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const electronLogger = require("./electron.wrapper");
|
|
2
|
+
const backendLogger = require("./backend.wrapper");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const LoggerFactory = function (loggerName, logger){
|
|
7
|
+
const logFunction = (level, message, extra = {}) =>{
|
|
8
|
+
logger.log({
|
|
9
|
+
level,
|
|
10
|
+
message,
|
|
11
|
+
...extra
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (loggerName === "default") {
|
|
15
|
+
return logFunction;
|
|
16
|
+
}
|
|
17
|
+
if (loggerName === "electron-application") {
|
|
18
|
+
return electronLogger(logFunction);
|
|
19
|
+
}
|
|
20
|
+
if (loggerName === "backend"){
|
|
21
|
+
return backendLogger(logFunction);
|
|
22
|
+
}
|
|
23
|
+
return logFunction;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
module.exports = LoggerFactory;
|