navi-hey 1.2.0 → 1.2.1

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 (35) hide show
  1. package/lib/common/utils/EnvResolver.js +26 -0
  2. package/lib/common/utils/env_resolver/EnvStringResolver.js +52 -0
  3. package/lib/common/utils/logging/BaseLogger.js +98 -0
  4. package/lib/common/utils/logging/BufferedLogger.js +100 -0
  5. package/lib/common/utils/logging/ConsoleLogger.js +20 -0
  6. package/lib/common/utils/logging/Log.js +82 -0
  7. package/lib/common/utils/logging/LogBuffer.js +122 -0
  8. package/lib/common/utils/logging/LogBufferCollection.js +56 -0
  9. package/lib/common/utils/logging/LogContext.js +51 -0
  10. package/lib/common/utils/logging/LogFactory.js +33 -0
  11. package/lib/common/utils/logging/LogFilter.js +34 -0
  12. package/lib/common/utils/logging/Logger.js +138 -0
  13. package/lib/common/utils/logging/LoggerGroup.js +104 -0
  14. package/lib/models/configs/Link.js +36 -0
  15. package/lib/models/configs/WebConfig.js +5 -1
  16. package/lib/server/Router.js +2 -0
  17. package/lib/server/handlers/LinksRequestHandler.js +32 -0
  18. package/lib/services/ConfigLoader.js +3 -3
  19. package/lib/utils/logging/BaseLogger.js +1 -98
  20. package/lib/utils/logging/BufferedLogger.js +1 -100
  21. package/lib/utils/logging/ConsoleLogger.js +1 -20
  22. package/lib/utils/logging/Log.js +1 -82
  23. package/lib/utils/logging/LogBuffer.js +1 -122
  24. package/lib/utils/logging/LogBufferCollection.js +1 -56
  25. package/lib/utils/logging/LogContext.js +1 -51
  26. package/lib/utils/logging/LogFactory.js +1 -33
  27. package/lib/utils/logging/LogFilter.js +1 -34
  28. package/lib/utils/logging/Logger.js +1 -138
  29. package/lib/utils/logging/LoggerGroup.js +1 -104
  30. package/package.json +1 -1
  31. package/static/assets/index-CX_uXu4Q.js +11 -0
  32. package/static/favicon.png +0 -0
  33. package/static/index.html +2 -1
  34. package/lib/utils/EnvResolver.js +0 -75
  35. package/static/assets/index-D5tOOLpl.js +0 -11
