@chronicle.app/logging 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrew Louis
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,22 @@
1
+ # @chronicle.app/logging
2
+
3
+ Shared stderr logger for Chronicle. Node.js 22.13+; ESM with TypeScript declarations.
4
+
5
+ ```js
6
+ import { createLogger } from '@chronicle.app/logging';
7
+
8
+ const logger = createLogger({ prefix: '[extract]', verbose: true });
9
+ logger.info('Extracted records', { count: 3 });
10
+ logger.debug('Source cursor', { position: 3 });
11
+ ```
12
+
13
+ All output goes to stderr so stdout stays available for extracted data. `quiet`
14
+ suppresses everything except errors. Debug messages require `verbose`; `level`
15
+ filters info/warn output. `verboseInfo` requires verbose and non-quiet mode. Errors
16
+ always print. Context can be rendered inline or with `debugMultiline`. A custom
17
+ `theme` supplies functions for each level; default colors are disabled for pipes.
18
+
19
+ `npm run build -w @chronicle.app/logging` builds the package; `npm test -w
20
+ @chronicle.app/logging` exercises its public API after a build.
21
+
22
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,3 @@
1
+ import { LoggerTheme } from './types.js';
2
+ export declare const defaultTheme: LoggerTheme;
3
+ //# sourceMappingURL=DefaultTheme.d.ts.map
@@ -0,0 +1,8 @@
1
+ import chalk from 'chalk';
2
+ // Enhanced theme with colored icons/timestamps only
3
+ export const defaultTheme = {
4
+ debug: msg => `${chalk.gray('⚪')} ${msg}`,
5
+ info: msg => `${chalk.blue('ℹ')} ${msg}`,
6
+ warn: msg => `${chalk.yellow('⚠')} ${msg}`,
7
+ error: msg => `${chalk.red('✖')} ${msg}`,
8
+ };
@@ -0,0 +1,20 @@
1
+ import { LoggerOptions, LoggerContext } from './types.js';
2
+ export declare class Logger {
3
+ private prefix;
4
+ private level;
5
+ private quiet;
6
+ private verbose;
7
+ private theme;
8
+ constructor(options?: LoggerOptions);
9
+ private shouldLog;
10
+ private formatPrefix;
11
+ private formatMessage;
12
+ private formatCompactJson;
13
+ debug(message: string, context?: LoggerContext): void;
14
+ debugMultiline(message: string, context?: LoggerContext): void;
15
+ info(message: string, context?: LoggerContext): void;
16
+ verboseInfo(message: string, context?: LoggerContext): void;
17
+ warn(message: string, context?: LoggerContext): void;
18
+ error(message: string, context?: LoggerContext): void;
19
+ }
20
+ //# sourceMappingURL=Logger.d.ts.map
package/dist/Logger.js ADDED
@@ -0,0 +1,112 @@
1
+ import { defaultTheme } from './DefaultTheme.js';
2
+ import chalk from 'chalk';
3
+ const LOG_LEVELS = {
4
+ debug: 0,
5
+ info: 1,
6
+ warn: 2,
7
+ error: 3,
8
+ };
9
+ export class Logger {
10
+ prefix;
11
+ level;
12
+ quiet;
13
+ verbose;
14
+ theme;
15
+ constructor(options = {}) {
16
+ this.prefix = options.prefix ? `${options.prefix} ` : '';
17
+ this.level = options.level ?? 'info';
18
+ this.quiet = options.quiet ?? false;
19
+ this.verbose = options.verbose ?? false;
20
+ this.theme = options.theme ?? defaultTheme;
21
+ // Only enable colors when writing to a real terminal (not when PM2 captures stderr)
22
+ if (process.stderr.isTTY) {
23
+ chalk.level = 3; // Force full color support for terminals
24
+ }
25
+ else {
26
+ chalk.level = 0; // Disable colors for file/pipe output
27
+ }
28
+ }
29
+ shouldLog(level) {
30
+ if (level === 'error')
31
+ return true; // Always show errors
32
+ if (this.quiet)
33
+ return false;
34
+ if (level === 'debug')
35
+ return this.verbose; // Debug messages only in verbose mode
36
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
37
+ }
38
+ formatPrefix(serviceName) {
39
+ // Extract service name from prefix like '[ServiceName]' or just use as-is
40
+ const match = serviceName.match(/\[([^\]]+)\]/);
41
+ const name = match ? match[1] : serviceName.replaceAll(/^\s*|\s*$/g, '');
42
+ // Fixed width of 25 characters, left-aligned
43
+ return name.padEnd(25);
44
+ }
45
+ formatMessage(message, context, multiline = false) {
46
+ const service = this.prefix ? this.formatPrefix(this.prefix) : ''.padEnd(25);
47
+ let formatted = `${service} ${message}`;
48
+ if (context && Object.keys(context).length > 0) {
49
+ if (multiline) {
50
+ // Custom JSON formatting: compact arrays, multiline objects
51
+ const compactJson = this.formatCompactJson(context);
52
+ formatted += `\n${compactJson}`;
53
+ }
54
+ else {
55
+ formatted += ` ${JSON.stringify(context)}`;
56
+ }
57
+ }
58
+ return formatted;
59
+ }
60
+ formatCompactJson(obj, depth = 0) {
61
+ const indent = ' '.repeat(depth);
62
+ const nextIndent = ' '.repeat(depth + 1);
63
+ if (Array.isArray(obj)) {
64
+ // Keep arrays on single line for compactness
65
+ return JSON.stringify(obj);
66
+ }
67
+ if (obj && typeof obj === 'object') {
68
+ const entries = Object.entries(obj);
69
+ if (entries.length === 0)
70
+ return '{}';
71
+ const formatted = entries
72
+ .map(([key, value]) => `${nextIndent}"${key}": ${this.formatCompactJson(value, depth + 1)}`)
73
+ .join(',\n');
74
+ return `{\n${formatted}\n${indent}}`;
75
+ }
76
+ return JSON.stringify(obj);
77
+ }
78
+ debug(message, context) {
79
+ if (this.shouldLog('debug')) {
80
+ const formatted = this.formatMessage(message, context);
81
+ process.stderr.write(`${this.theme.debug(formatted)}\n`);
82
+ }
83
+ }
84
+ debugMultiline(message, context) {
85
+ if (this.shouldLog('debug')) {
86
+ const formatted = this.formatMessage(message, context, true);
87
+ process.stderr.write(`${this.theme.debug(formatted)}\n`);
88
+ }
89
+ }
90
+ info(message, context) {
91
+ if (this.shouldLog('info')) {
92
+ const formatted = this.formatMessage(message, context);
93
+ process.stderr.write(`${this.theme.info(formatted)}\n`);
94
+ }
95
+ }
96
+ verboseInfo(message, context) {
97
+ if (!this.quiet && this.verbose) {
98
+ const formatted = this.formatMessage(message, context);
99
+ process.stderr.write(`${this.theme.info(formatted)}\n`);
100
+ }
101
+ }
102
+ warn(message, context) {
103
+ if (this.shouldLog('warn')) {
104
+ const formatted = this.formatMessage(message, context);
105
+ process.stderr.write(`${this.theme.warn(formatted)}\n`);
106
+ }
107
+ }
108
+ error(message, context) {
109
+ const formatted = this.formatMessage(message, context);
110
+ process.stderr.write(`${this.theme.error(formatted)}\n`);
111
+ }
112
+ }
@@ -0,0 +1,10 @@
1
+ export { Logger } from './Logger.js';
2
+ export { defaultTheme } from './DefaultTheme.js';
3
+ export type { LoggerTheme, LoggerOptions, LogLevel, LoggerContext } from './types.js';
4
+ import { Logger } from './Logger.js';
5
+ import { LoggerOptions } from './types.js';
6
+ /**
7
+ * Factory function to create a logger instance
8
+ */
9
+ export declare function createLogger(options?: LoggerOptions): Logger;
10
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { Logger } from './Logger.js';
2
+ export { defaultTheme } from './DefaultTheme.js';
3
+ import { Logger } from './Logger.js';
4
+ /**
5
+ * Factory function to create a logger instance
6
+ */
7
+ export function createLogger(options = {}) {
8
+ return new Logger(options);
9
+ }
@@ -0,0 +1,18 @@
1
+ export interface LoggerTheme {
2
+ info: (message: string) => string;
3
+ warn: (message: string) => string;
4
+ error: (message: string) => string;
5
+ debug: (message: string) => string;
6
+ }
7
+ export interface LoggerOptions {
8
+ prefix?: string;
9
+ level?: LogLevel;
10
+ theme?: LoggerTheme;
11
+ quiet?: boolean;
12
+ verbose?: boolean;
13
+ }
14
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
15
+ export interface LoggerContext {
16
+ [key: string]: any;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@chronicle.app/logging",
3
+ "version": "0.1.0",
4
+ "main": "./dist/index.js",
5
+ "types": "./dist/index.d.ts",
6
+ "files": [
7
+ "dist/*.js",
8
+ "dist/*.d.ts"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc -b tsconfig.lib.json",
12
+ "typecheck": "tsc -p tsconfig.json",
13
+ "lint": "eslint src --ext .ts,.js",
14
+ "test": "node --test src/*.test.js"
15
+ },
16
+ "keywords": [],
17
+ "author": "Andrew Louis",
18
+ "license": "MIT",
19
+ "type": "module",
20
+ "description": "Chronicle shared logging utilities",
21
+ "homepage": "https://chronicle.app",
22
+ "bugs": {
23
+ "url": "https://github.com/chronicle-app/chronicle/issues/new?labels=core:logging&title=[logging]%20"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/chronicle-app/chronicle.git",
28
+ "directory": "core/logging"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://registry.npmjs.org/"
33
+ },
34
+ "dependencies": {
35
+ "chalk": "^4.1.2"
36
+ },
37
+ "engines": {
38
+ "node": ">=22.13.0"
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.js"
44
+ }
45
+ },
46
+ "devDependencies": {
47
+ "@chronicle.app/tsconfig": "0.1.0",
48
+ "@types/node": "^22.10.1",
49
+ "typescript": "^5.7.2"
50
+ }
51
+ }