logiscout 1.0.1 → 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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/core/types/LogEntry.d.ts +1 -0
  4. package/dist/cjs/core/types/LogEntry.d.ts.map +1 -1
  5. package/dist/cjs/index.cjs +13 -2
  6. package/dist/cjs/index.d.ts +1 -0
  7. package/dist/cjs/index.d.ts.map +1 -1
  8. package/dist/cjs/init.cjs +13 -0
  9. package/dist/cjs/init.d.ts +3 -0
  10. package/dist/cjs/init.d.ts.map +1 -0
  11. package/dist/cjs/initiator/state.cjs +17 -0
  12. package/dist/cjs/initiator/state.d.ts +8 -0
  13. package/dist/cjs/initiator/state.d.ts.map +1 -0
  14. package/dist/cjs/middlewares/correlationMiddleware.cjs +2 -0
  15. package/dist/cjs/middlewares/correlationMiddleware.d.ts.map +1 -1
  16. package/dist/cjs/services/Logger/Logger.cjs +43 -15
  17. package/dist/cjs/services/Logger/Logger.d.ts +4 -1
  18. package/dist/cjs/services/Logger/Logger.d.ts.map +1 -1
  19. package/dist/cjs/services/formatters/ConsoleFormatter.cjs +37 -0
  20. package/dist/cjs/services/formatters/ConsoleFormatter.d.ts +12 -0
  21. package/dist/cjs/services/formatters/ConsoleFormatter.d.ts.map +1 -0
  22. package/dist/esm/core/types/LogEntry.d.ts +1 -0
  23. package/dist/esm/core/types/LogEntry.d.ts.map +1 -1
  24. package/dist/esm/index.d.ts +1 -0
  25. package/dist/esm/index.d.ts.map +1 -1
  26. package/dist/esm/index.js +11 -1
  27. package/dist/esm/init.d.ts +3 -0
  28. package/dist/esm/init.d.ts.map +1 -0
  29. package/dist/esm/init.js +10 -0
  30. package/dist/esm/initiator/state.d.ts +8 -0
  31. package/dist/esm/initiator/state.d.ts.map +1 -0
  32. package/dist/esm/initiator/state.js +13 -0
  33. package/dist/esm/middlewares/correlationMiddleware.d.ts.map +1 -1
  34. package/dist/esm/middlewares/correlationMiddleware.js +2 -0
  35. package/dist/esm/services/Logger/Logger.d.ts +4 -1
  36. package/dist/esm/services/Logger/Logger.d.ts.map +1 -1
  37. package/dist/esm/services/Logger/Logger.js +43 -15
  38. package/dist/esm/services/formatters/ConsoleFormatter.d.ts +12 -0
  39. package/dist/esm/services/formatters/ConsoleFormatter.d.ts.map +1 -0
  40. package/dist/esm/services/formatters/ConsoleFormatter.js +33 -0
  41. package/package.json +5 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Muhammad Saad Akmal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Logiscout
@@ -5,5 +5,6 @@ export interface LogEntry {
5
5
  timestamp: string;
6
6
  level: LogLevels;
7
7
  correlationId?: string;
8
+ send?: boolean;
8
9
  }
9
10
  //# sourceMappingURL=LogEntry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LogEntry.d.ts","sourceRoot":"","sources":["../../../../src/core/types/LogEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