@@ -0,0 +1,138 @@
1
+ import { ConsoleLogger } from './ConsoleLogger.js';
2
+ import { LoggerGroup } from './LoggerGroup.js';
3
+
4
+ /**
5
+ * Static facade for the default LoggerGroup singleton.
6
+ * All instance-level log logic lives in BaseLogger / ConsoleLogger / LoggerGroup.
7
+ *
8
+ * @example <caption>Basic logging (default ConsoleLogger)</caption>
9
+ * Logger.info('Server started');
10
+ * Logger.warn('Low memory');
11
+ * Logger.error('Request failed');
12
+ *
13
+ * @example <caption>Swap to a custom logger</caption>
14
+ * Logger.setLogger(myCustomLogger);
15
+ * Logger.info('Now routed through myCustomLogger');
16
+ *
17
+ * @example <caption>Add an extra log destination</caption>
18
+ * const buffered = new BufferedLogger();
19
+ * Logger.addLogger(buffered);
20
+ * Logger.info('Goes to console and buffered logger');
21
+ *
22
+ * @example <caption>Suppress all output</caption>
23
+ * Logger.suppress();
24
+ * Logger.info('This will not be printed');
25
+ * Logger.suppress(false); // restore output
26
+ *
27
+ * @author darthjee
28
+ */
29
+ class Logger {
30
+ static #loggerGroup;
31
+
32
+ /**
33
+ * Returns the default LoggerGroup instance (singleton).
34
+ * Initialized with a ConsoleLogger on first access.
35
+ * @returns {LoggerGroup} The default logger group instance.
36
+ */
37
+ static default() {
38
+ this.#ensureLoggerGroup();
39
+ return this.#loggerGroup;
40
+ }
41
+
42
+ /**
43
+ * Logs a debug message using the default logger instance.
44
+ * @param {string} message - The message to log.
45
+ * @param {object} [attributes={}] - Optional structured metadata.
46
+ * @returns {void}
47
+ */
48
+ static debug(message, attributes = {}) {
49
+ this.default().debug(message, attributes);
50
+ }
51
+
52
+ /**
53
+ * Logs an info message using the default logger instance.
54
+ * @param {string} message - The message to log.
55
+ * @param {object} [attributes={}] - Optional structured metadata.
56
+ * @returns {void}
57
+ */
58
+ static info(message, attributes = {}) {
59
+ this.default().info(message, attributes);
60
+ }
61
+
62
+ /**
63
+ * Logs a warn message using the default logger instance.
64
+ * @param {string} message - The message to log.
65
+ * @param {object} [attributes={}] - Optional structured metadata.
66
+ * @returns {void}
67
+ */
68
+ static warn(message, attributes = {}) {
69
+ this.default().warn(message, attributes);
70
+ }
71
+
72
+ /**
73
+ * Logs an error message using the default logger instance.
74
+ * @param {string} message - The message to log.
75
+ * @param {object} [attributes={}] - Optional structured metadata.
76
+ * @returns {void}
77
+ */
78
+ static error(message, attributes = {}) {
79
+ this.default().error(message, attributes);
80
+ }
81
+
82
+ /**
83
+ * Suppresses or restores log output on the default logger instance.
84
+ * @param {boolean} [value=true] - When true, all log output is suppressed.
85
+ * @returns {void}
86
+ */
87
+ static suppress(value = true) {
88
+ this.default().suppress(value);
89
+ }
90
+
91
+ /**
92
+ * Sets the log level threshold on the default logger instance.
93
+ * @param {string} level - The new log level ('debug', 'info', 'warn', 'error', 'silent').
94
+ * @returns {void}
95
+ */
96
+ static setLevel(level) {
97
+ this.default().setLevel(level);
98
+ }
99
+
100
+ /**
101
+ * Resets the default logger group so a new one is created on the next call to default().
102
+ * Useful in tests to ensure a clean singleton state.
103
+ * @returns {void}
104
+ */
105
+ static reset() {
106
+ this.#loggerGroup = null;
107
+ }
108
+
109
+ /**
110
+ * Replaces the default logger group with a new LoggerGroup containing the provided logger.
111
+ * @param {BaseLogger} logger - The logger instance to use in the new group.
112
+ * @returns {void}
113
+ */
114
+ static setLogger(logger) {
115
+ this.#loggerGroup = new LoggerGroup([logger]);
116
+ }
117
+
118
+ /**
119
+ * Adds a logger to the default logger group.
120
+ * @param {BaseLogger} logger - The logger instance to add.
121
+ * @returns {void}
122
+ */
123
+ static addLogger(logger) {
124
+ this.default().addLogger(logger);
125
+ }
126
+
127
+ /**
128
+ * Ensures the default LoggerGroup instance exists, creating one with a ConsoleLogger if needed.
129
+ * @returns {void}
130
+ */
131
+ static #ensureLoggerGroup() {
132
+ if (!this.#loggerGroup) {
133
+ this.#loggerGroup = new LoggerGroup([new ConsoleLogger()]);
134
+ }
135
+ }
136
+ }
137
+
138
+ export { Logger };
@@ -0,0 +1,104 @@
1
+ /**
2
+ * LoggerGroup broadcasts log messages to multiple Logger instances.
3
+ * Useful for sending the same log output to multiple destinations (console, web, file, etc.).
4
+ * @author darthjee
5
+ */
6
+ class LoggerGroup {
7
+ #loggers;
8
+
9
+ /**
10
+ * Creates a new LoggerGroup instance.
11
+ * @param {Array<Logger>} [loggers=[]] - Array of Logger instances to broadcast to.
12
+ */
13
+ constructor(loggers = []) {
14
+ this.#loggers = loggers;
15
+ }
16
+
17
+ /**
18
+ * Adds a logger to the group.
19
+ * @param {Logger} logger - The Logger instance to add.
20
+ * @returns {LoggerGroup} This instance for method chaining.
21
+ */
22
+ addLogger(logger) {
23
+ this.#loggers.push(logger);
24
+ return this;
25
+ }
26
+
27
+ /**
28
+ * Removes a logger from the group.
29
+ * @param {Logger} logger - The Logger instance to remove.
30
+ * @returns {LoggerGroup} This instance for method chaining.
31
+ */
32
+ removeLogger(logger) {
33
+ this.#loggers = this.#loggers.filter(l => l !== logger);
34
+ return this;
35
+ }
36
+
37
+ /**
38
+ * Returns all loggers in the group.
39
+ * @returns {Array<Logger>} Array of Logger instances.
40
+ */
41
+ getLoggers() {
42
+ return [...this.#loggers];
43
+ }
44
+
45
+ /**
46
+ * Broadcasts a debug message to all loggers in the group.
47
+ * @param {string} message - The message to log.
48
+ * @param {object} [attributes={}] - Optional structured metadata.
49
+ * @returns {void}
50
+ */
51
+ debug(message, attributes = {}) {
52
+ this.#loggers.forEach(logger => logger.debug(message, attributes));
53
+ }
54
+
55
+ /**
56
+ * Broadcasts an info message to all loggers in the group.
57
+ * @param {string} message - The message to log.
58
+ * @param {object} [attributes={}] - Optional structured metadata.
59
+ * @returns {void}
60
+ */
61
+ info(message, attributes = {}) {
62
+ this.#loggers.forEach(logger => logger.info(message, attributes));
63
+ }
64
+
65
+ /**
66
+ * Broadcasts a warn message to all loggers in the group.
67
+ * @param {string} message - The message to log.
68
+ * @param {object} [attributes={}] - Optional structured metadata.
69
+ * @returns {void}
70
+ */
71
+ warn(message, attributes = {}) {
72
+ this.#loggers.forEach(logger => logger.warn(message, attributes));
73
+ }
74
+
75
+ /**
76
+ * Broadcasts an error message to all loggers in the group.
77
+ * @param {string} message - The message to log.
78
+ * @param {object} [attributes={}] - Optional structured metadata.
79
+ * @returns {void}
80
+ */
81
+ error(message, attributes = {}) {
82
+ this.#loggers.forEach(logger => logger.error(message, attributes));
83
+ }
84
+
85
+ /**
86
+ * Suppresses or restores log output on all loggers in the group.
87
+ * @param {boolean} [value=true] - When true, all log output is suppressed.
88
+ * @returns {void}
89
+ */
90
+ suppress(value = true) {
91
+ this.#loggers.forEach(logger => logger.suppress(value));
92
+ }
93
+
94
+ /**
95
+ * Sets the log level threshold on all loggers in the group.
96
+ * @param {string} level - The new log level ('debug', 'info', 'warn', 'error', 'silent').
97
+ * @returns {void}
98
+ */
99
+ setLevel(level) {
100
+ this.#loggers.forEach(logger => logger.setLevel(level));
101
+ }
102
+ }
103
+
104
+ export { LoggerGroup };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Represents a web link item configured for the UI.
3
+ * @author darthjee
4
+ */
5
+ class Link {
6
+ /**
7
+ * Creates a Link instance.
8
+ * @param {object} params - Constructor params.
9
+ * @param {string} params.url - Link URL.
10
+ * @param {string} [params.text] - Link display text.
11
+ */
12
+ constructor({ url, text }) {
13
+ this.url = url;
14
+ this.text = text ?? url;
15
+ }
16
+
17
+ /**
18
+ * Creates a Link instance from a YAML entry.
19
+ * @param {string|object} entry - A URL string or an object with text/url fields.
20
+ * @returns {Link} The parsed Link instance.
21
+ */
22
+ static fromObject(entry) {
23
+ if (typeof entry === 'string') return new Link({ url: entry, text: entry });
24
+ return new Link({ url: entry.url, text: entry.text });
25
+ }
26
+
27
+ /**
28
+ * Serializes this link for JSON responses.
29
+ * @returns {{url: string, text: string}} The serialized link.
30
+ */
31
+ toJSON() {
32
+ return { url: this.url, text: this.text };
33
+ }
34
+ }
35
+
36
+ export { Link };
@@ -1,3 +1,5 @@
1
+ import { Link } from './Link.js';
2
+
1
3
  /**
2
4
  * Represents the web server configuration.
3
5
  * @author darthjee
@@ -8,11 +10,13 @@ class WebConfig {
8
10
  * @param {number} config.port - The port number to listen on.
9
11
  * @param {number} [config.logs_page_size=20] - Maximum number of log entries per page.
10
12
  * @param {boolean} [config.enable_shutdown=true] - Whether the shutdown button is enabled.
13
+ * @param {Array<string|object>} [config.links=[]] - Links shown in the web UI.
11
14
  */
12
- constructor({ port, logs_page_size: logsPageSize = 20, enable_shutdown: enableShutdown = true }) {
15
+ constructor({ port, logs_page_size: logsPageSize = 20, enable_shutdown: enableShutdown = true, links = [] }) {
13
16
  this.port = port;
14
17
  this.logsPageSize = logsPageSize;
15
18
  this.enableShutdown = enableShutdown;
19
+ this.links = links.map((link) => Link.fromObject(link));
16
20
  }
17
21
  }
18
22
 
@@ -15,6 +15,7 @@ import { JobLogsRequestHandler } from './handlers/jobs/JobLogsRequestHandler.js'
15
15
  import { JobRequestHandler } from './handlers/jobs/JobRequestHandler.js';
16
16
  import { JobRetryRequestHandler } from './handlers/jobs/JobRetryRequestHandler.js';
17
17
  import { JobsRequestHandler } from './handlers/jobs/JobsRequestHandler.js';
18
+ import { LinksRequestHandler } from './handlers/LinksRequestHandler.js';
18
19
  import { LogsRequestHandler } from './handlers/LogsRequestHandler.js';
19
20
  import { SettingsRequestHandler } from './handlers/SettingsRequestHandler.js';
20
21
  import { StatsRequestHandler } from './handlers/StatsRequestHandler.js';
@@ -57,6 +58,7 @@ class Router {
57
58
  '/job/:id.json': new JobRequestHandler(),
58
59
  '/engine/status': new EngineStatusRequestHandler(),
59
60
  '/logs.json': new LogsRequestHandler({ pageSize: this.#webConfig.logsPageSize }),
61
+ '/links.json': new LinksRequestHandler({ links: this.#webConfig.links }),
60
62
  '/': new IndexRequestHandler(),
61
63
  '/assets/*path': new AssetsRequestHandler(),
62
64
  };
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../RequestHandler.js';
2
+
3
+ /**
4
+ * Handles GET /links.json requests.
5
+ * Responds with the configured web links.
6
+ * @author darthjee
7
+ */
8
+ class LinksRequestHandler extends RequestHandler {
9
+ #links;
10
+
11
+ /**
12
+ * Creates a new LinksRequestHandler instance.
13
+ * @param {object} [params={}] - Constructor params.
14
+ * @param {Array<object>} [params.links=[]] - Links from web configuration.
15
+ */
16
+ constructor({ links = [] } = {}) {
17
+ super();
18
+ this.#links = links;
19
+ }
20
+
21
+ /**
22
+ * Responds with configured links.
23
+ * @param {object} _req - The Express request object.
24
+ * @param {object} res - The Express response object.
25
+ * @returns {void}
26
+ */
27
+ handle(_req, res) {
28
+ res.json({ links: this.#links.map((link) => link.toJSON()) });
29
+ }
30
+ }
31
+
32
+ export { LinksRequestHandler };
@@ -1,8 +1,8 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import YAML from 'yaml';
3
3
  import { ConfigParser } from './ConfigParser.js';
4
+ import { EnvStringResolver } from '../common/utils/env_resolver/EnvStringResolver.js';
4
5
  import { ConfigurationFileNotFound } from '../exceptions/config/ConfigurationFileNotFound.js';
5
- import { EnvResolver } from '../utils/EnvResolver.js';
6
6
  import { Logger } from '../utils/logging/Logger.js';
7
7
 
8
8
  /**
@@ -55,7 +55,7 @@ class ConfigLoader {
55
55
  * @throws {ConfigurationFileNotFound} If the configuration file is not found at the specified path.
56
56
  */
57
57
  #parseYaml() {
58
- return YAML.parse(EnvResolver.resolveString(this.#yamlContent()));
58
+ return YAML.parse(EnvStringResolver.resolve(this.#yamlContent()));
59
59
  }
60
60
 
61
61
  /**
@@ -73,4 +73,4 @@ class ConfigLoader {
73
73
  }
74
74
  }
75
75
 
76
- export { ConfigLoader };
76
+ export { ConfigLoader };
@@ -1,98 +1 @@
1
- /**
2
- * Base logger that filters log output based on a configurable level threshold.
3
- * Subclasses must implement _output(level, message) to handle the actual output.
4
- * @author darthjee
5
- */
6
- class BaseLogger {
7
- #level;
8
- #suppressed = false;
9
- #levels = { debug: 0, info: 1, warn: 2, error: 3, silent: 4 };
10
-
11
- /**
12
- * Creates a new BaseLogger instance.
13
- * @param {string} [level] - The log level threshold. Defaults to the LOG_LEVEL env var or 'info'.
14
- */
15
- constructor(level) {
16
- this.#level = level ?? process.env.LOG_LEVEL ?? 'info';
17
- }
18
-
19
- /**
20
- * Outputs a message at the given level. Override in subclasses.
21
- * @param {string} _level - The log level.
22
- * @param {string} _message - The message to output.
23
- * @param {object} _attributes - The structured metadata for the log entry.
24
- * @returns {void}
25
- */
26
- _output(_level, _message, _attributes) {}
27
-
28
- /**
29
- * Logs a debug message if the configured level allows it.
30
- * @param {string} message - The message to log.
31
- * @param {object} [attributes={}] - Optional structured metadata.
32
- * @returns {void}
33
- */
34
- debug(message, attributes = {}) {
35
- if (this.#shouldLog('debug')) this._output('debug', message, attributes);
36
- }
37
-
38
- /**
39
- * Logs an info message if the configured level allows it.
40
- * @param {string} message - The message to log.
41
- * @param {object} [attributes={}] - Optional structured metadata.
42
- * @returns {void}
43
- */
44
- info(message, attributes = {}) {
45
- if (this.#shouldLog('info')) this._output('info', message, attributes);
46
- }
47
-
48
- /**
49
- * Logs a warn message if the configured level allows it.
50
- * @param {string} message - The message to log.
51
- * @param {object} [attributes={}] - Optional structured metadata.
52
- * @returns {void}
53
- */
54
- warn(message, attributes = {}) {
55
- if (this.#shouldLog('warn')) this._output('warn', message, attributes);
56
- }
57
-
58
- /**
59
- * Logs an error message if the configured level allows it.
60
- * @param {string} message - The message to log.
61
- * @param {object} [attributes={}] - Optional structured metadata.
62
- * @returns {void}
63
- */
64
- error(message, attributes = {}) {
65
- if (this.#shouldLog('error')) this._output('error', message, attributes);
66
- }
67
-
68
- /**
69
- * Suppresses or restores log output for this instance.
70
- * @param {boolean} [value=true] - When true, all log output is suppressed.
71
- * @returns {void}
72
- */
73
- suppress(value = true) {
74
- this.#suppressed = value;
75
- }
76
-
77
- /**
78
- * Sets the log level threshold for this instance.
79
- * @param {string} level - The new log level ('debug', 'info', 'warn', 'error', 'silent').
80
- * @returns {void}
81
- */
82
- setLevel(level) {
83
- if (!(level in this.#levels)) {
84
- throw new Error(`Invalid log level: "${level}". Must be one of: ${Object.keys(this.#levels).join(', ')}.`);
85
- }
86
- this.#level = level;
87
- }
88
-
89
- /**
90
- * @param {string} level - The log level to check.
91
- * @returns {boolean} True if the message should be logged at the given level.
92
- */
93
- #shouldLog(level) {
94
- return !this.#suppressed && this.#levels[level] >= this.#levels[this.#level];
95
- }
96
- }
97
-
98
- export { BaseLogger };
1
+ export * from '../../common/utils/logging/BaseLogger.js';
@@ -1,100 +1 @@
1
- import { BaseLogger } from './BaseLogger.js';
2
- import { LogBuffer } from './LogBuffer.js';
3
-
4
- /**
5
- * BufferedLogger extends BaseLogger by maintaining a history of log messages.
6
- * Useful for displaying logs in a web interface or debugging.
7
- * @author darthjee
8
- */
9
- class BufferedLogger extends BaseLogger {
10
- #buffer;
11
-
12
- /**
13
- * Creates a new BufferedLogger instance.
14
- * @param {string} [level] - The log level threshold.
15
- * @param {number} [retention=100] - Maximum number of logs to retain in buffer.
16
- */
17
- constructor(level, retention = 100) {
18
- super(level);
19
- this.#buffer = new LogBuffer(retention);
20
- }
21
-
22
- /**
23
- * Stores the message in the buffer.
24
- * @param {string} level - The log level ('debug', 'info', 'warn', 'error').
25
- * @param {string} message - The message to output.
26
- * @param {object} [attributes={}] - Optional structured metadata for the log entry.
27
- * @returns {void}
28
- */
29
- _output(level, message, attributes = {}) {
30
- this.#buffer.add(level, message, attributes);
31
- }
32
-
33
- /**
34
- * Returns the most recently added log, or undefined if the buffer is empty.
35
- * @returns {import('./Log.js').Log|undefined} The most recently added log entry, or undefined.
36
- */
37
- get latestLog() {
38
- return this.#buffer.latestLog;
39
- }
40
-
41
- /**
42
- * Gets all logs from the buffer.
43
- * @returns {Array<import('./Log.js').Log>} Array of log entries.
44
- */
45
- getLogs() {
46
- return this.#buffer.getLogs();
47
- }
48
-
49
- /**
50
- * Gets a specific log by ID.
51
- * @param {number} id - The log ID to find.
52
- * @returns {import('./Log.js').Log|undefined} The log entry or undefined if not found.
53
- */
54
- getLogById(id) {
55
- return this.#buffer.getLogById(id);
56
- }
57
-
58
- /**
59
- * Gets logs filtered by level.
60
- * @param {string} level - The log level to filter by.
61
- * @returns {Array<import('./Log.js').Log>} Array of log entries matching the level.
62
- */
63
- getLogsByLevel(level) {
64
- return this.#buffer.getLogsByLevel(level);
65
- }
66
-
67
- /**
68
- * Clears all logs from the buffer.
69
- * @returns {void}
70
- */
71
- clearLogs() {
72
- this.#buffer.clear();
73
- }
74
-
75
- /**
76
- * Gets the current number of logs in the buffer.
77
- * @returns {number} The number of logs.
78
- */
79
- get bufferSize() {
80
- return this.#buffer.size;
81
- }
82
-
83
- /**
84
- * Gets the retention limit.
85
- * @returns {number} The maximum number of logs to retain.
86
- */
87
- get retention() {
88
- return this.#buffer.retention;
89
- }
90
-
91
- /**
92
- * Converts all logs to JSON array.
93
- * @returns {Array<object>} Array of log objects.
94
- */
95
- getLogsJSON() {
96
- return this.#buffer.toJSON();
97
- }
98
- }
99
-
100
- export { BufferedLogger };
1
+ export * from '../../common/utils/logging/BufferedLogger.js';
@@ -1,20 +1 @@
1
- import { BaseLogger } from './BaseLogger.js';
2
-
3
- /**
4
- * Logger that writes output to the browser/Node.js console.
5
- * @author darthjee
6
- */
7
- class ConsoleLogger extends BaseLogger {
8
- /**
9
- * Writes a message to the console at the given level.
10
- * @param {string} level - One of 'debug', 'info', 'warn', 'error'.
11
- * @param {string} message - The message to output.
12
- * @param {object} [attributes={}] - Optional structured metadata to output alongside the message.
13
- * @returns {void}
14
- */
15
- _output(level, message, attributes = {}) {
16
- console[level](message, attributes); // eslint-disable-line no-console
17
- }
18
- }
19
-
20
- export { ConsoleLogger };
1
+ export * from '../../common/utils/logging/ConsoleLogger.js';
@@ -1,82 +1 @@
1
- /**
2
- * Represents a single log entry with id, level, message, attributes and timestamp.
3
- * @author darthjee
4
- */
5
- class Log {
6
- #id;
7
- #level;
8
- #message;
9
- #attributes;
10
- #timestamp;
11
-
12
- /**
13
- * Creates a new Log instance.
14
- * @param {number} id - Unique incremental identifier for this log.
15
- * @param {string} level - The log level (debug, info, warn, error).
16
- * @param {string} message - The log message.
17
- * @param {object} [attributes={}] - Optional structured metadata for the log entry.
18
- */
19
- constructor(id, level, message, attributes = {}) {
20
- this.#id = id;
21
- this.#level = level;
22
- this.#message = message;
23
- this.#attributes = attributes;
24
- this.#timestamp = new Date();
25
- }
26
-
27
- /**
28
- * Gets the log ID.
29
- * @returns {number} The log ID.
30
- */
31
- get id() {
32
- return this.#id;
33
- }
34
-
35
- /**
36
- * Gets the log level.
37
- * @returns {string} The log level.
38
- */
39
- get level() {
40
- return this.#level;
41
- }
42
-
43
- /**
44
- * Gets the log message.
45
- * @returns {string} The log message.
46
- */
47
- get message() {
48
- return this.#message;
49
- }
50
-
51
- /**
52
- * Gets the log attributes.
53
- * @returns {object} The structured metadata attached to this log entry.
54
- */
55
- get attributes() {
56
- return this.#attributes;
57
- }
58
-
59
- /**
60
- * Gets the log timestamp.
61
- * @returns {Date} The timestamp when the log was created.
62
- */
63
- get timestamp() {
64
- return this.#timestamp;
65
- }
66
-
67
- /**
68
- * Converts the log to a plain object.
69
- * @returns {object} Plain object representation of the log.
70
- */
71
- toJSON() {
72
- return {
73
- id: this.#id,
74
- level: this.#level,
75
- message: this.#message,
76
- attributes: this.#attributes,
77
- timestamp: this.#timestamp.toISOString()
78
- };
79
- }
80
- }
81
-
82
- export { Log };
1
+ export * from '../../common/utils/logging/Log.js';