@arnob-b/observability 1.0.2 → 1.0.3

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 CHANGED
@@ -79,21 +79,26 @@ module.exports = OBSERVABILITY_CONFIG;
79
79
 
80
80
  ### predefined logger object from factory
81
81
  ```javascript
82
- const electronLogger = Observability.getLogger("electron-application");
83
-
84
- module.exports = electronLogger;
85
- ```
86
-
87
- there are two products from logger factory, one is for electron-application another is for backend node environment.
82
+ const {logFunction} = require("@arnob-b/observability")
83
+ const {normalizeData} = require("./helper.cjs")
84
+
85
+ const log = {
86
+ info: (msg, data = null) => logFunction('info', msg, {process:'main', data:normalizeData(data)}),
87
+ error: (msg, data = null) => logFunction('warn', msg, {process:'main', data:normalizeData(data)}),
88
+ debug: (msg, data = null) => logFunction('debug', msg, {process:'main', data:normalizeData(data)}),
89
+ warn: (msg, data = null) => logFunction('warn', msg, {process:'main', data:normalizeData(data)}),
90
+
91
+ renderer: {
92
+ info: (msg, data) => logFunction('info', msg, {process:'renderer', data:normalizeData(data)}),
93
+ error: (msg, data) => logFunction('error', msg, {process:'renderer', data:normalizeData(data)}),
94
+ warn: (msg, data) => logFunction('warn', msg, {process:'renderer', data:normalizeData(data)}),
95
+ debug: (msg, data) => logFunction('debug', msg, {process:'renderer', data:normalizeData(data)}),
96
+ }
97
+ }
88
98
 
89
- #### using logger in electron application
90
- ```javascript
91
- const log = require('./utils/logger');
92
- log.info("This is an info log from electron application");
93
- log.render.info("This is a render log from electron application");
99
+ module.exports = log;
94
100
  ```
95
101
 
96
-
97
102
  ### adding hooks for events emmited by tranports
98
103
 
99
104
  ```javascript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arnob-b/observability",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "observability for nodejs application using winston and opentelemetry",
5
5
  "keywords": ["observability", "nodejs", "winston", "opentelemetry", "electron", "desktop application"],
6
6
  "license": "MIT",
@@ -10,13 +10,15 @@
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1"
12
12
  },
13
- "peerDependencies": {
14
- "@opentelemetry/api": "^1.9.0",
13
+ "dependencies": {
15
14
  "@opentelemetry/instrumentation-undici": "^0.21.0",
16
15
  "@opentelemetry/sdk-node": "^0.212.0",
17
16
  "@opentelemetry/instrumentation-express": "^0.59.0",
18
17
  "@opentelemetry/instrumentation-http": "^0.212.0",
19
- "winston": "^3.19.0",
20
18
  "winston-daily-rotate-file": "^5.0.0"
19
+ },
20
+ "peerDependencies": {
21
+ "@opentelemetry/api": "^1.9.0",
22
+ "winston": "^3.19.0"
21
23
  }
22
24
  }
package/src/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  const { traceExecution, traceAsyncExecution, startTracedExecution } = require("./otel");
2
- const {attachHooksOnTransport} = require("./logger");
2
+ const {attachHooksOnTransport, logFunction} = require("./logger");
3
3
  const Observability = require("./observability");
4
4
 
5
5
 
6
6
  module.exports = {
7
7
  Observability,
8
+ logFunction,
8
9
  traceExecution,
9
10
  traceAsyncExecution,
10
11
  startTracedExecution,
package/src/logger.js CHANGED
@@ -38,8 +38,16 @@ function attachHooksOnTransport(transportName, hooks = {}){
38
38
  }
39
39
  }
40
40
 
41
+ const logFunction = (level, message, extra = {}) =>{
42
+ logger.log({
43
+ level,
44
+ message,
45
+ ...extra
46
+ });
47
+ }
41
48
 
42
49
  module.exports = {
43
50
  initLogger,
44
- attachHooksOnTransport
51
+ attachHooksOnTransport,
52
+ logFunction
45
53
  }
@@ -1,6 +1,5 @@
1
1
  const {initOtel} = require("./otel");
2
2
  const {initLogger} = require("./logger");
3
- const { LoggerFactory } = require("./wrappers");
4
3
  class Observability {
5
4
  constructor() {
6
5
  if (Observability.instance) {
@@ -21,13 +20,6 @@ class Observability {
21
20
 
22
21
  this.initialized = true;
23
22
  }
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
23
  }
32
24
 
33
25
 
@@ -30,6 +30,10 @@ const FileRotationTransport = (CONFIG) =>{
30
30
  const fileName = path.join(info.dir, timestamp);
31
31
  const finalPath = fileName + '.log' + info.ext;
32
32
  fs.renameSync(oldFilename, finalPath);
33
+ transport.emit('post-archive',{
34
+ originalPath: oldFilename,
35
+ archivedPath: finalPath
36
+ })
33
37
  } catch (e) {
34
38
  // logger object avoided o prevent recursive logging
35
39
  console.error('Error during log file archiving:', e);
@@ -1,17 +0,0 @@
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
- };
@@ -1,10 +0,0 @@
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;
@@ -1,19 +0,0 @@
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;
@@ -1,28 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- const LoggerFactory = require('./factory');
2
- module.exports = {
3
- LoggerFactory
4
- }