1
+ {"version":3,"file":"LogEntry.d.ts","sourceRoot":"","sources":["../../../../src/core/types/LogEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAC,OAAO,CAAA;CACd"}
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCorrelationMiddleware = exports.createLogger = exports.BaseLogger = exports.Levels = exports.LogLevels = void 0;
3
+ exports.createCorrelationMiddleware = exports.createLogger = exports.initLogiscout = exports.BaseLogger = exports.Levels = exports.LogLevels = void 0;
4
4
  var LogLevels_js_1 = require("./core/enum/LogLevels.cjs");
5
5
  Object.defineProperty(exports, "LogLevels", { enumerable: true, get: function () { return LogLevels_js_1.LogLevels; } });
6
6
  var Levels_js_1 = require("./services/Levels/Levels.cjs");
7
7
  Object.defineProperty(exports, "Levels", { enumerable: true, get: function () { return Levels_js_1.Levels; } });
8
8
  var Logger_js_1 = require("./services/Logger/Logger.cjs");
9
9
  Object.defineProperty(exports, "BaseLogger", { enumerable: true, get: function () { return Logger_js_1.Logger; } });
10
+ const state_js_1 = require("./initiator/state.cjs");
10
11
  const Levels_js_2 = require("./services/Levels/Levels.cjs");
11
12
  // const Logger = new Levels();
12
- const createLogger = (component) => new Levels_js_2.Levels(component);
13
+ // export const createLogger = (component: string) =>
14
+ // new Levels(component);
15
+ var init_js_1 = require("./init.cjs");
16
+ Object.defineProperty(exports, "initLogiscout", { enumerable: true, get: function () { return init_js_1.initLogiscout; } });
17
+ const createLogger = (component) => {
18
+ const config = (0, state_js_1.getLogiScouConfig)();
19
+ return new Levels_js_2.Levels(component, {
20
+ projectName: config.projectName,
21
+ environment: config.environment,
22
+ });
23
+ };
13
24
  exports.createLogger = createLogger;
14
25
  var correlationMiddleware_js_1 = require("./middlewares/correlationMiddleware.cjs");
15
26
  Object.defineProperty(exports, "createCorrelationMiddleware", { enumerable: true, get: function () { return correlationMiddleware_js_1.createCorrelationMiddleware; } });
@@ -4,6 +4,7 @@ export { LogEntry } from "./core/types/LogEntry.js";
4
4
  export { Levels } from "./services/Levels/Levels.js";
5
5
  export { Logger as BaseLogger } from "./services/Logger/Logger.js";
6
6
  import { Levels } from "./services/Levels/Levels.js";
7
+ export { initLogiscout } from "./init.js";
7
8
  export declare const createLogger: (component: string) => Levels;
8
9
  export { createCorrelationMiddleware } from "./middlewares/correlationMiddleware.js";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAGrD,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,WACvB,CAAC;AAGxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAOrD,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AACvC,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,WAO7C,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initLogiscout = initLogiscout;
4
+ const state_js_1 = require("./initiator/state.cjs");
5
+ function initLogiscout(config) {
6
+ if (!config.projectName) {
7
+ throw new Error("projectName is required");
8
+ }
9
+ if (!config.environment) {
10
+ throw new Error("environment is required");
11
+ }
12
+ (0, state_js_1.setConfig)(config);
13
+ }
@@ -0,0 +1,3 @@
1
+ import { LogiscoutConfig } from "./initiator/state.js";
2
+ export declare function initLogiscout(config: LogiscoutConfig): void;
3
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAa,MAAM,sBAAsB,CAAC;AAIlE,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,QAUpD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setConfig = setConfig;
4
+ exports.getLogiScouConfig = getLogiScouConfig;
5
+ let config = null;
6
+ function setConfig(c) {
7
+ if (config) {
8
+ throw new Error("Logiscout has already been initialized");
9
+ }
10
+ config = c;
11
+ }
12
+ function getLogiScouConfig() {
13
+ if (!config) {
14
+ throw new Error("Logiscout is not initialized. Call initLogiscout() before using the SDK.");
15
+ }
16
+ return config;
17
+ }
@@ -0,0 +1,8 @@
1
+ export type LogiscoutConfig = {
2
+ projectName: string;
3
+ environment: "dev" | "staging" | "prod" | string;
4
+ apiKey?: string;
5
+ };
6
+ export declare function setConfig(c: LogiscoutConfig): void;
7
+ export declare function getLogiScouConfig(): LogiscoutConfig;
8
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/initiator/state.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,QAK3C;AAED,wBAAgB,iBAAiB,IAAI,eAAe,CAOnD"}
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createCorrelationMiddleware = void 0;
7
7
  const RequestContext_js_1 = require("../core/context/RequestContext.cjs");
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
+ const state_js_1 = require("../initiator/state.cjs");
9
10
  const createCorrelationMiddleware = () => {
10
11
  return (req, res, next) => {
11
12
  // Validate request object
13
+ const { projectName, environment } = (0, state_js_1.getLogiScouConfig)(); // 🔒 guard
12
14
  if (!req || typeof req !== "object") {
13
15
  console.error("[CorrelationMiddleware] Error: Invalid request object. " +
14
16
  "Usage: createCorrelationMiddleware()(req, res, next)");
@@ -1 +1 @@
1
- {"version":3,"file":"correlationMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middlewares/correlationMiddleware.ts"],"names":[],"mappings":"AAGA,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACxD,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC9C;AAED,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,UAAU,YAAY;IACpB,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,UAAU,iBAAiB;IACzB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACjE;AAED,eAAO,MAAM,2BAA2B,QAAO,iBAkF9C,CAAC"}
1
+ {"version":3,"file":"correlationMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middlewares/correlationMiddleware.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACxD,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC9C;AAED,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,UAAU,YAAY;IACpB,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,UAAU,iBAAiB;IACzB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACjE;AAED,eAAO,MAAM,2BAA2B,QAAO,iBAmF9C,CAAC"}
@@ -37,10 +37,13 @@ exports.Logger = void 0;
37
37
  const winston_1 = __importStar(require("winston"));
38
38
  const LogLevels_js_1 = require("../../core/enum/LogLevels.cjs");
39
39
  const RequestContext_js_1 = require("../../core/context/RequestContext.cjs");
40
+ const ConsoleFormatter_js_1 = require("../formatters/ConsoleFormatter.cjs");
40
41
  class Logger {
41
42
  winstonLogger;
42
43
  componentName;
43
- constructor(componentName) {
44
+ projectName;
45
+ environment;
46
+ constructor(componentName, config) {
44
47
  // Validate component name
45
48
  if (!componentName || typeof componentName !== "string") {
46
49
  throw new Error("Logger: Component name must be a non-empty string. " +
@@ -51,7 +54,11 @@ class Logger {
51
54
  `Received: '${componentName.substring(0, 20)}...'`);
52
55
  }
53
56
  this.componentName = componentName;
57
+ this.projectName = config.projectName;
58
+ this.environment = config.environment;
54
59
  try {
60
+ // Create structlog-style formatter instance
61
+ const consoleFormatter = new ConsoleFormatter_js_1.ConsoleFormatter();
55
62
  this.winstonLogger = winston_1.default.createLogger({
56
63
  level: "debug",
57
64
  levels: {
@@ -60,15 +67,29 @@ class Logger {
60
67
  info: 2,
61
68
  debug: 3,
62
69
  },
63
- format: winston_1.format.combine(winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.printf(({ timestamp, level, message, component, correlationId, ...meta }) => {
64
- const metaString = Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : "";
65
- return `[${component}] [${timestamp}] [${level.toUpperCase()}] [${correlationId}] ${message}${metaString}`;
70
+ // File transport format (non-colorized)
71
+ format: winston_1.format.combine(winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.printf(({ timestamp, level, message, component, ...meta }) => {
72
+ const formatted = consoleFormatter.format({
73
+ level: level,
74
+ message: String(message),
75
+ timestamp: String(timestamp),
76
+ component: component,
77
+ ...meta,
78
+ });
79
+ return `[${config.projectName}] ${formatted}`;
66
80
  })),
67
81
  transports: [
68
82
  new winston_1.transports.Console({
69
- format: winston_1.format.combine(winston_1.format.colorize({ all: true }), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.printf(({ timestamp, level, message, ...meta }) => {
70
- const metaString = Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : "";
71
- return `[${componentName}] [${timestamp}] [${level}] ${message}${metaString}`;
83
+ // Console transport with structlog-style formatting and colors
84
+ format: winston_1.format.combine(winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.printf(({ timestamp, level, message, component, ...meta }) => {
85
+ const formatted = consoleFormatter.format({
86
+ level: level,
87
+ message: String(message),
88
+ timestamp: String(timestamp),
89
+ component: component,
90
+ ...meta,
91
+ });
92
+ return formatted;
72
93
  })),
73
94
  }),
74
95
  ],
@@ -114,14 +135,20 @@ class Logger {
114
135
  };
115
136
  }
116
137
  this.winstonLogger.log(entry.level, entry.message, logMeta);
117
- // Send structured log to API (no formatting)
118
- // LogApi({
119
- // logs: {
120
- // ...entry,
121
- // component: this.componentName,
122
- // correlationId,
123
- // },
124
- // });
138
+ if (entry.send && this.environment == "prod") {
139
+ // console.log("sending to he server")
140
+ // Send structured log to API (no formatting)
141
+ // LogApi({
142
+ // logs: {
143
+ // ...entry,
144
+ // component: this.componentName,
145
+ // correlationId,
146
+ // },
147
+ // });
148
+ }
149
+ else {
150
+ // console.log("Showed to the user")
151
+ }
125
152
  }
126
153
  catch (error) {
127
154
  // Silent failure - logger should never crash the application
@@ -149,6 +176,7 @@ class Logger {
149
176
  meta,
150
177
  timestamp: new Date().toISOString(),
151
178
  level: logLevel,
179
+ send: true
152
180
  };
153
181
  return entry;
154
182
  }
@@ -1,10 +1,13 @@
1
1
  import { Logger as WinstonLogger } from "winston";
2
2
  import { LogEntry } from "../../core/types/LogEntry.js";
3
3
  import { LogLevels } from "../../core/enum/LogLevels.js";
4
+ import { LogiscoutConfig } from "../../initiator/state.js";
4
5
  export declare abstract class Logger {
5
6
  protected winstonLogger: WinstonLogger;
6
7
  private componentName;
7
- constructor(componentName: string);
8
+ private projectName;
9
+ private environment;
10
+ constructor(componentName: string, config: LogiscoutConfig);
8
11
  protected log(entry: LogEntry): void;
9
12
  getWinstonLogger(): WinstonLogger;
10
13
  protected getLogEntry(message: string, logLevel: LogLevels, meta?: Record<string, unknown>): LogEntry;
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/services/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,IAAI,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD,8BAAsB,MAAM;IAC1B,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,OAAO,CAAC,aAAa,CAAS;gBAElB,aAAa,EAAE,MAAM;IAkEjC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAgEpC,gBAAgB,IAAI,aAAa;IAIjC,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,QAAQ;CAyBZ"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/services/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,IAAI,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAI3D,8BAAsB,MAAM;IAC1B,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAQ;gBAEf,aAAa,EAAE,MAAM,EAAG,MAAM,EAAC,eAAe;IAwE1D,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAsEpC,gBAAgB,IAAI,aAAa;IAIjC,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,QAAQ;CA0BZ"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleFormatter = void 0;
4
+ const LogLevels_js_1 = require("../../core/enum/LogLevels.cjs");
5
+ const LEVEL_COLORS = {
6
+ [LogLevels_js_1.LogLevels.DEBUG]: "\x1b[90m", // gray
7
+ [LogLevels_js_1.LogLevels.INFO]: "\x1b[32m", // green
8
+ [LogLevels_js_1.LogLevels.WARN]: "\x1b[33m", // yellow
9
+ [LogLevels_js_1.LogLevels.ERROR]: "\x1b[31m", // red
10
+ [LogLevels_js_1.LogLevels.CRITICAL]: "\x1b[35m" // magenta
11
+ };
12
+ const RESET = "\x1b[0m";
13
+ class ConsoleFormatter {
14
+ format(data) {
15
+ const { level, message, timestamp, component, meta } = data;
16
+ const color = LEVEL_COLORS[level] ?? "";
17
+ const levelLabel = `${color}${level.toUpperCase()}${RESET}`;
18
+ const componentLabel = component ?? "App";
19
+ let output = `${timestamp} ` +
20
+ `[${levelLabel}] ` +
21
+ `[${componentLabel}] ` +
22
+ `${message}`;
23
+ if (meta && Object.keys(meta).length > 0) {
24
+ output += `\n${this.prettyJson(meta)}`;
25
+ }
26
+ return output;
27
+ }
28
+ prettyJson(obj) {
29
+ try {
30
+ return JSON.stringify(obj, null, 2);
31
+ }
32
+ catch {
33
+ return "{ \"error\": \"Failed to serialize metadata\" }";
34
+ }
35
+ }
36
+ }
37
+ exports.ConsoleFormatter = ConsoleFormatter;
@@ -0,0 +1,12 @@
1
+ import { LogLevels } from "../../core/enum/LogLevels.js";
2
+ export declare class ConsoleFormatter {
3
+ format(data: {
4
+ level: LogLevels;
5
+ message: string;
6
+ timestamp: string;
7
+ component?: string;
8
+ meta?: Record<string, unknown>;
9
+ }): string;
10
+ private prettyJson;
11
+ }
12
+ //# sourceMappingURL=ConsoleFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsoleFormatter.d.ts","sourceRoot":"","sources":["../../../../src/services/formatters/ConsoleFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAazD,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,IAAI,EAAE;QACX,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC,GAAG,MAAM;IAoBV,OAAO,CAAC,UAAU;CAOnB"}
@@ -5,5 +5,6 @@ export interface LogEntry {
5
5
  timestamp: string;
6
6
  level: LogLevels;
7
7
  correlationId?: string;
8
+ send?: boolean;
8
9
  }
9
10
  //# sourceMappingURL=LogEntry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LogEntry.d.ts","sourceRoot":"","sources":["../../../../src/core/types/LogEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
1
+ {"version":3,"file":"LogEntry.d.ts","sourceRoot":"","sources":["../../../../src/core/types/LogEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAC,OAAO,CAAA;CACd"}
@@ -4,6 +4,7 @@ export { LogEntry } from "./core/types/LogEntry.js";
4
4
  export { Levels } from "./services/Levels/Levels.js";
5
5
  export { Logger as BaseLogger } from "./services/Logger/Logger.js";
6
6
  import { Levels } from "./services/Levels/Levels.js";
7
+ export { initLogiscout } from "./init.js";
7
8
  export declare const createLogger: (component: string) => Levels;
8
9
  export { createCorrelationMiddleware } from "./middlewares/correlationMiddleware.js";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAGrD,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,WACvB,CAAC;AAGxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAOrD,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AACvC,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,WAO7C,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,8 +1,18 @@
1
1
  export { LogLevels } from "./core/enum/LogLevels.js";
2
2
  export { Levels } from "./services/Levels/Levels.js";
3
3
  export { Logger as BaseLogger } from "./services/Logger/Logger.js";
4
+ import { getLogiScouConfig } from "./initiator/state.js";
4
5
  import { Levels } from "./services/Levels/Levels.js";
5
6
  // const Logger = new Levels();
6
- export const createLogger = (component) => new Levels(component);
7
+ // export const createLogger = (component: string) =>
8
+ // new Levels(component);
9
+ export { initLogiscout } from "./init.js";
10
+ export const createLogger = (component) => {
11
+ const config = getLogiScouConfig();
12
+ return new Levels(component, {
13
+ projectName: config.projectName,
14
+ environment: config.environment,
15
+ });
16
+ };
7
17
  export { createCorrelationMiddleware } from "./middlewares/correlationMiddleware.js";
8
18
  // export { Logger };
@@ -0,0 +1,3 @@
1
+ import { LogiscoutConfig } from "./initiator/state.js";
2
+ export declare function initLogiscout(config: LogiscoutConfig): void;
3
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAa,MAAM,sBAAsB,CAAC;AAIlE,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,QAUpD"}
@@ -0,0 +1,10 @@
1
+ import { setConfig } from "./initiator/state.js";
2
+ export function initLogiscout(config) {
3
+ if (!config.projectName) {
4
+ throw new Error("projectName is required");
5
+ }
6
+ if (!config.environment) {
7
+ throw new Error("environment is required");
8
+ }
9
+ setConfig(config);
10
+ }
@@ -0,0 +1,8 @@
1
+ export type LogiscoutConfig = {
2
+ projectName: string;
3
+ environment: "dev" | "staging" | "prod" | string;
4
+ apiKey?: string;
5
+ };
6
+ export declare function setConfig(c: LogiscoutConfig): void;
7
+ export declare function getLogiScouConfig(): LogiscoutConfig;
8
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/initiator/state.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,QAK3C;AAED,wBAAgB,iBAAiB,IAAI,eAAe,CAOnD"}
@@ -0,0 +1,13 @@
1
+ let config = null;
2
+ export function setConfig(c) {
3
+ if (config) {
4
+ throw new Error("Logiscout has already been initialized");
5
+ }
6
+ config = c;
7
+ }
8
+ export function getLogiScouConfig() {
9
+ if (!config) {
10
+ throw new Error("Logiscout is not initialized. Call initLogiscout() before using the SDK.");
11
+ }
12
+ return config;
13
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"correlationMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middlewares/correlationMiddleware.ts"],"names":[],"mappings":"AAGA,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACxD,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC9C;AAED,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,UAAU,YAAY;IACpB,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,UAAU,iBAAiB;IACzB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACjE;AAED,eAAO,MAAM,2BAA2B,QAAO,iBAkF9C,CAAC"}
1
+ {"version":3,"file":"correlationMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middlewares/correlationMiddleware.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACxD,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC9C;AAED,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,UAAU,YAAY;IACpB,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,UAAU,iBAAiB;IACzB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACjE;AAED,eAAO,MAAM,2BAA2B,QAAO,iBAmF9C,CAAC"}
@@ -1,8 +1,10 @@
1
1
  import { RequestContext } from "../core/context/RequestContext.js";
2
2
  import crypto from "crypto";
3
+ import { getLogiScouConfig } from "../initiator/state.js";
3
4
  export const createCorrelationMiddleware = () => {
4
5
  return (req, res, next) => {
5
6
  // Validate request object
7
+ const { projectName, environment } = getLogiScouConfig(); // 🔒 guard
6
8
  if (!req || typeof req !== "object") {
7
9
  console.error("[CorrelationMiddleware] Error: Invalid request object. " +
8
10
  "Usage: createCorrelationMiddleware()(req, res, next)");
@@ -1,10 +1,13 @@
1
1
  import { Logger as WinstonLogger } from "winston";
2
2
  import { LogEntry } from "../../core/types/LogEntry.js";
3
3
  import { LogLevels } from "../../core/enum/LogLevels.js";
4
+ import { LogiscoutConfig } from "../../initiator/state.js";
4
5
  export declare abstract class Logger {
5
6
  protected winstonLogger: WinstonLogger;
6
7
  private componentName;
7
- constructor(componentName: string);
8
+ private projectName;
9
+ private environment;
10
+ constructor(componentName: string, config: LogiscoutConfig);
8
11
  protected log(entry: LogEntry): void;
9
12
  getWinstonLogger(): WinstonLogger;
10
13
  protected getLogEntry(message: string, logLevel: LogLevels, meta?: Record<string, unknown>): LogEntry;
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/services/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,IAAI,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD,8BAAsB,MAAM;IAC1B,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,OAAO,CAAC,aAAa,CAAS;gBAElB,aAAa,EAAE,MAAM;IAkEjC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAgEpC,gBAAgB,IAAI,aAAa;IAIjC,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,QAAQ;CAyBZ"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/services/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,IAAI,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAI3D,8BAAsB,MAAM;IAC1B,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAQ;gBAEf,aAAa,EAAE,MAAM,EAAG,MAAM,EAAC,eAAe;IAwE1D,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAsEpC,gBAAgB,IAAI,aAAa;IAIjC,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,QAAQ;CA0BZ"}
@@ -1,10 +1,13 @@
1
1
  import winston, { format, transports } from "winston";
2
2
  import { LogLevels } from "../../core/enum/LogLevels.js";
3
3
  import { RequestContext } from "../../core/context/RequestContext.js";
4
+ import { ConsoleFormatter } from "../formatters/ConsoleFormatter.js";
4
5
  export class Logger {
5
6
  winstonLogger;
6
7
  componentName;
7
- constructor(componentName) {
8
+ projectName;
9
+ environment;
10
+ constructor(componentName, config) {
8
11
  // Validate component name
9
12
  if (!componentName || typeof componentName !== "string") {
10
13
  throw new Error("Logger: Component name must be a non-empty string. " +
@@ -15,7 +18,11 @@ export class Logger {
15
18
  `Received: '${componentName.substring(0, 20)}...'`);
16
19
  }
17
20
  this.componentName = componentName;
21
+ this.projectName = config.projectName;
22
+ this.environment = config.environment;
18
23
  try {
24
+ // Create structlog-style formatter instance
25
+ const consoleFormatter = new ConsoleFormatter();
19
26
  this.winstonLogger = winston.createLogger({
20
27
  level: "debug",
21
28
  levels: {
@@ -24,15 +31,29 @@ export class Logger {
24
31
  info: 2,
25
32
  debug: 3,
26
33
  },
27
- format: format.combine(format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, component, correlationId, ...meta }) => {
28
- const metaString = Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : "";
29
- return `[${component}] [${timestamp}] [${level.toUpperCase()}] [${correlationId}] ${message}${metaString}`;
34
+ // File transport format (non-colorized)
35
+ format: format.combine(format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, component, ...meta }) => {
36
+ const formatted = consoleFormatter.format({
37
+ level: level,
38
+ message: String(message),
39
+ timestamp: String(timestamp),
40
+ component: component,
41
+ ...meta,
42
+ });
43
+ return `[${config.projectName}] ${formatted}`;
30
44
  })),
31
45
  transports: [
32
46
  new transports.Console({
33
- format: format.combine(format.colorize({ all: true }), format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, ...meta }) => {
34
- const metaString = Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : "";
35
- return `[${componentName}] [${timestamp}] [${level}] ${message}${metaString}`;
47
+ // Console transport with structlog-style formatting and colors
48
+ format: format.combine(format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, component, ...meta }) => {
49
+ const formatted = consoleFormatter.format({
50
+ level: level,
51
+ message: String(message),
52
+ timestamp: String(timestamp),
53
+ component: component,
54
+ ...meta,
55
+ });
56
+ return formatted;
36
57
  })),
37
58
  }),
38
59
  ],
@@ -78,14 +99,20 @@ export class Logger {
78
99
  };
79
100
  }
80
101
  this.winstonLogger.log(entry.level, entry.message, logMeta);
81
- // Send structured log to API (no formatting)
82
- // LogApi({
83
- // logs: {
84
- // ...entry,
85
- // component: this.componentName,
86
- // correlationId,
87
- // },
88
- // });
102
+ if (entry.send && this.environment == "prod") {
103
+ // console.log("sending to he server")
104
+ // Send structured log to API (no formatting)
105
+ // LogApi({
106
+ // logs: {
107
+ // ...entry,
108
+ // component: this.componentName,
109
+ // correlationId,
110
+ // },
111
+ // });
112
+ }
113
+ else {
114
+ // console.log("Showed to the user")
115
+ }
89
116
  }
90
117
  catch (error) {
91
118
  // Silent failure - logger should never crash the application
@@ -113,6 +140,7 @@ export class Logger {
113
140
  meta,
114
141
  timestamp: new Date().toISOString(),
115
142
  level: logLevel,
143
+ send: true
116
144
  };
117
145
  return entry;
118
146
  }
@@ -0,0 +1,12 @@
1
+ import { LogLevels } from "../../core/enum/LogLevels.js";
2
+ export declare class ConsoleFormatter {
3
+ format(data: {
4
+ level: LogLevels;
5
+ message: string;
6
+ timestamp: string;
7
+ component?: string;
8
+ meta?: Record<string, unknown>;
9
+ }): string;
10
+ private prettyJson;
11
+ }
12
+ //# sourceMappingURL=ConsoleFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsoleFormatter.d.ts","sourceRoot":"","sources":["../../../../src/services/formatters/ConsoleFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAazD,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,IAAI,EAAE;QACX,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC,GAAG,MAAM;IAoBV,OAAO,CAAC,UAAU;CAOnB"}
@@ -0,0 +1,33 @@
1
+ import { LogLevels } from "../../core/enum/LogLevels.js";
2
+ const LEVEL_COLORS = {
3
+ [LogLevels.DEBUG]: "\x1b[90m", // gray
4
+ [LogLevels.INFO]: "\x1b[32m", // green
5
+ [LogLevels.WARN]: "\x1b[33m", // yellow
6
+ [LogLevels.ERROR]: "\x1b[31m", // red
7
+ [LogLevels.CRITICAL]: "\x1b[35m" // magenta
8
+ };
9
+ const RESET = "\x1b[0m";
10
+ export class ConsoleFormatter {
11
+ format(data) {
12
+ const { level, message, timestamp, component, meta } = data;
13
+ const color = LEVEL_COLORS[level] ?? "";
14
+ const levelLabel = `${color}${level.toUpperCase()}${RESET}`;
15
+ const componentLabel = component ?? "App";
16
+ let output = `${timestamp} ` +
17
+ `[${levelLabel}] ` +
18
+ `[${componentLabel}] ` +
19
+ `${message}`;
20
+ if (meta && Object.keys(meta).length > 0) {
21
+ output += `\n${this.prettyJson(meta)}`;
22
+ }
23
+ return output;
24
+ }
25
+ prettyJson(obj) {
26
+ try {
27
+ return JSON.stringify(obj, null, 2);
28
+ }
29
+ catch {
30
+ return "{ \"error\": \"Failed to serialize metadata\" }";
31
+ }
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logiscout",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Logiscout — a structured logger library",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -43,10 +43,12 @@
43
43
  "node": ">=18"
44
44
  },
45
45
  "dependencies": {
46
+ "axios": "^1.13.2",
46
47
  "winston": "^3.11.0"
47
48
  },
48
49
  "devDependencies": {
49
- "typescript": "^5.3.3",
50
- "@types/node": "^20.10.0"
50
+ "@types/node": "^20.10.0",
51
+ "ts-node": "^10.9.2",
52
+ "typescript": "^5.9.3"
51
53
  }
52
54
  }