@mcphero/logger 1.1.6
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/.turbo/turbo-build.log +17 -0
- package/.turbo/turbo-check.log +12 -0
- package/.turbo/turbo-prepack.log +26 -0
- package/build/index.d.ts +28 -0
- package/build/index.js +84 -0
- package/build/index.js.map +1 -0
- package/eslint.config.mjs +99 -0
- package/package.json +36 -0
- package/src/cli.ts +19 -0
- package/src/index.ts +3 -0
- package/src/logger.ts +57 -0
- package/src/types.ts +21 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
> @mcphero/logger@1.1.6 build /Users/atomic/projects/ai/mcphero/packages/logger
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
CLI Building entry: src/index.ts
|
|
6
|
+
CLI Using tsconfig: tsconfig.json
|
|
7
|
+
CLI tsup v8.5.1
|
|
8
|
+
CLI Using tsup config: /Users/atomic/projects/ai/mcphero/packages/logger/tsup.config.ts
|
|
9
|
+
CLI Target: node18
|
|
10
|
+
CLI Cleaning output folder
|
|
11
|
+
ESM Build start
|
|
12
|
+
ESM build/index.js 2.10 KB
|
|
13
|
+
ESM build/index.js.map 4.77 KB
|
|
14
|
+
ESM ⚡️ Build success in 5ms
|
|
15
|
+
DTS Build start
|
|
16
|
+
DTS ⚡️ Build success in 376ms
|
|
17
|
+
DTS build/index.d.ts 1.04 KB
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
> @mcphero/logger@1.1.6 check /Users/atomic/projects/ai/mcphero/packages/logger
|
|
3
|
+
> pnpm lint && pnpm typecheck
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> @mcphero/logger@1.1.6 lint /Users/atomic/projects/ai/mcphero/packages/logger
|
|
7
|
+
> eslint
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
> @mcphero/logger@1.1.6 typecheck /Users/atomic/projects/ai/mcphero/packages/logger
|
|
11
|
+
> tsc --noEmit
|
|
12
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @mcphero/logger@1.1.6 prepack /Users/atomic/projects/ai/mcphero/packages/logger
|
|
4
|
+
> pnpm clean && pnpm build
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
> @mcphero/logger@1.1.6 clean /Users/atomic/projects/ai/mcphero/packages/logger
|
|
8
|
+
> rimraf build
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
> @mcphero/logger@1.1.6 build /Users/atomic/projects/ai/mcphero/packages/logger
|
|
12
|
+
> tsup
|
|
13
|
+
|
|
14
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
15
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
16
|
+
[34mCLI[39m tsup v8.5.1
|
|
17
|
+
[34mCLI[39m Using tsup config: /Users/atomic/projects/ai/mcphero/packages/logger/tsup.config.ts
|
|
18
|
+
[34mCLI[39m Target: node18
|
|
19
|
+
[34mCLI[39m Cleaning output folder
|
|
20
|
+
[34mESM[39m Build start
|
|
21
|
+
[32mESM[39m [1mbuild/index.js [22m[32m2.10 KB[39m
|
|
22
|
+
[32mESM[39m [1mbuild/index.js.map [22m[32m4.77 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 6ms
|
|
24
|
+
DTS Build start
|
|
25
|
+
DTS ⚡️ Build success in 408ms
|
|
26
|
+
DTS build/index.d.ts 1.04 KB
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface MessageOptions {
|
|
2
|
+
message: string;
|
|
3
|
+
}
|
|
4
|
+
interface ProgressOptions {
|
|
5
|
+
progress: number;
|
|
6
|
+
total?: number;
|
|
7
|
+
message?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const LogLevels: readonly ["error", "debug", "info", "notice", "warning", "critical", "alert", "emergency"];
|
|
10
|
+
type LogLevel = typeof LogLevels[number];
|
|
11
|
+
type LogFn = (data: unknown) => void;
|
|
12
|
+
interface Logger extends Record<LogLevel, LogFn> {
|
|
13
|
+
progress: (options: ProgressOptions) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface CreateLoggerOptions {
|
|
17
|
+
name?: string;
|
|
18
|
+
level?: string;
|
|
19
|
+
stream?: NodeJS.WritableStream | false;
|
|
20
|
+
onLog?: (level: LogLevel, data: unknown) => void;
|
|
21
|
+
onProgress?: (options: ProgressOptions) => void;
|
|
22
|
+
}
|
|
23
|
+
declare function createLogger(options?: CreateLoggerOptions): Logger;
|
|
24
|
+
declare function buildLogLevels(fn: (level: LogLevel, data: unknown) => void): Record<LogLevel, LogFn>;
|
|
25
|
+
|
|
26
|
+
declare function createCLILogger(): Logger;
|
|
27
|
+
|
|
28
|
+
export { type CreateLoggerOptions, type LogFn, type LogLevel, LogLevels, type Logger, type MessageOptions, type ProgressOptions, buildLogLevels, createCLILogger, createLogger };
|
package/build/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var LogLevels = ["error", "debug", "info", "notice", "warning", "critical", "alert", "emergency"];
|
|
3
|
+
|
|
4
|
+
// src/logger.ts
|
|
5
|
+
import pino from "pino";
|
|
6
|
+
var PINO_LEVEL_MAP = {
|
|
7
|
+
emergency: "fatal",
|
|
8
|
+
alert: "fatal",
|
|
9
|
+
critical: "fatal",
|
|
10
|
+
error: "error",
|
|
11
|
+
warning: "warn",
|
|
12
|
+
notice: "info",
|
|
13
|
+
info: "info",
|
|
14
|
+
debug: "debug"
|
|
15
|
+
};
|
|
16
|
+
function createLogger(options = {}) {
|
|
17
|
+
const { name, level = "debug", stream, onLog, onProgress } = options;
|
|
18
|
+
const pinoOptions = { name, level };
|
|
19
|
+
const instance = stream === false ? pino(pinoOptions, pino.destination("/dev/null")) : stream ? pino(pinoOptions, stream) : pino(pinoOptions);
|
|
20
|
+
const logLevels = Object.fromEntries(LogLevels.map((logLevel) => {
|
|
21
|
+
const pinoLevel = PINO_LEVEL_MAP[logLevel];
|
|
22
|
+
return [logLevel, (data) => {
|
|
23
|
+
instance[pinoLevel](data);
|
|
24
|
+
onLog?.(logLevel, data);
|
|
25
|
+
}];
|
|
26
|
+
}));
|
|
27
|
+
return {
|
|
28
|
+
...logLevels,
|
|
29
|
+
progress: (progressOptions) => {
|
|
30
|
+
if (onProgress) {
|
|
31
|
+
onProgress(progressOptions);
|
|
32
|
+
} else {
|
|
33
|
+
instance.info({ ...progressOptions }, progressOptions.message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function buildLogLevels(fn) {
|
|
39
|
+
return Object.fromEntries(LogLevels.map((level) => [level, (data) => {
|
|
40
|
+
fn(level, data);
|
|
41
|
+
}]));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/cli.ts
|
|
45
|
+
import { log } from "@clack/prompts";
|
|
46
|
+
function createCLILogger() {
|
|
47
|
+
const toString = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
48
|
+
return {
|
|
49
|
+
error: (data) => {
|
|
50
|
+
log.error(toString(data));
|
|
51
|
+
},
|
|
52
|
+
debug: (data) => {
|
|
53
|
+
log.message(toString(data));
|
|
54
|
+
},
|
|
55
|
+
info: (data) => {
|
|
56
|
+
log.info(toString(data));
|
|
57
|
+
},
|
|
58
|
+
notice: (data) => {
|
|
59
|
+
log.message(toString(data));
|
|
60
|
+
},
|
|
61
|
+
warning: (data) => {
|
|
62
|
+
log.warn(toString(data));
|
|
63
|
+
},
|
|
64
|
+
critical: (data) => {
|
|
65
|
+
log.error(toString(data));
|
|
66
|
+
},
|
|
67
|
+
alert: (data) => {
|
|
68
|
+
log.error(toString(data));
|
|
69
|
+
},
|
|
70
|
+
emergency: (data) => {
|
|
71
|
+
log.error(toString(data));
|
|
72
|
+
},
|
|
73
|
+
progress: ({ progress, total, message }) => {
|
|
74
|
+
log.info(toString({ progress, total, message }));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
LogLevels,
|
|
80
|
+
buildLogLevels,
|
|
81
|
+
createCLILogger,
|
|
82
|
+
createLogger
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/logger.ts","../src/cli.ts"],"sourcesContent":["export interface MessageOptions {\n message: string\n}\n\nexport interface ProgressOptions {\n progress: number\n total?: number\n message?: string\n}\n\nconst LogLevels = ['error', 'debug', 'info', 'notice', 'warning', 'critical', 'alert', 'emergency'] as const\n\nexport type LogLevel = typeof LogLevels[number]\n\nexport type LogFn = (data: unknown) => void\n\nexport interface Logger extends Record<LogLevel, LogFn> {\n progress: (options: ProgressOptions) => void\n}\n\nexport { LogLevels }\n","import pino from 'pino'\nimport { Logger, LogFn, LogLevel, LogLevels, ProgressOptions } from './types.js'\n\ntype PinoLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace'\n\nconst PINO_LEVEL_MAP: Record<LogLevel, PinoLevel> = {\n emergency: 'fatal',\n alert: 'fatal',\n critical: 'fatal',\n error: 'error',\n warning: 'warn',\n notice: 'info',\n info: 'info',\n debug: 'debug'\n}\n\nexport interface CreateLoggerOptions {\n name?: string\n level?: string\n stream?: NodeJS.WritableStream | false\n onLog?: (level: LogLevel, data: unknown) => void\n onProgress?: (options: ProgressOptions) => void\n}\n\nexport function createLogger(options: CreateLoggerOptions = {}): Logger {\n const { name, level = 'debug', stream, onLog, onProgress } = options\n\n const pinoOptions: pino.LoggerOptions = { name, level }\n const instance = stream === false\n ? pino(pinoOptions, pino.destination('/dev/null'))\n : stream\n ? pino(pinoOptions, stream)\n : pino(pinoOptions)\n\n const logLevels = Object.fromEntries(LogLevels.map((logLevel) => {\n const pinoLevel = PINO_LEVEL_MAP[logLevel]\n return [logLevel, (data: unknown) => {\n instance[pinoLevel](data)\n onLog?.(logLevel, data)\n }]\n })) as Record<LogLevel, LogFn>\n\n return {\n ...logLevels,\n progress: (progressOptions) => {\n if (onProgress) {\n onProgress(progressOptions)\n } else {\n instance.info({ ...progressOptions }, progressOptions.message)\n }\n }\n }\n}\n\nexport function buildLogLevels(fn: (level: LogLevel, data: unknown) => void): Record<LogLevel, LogFn> {\n return Object.fromEntries(LogLevels.map((level) => [level, (data: unknown) => { fn(level, data) }])) as Record<LogLevel, LogFn>\n}\n","import { log } from '@clack/prompts'\nimport { Logger } from './types.js'\n\nexport function createCLILogger(): Logger {\n const toString = (value: unknown) => typeof value === 'string' ? value : JSON.stringify(value)\n return {\n error: (data) => { log.error(toString(data)) },\n debug: (data) => { log.message(toString(data)) },\n info: (data) => { log.info(toString(data)) },\n notice: (data) => { log.message(toString(data)) },\n warning: (data) => { log.warn(toString(data)) },\n critical: (data) => { log.error(toString(data)) },\n alert: (data) => { log.error(toString(data)) },\n emergency: (data) => { log.error(toString(data)) },\n progress: ({ progress, total, message }) => {\n log.info(toString({ progress, total, message }))\n }\n }\n}\n"],"mappings":";AAUA,IAAM,YAAY,CAAC,SAAS,SAAS,QAAQ,UAAU,WAAW,YAAY,SAAS,WAAW;;;ACVlG,OAAO,UAAU;AAKjB,IAAM,iBAA8C;AAAA,EAClD,WAAW;AAAA,EACX,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AACT;AAUO,SAAS,aAAa,UAA+B,CAAC,GAAW;AACtE,QAAM,EAAE,MAAM,QAAQ,SAAS,QAAQ,OAAO,WAAW,IAAI;AAE7D,QAAM,cAAkC,EAAE,MAAM,MAAM;AACtD,QAAM,WAAW,WAAW,QACxB,KAAK,aAAa,KAAK,YAAY,WAAW,CAAC,IAC/C,SACE,KAAK,aAAa,MAAM,IACxB,KAAK,WAAW;AAEtB,QAAM,YAAY,OAAO,YAAY,UAAU,IAAI,CAAC,aAAa;AAC/D,UAAM,YAAY,eAAe,QAAQ;AACzC,WAAO,CAAC,UAAU,CAAC,SAAkB;AACnC,eAAS,SAAS,EAAE,IAAI;AACxB,cAAQ,UAAU,IAAI;AAAA,IACxB,CAAC;AAAA,EACH,CAAC,CAAC;AAEF,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,CAAC,oBAAoB;AAC7B,UAAI,YAAY;AACd,mBAAW,eAAe;AAAA,MAC5B,OAAO;AACL,iBAAS,KAAK,EAAE,GAAG,gBAAgB,GAAG,gBAAgB,OAAO;AAAA,MAC/D;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,eAAe,IAAuE;AACpG,SAAO,OAAO,YAAY,UAAU,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAkB;AAAE,OAAG,OAAO,IAAI;AAAA,EAAE,CAAC,CAAC,CAAC;AACrG;;;ACxDA,SAAS,WAAW;AAGb,SAAS,kBAA0B;AACxC,QAAM,WAAW,CAAC,UAAmB,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AAC7F,SAAO;AAAA,IACL,OAAO,CAAC,SAAS;AAAE,UAAI,MAAM,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAC7C,OAAO,CAAC,SAAS;AAAE,UAAI,QAAQ,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAC/C,MAAM,CAAC,SAAS;AAAE,UAAI,KAAK,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAC3C,QAAQ,CAAC,SAAS;AAAE,UAAI,QAAQ,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAChD,SAAS,CAAC,SAAS;AAAE,UAAI,KAAK,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAC9C,UAAU,CAAC,SAAS;AAAE,UAAI,MAAM,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAChD,OAAO,CAAC,SAAS;AAAE,UAAI,MAAM,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IAC7C,WAAW,CAAC,SAAS;AAAE,UAAI,MAAM,SAAS,IAAI,CAAC;AAAA,IAAE;AAAA,IACjD,UAAU,CAAC,EAAE,UAAU,OAAO,QAAQ,MAAM;AAC1C,UAAI,KAAK,SAAS,EAAE,UAAU,OAAO,QAAQ,CAAC,CAAC;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import eslint from '@eslint/js'
|
|
2
|
+
import stylistic from '@stylistic/eslint-plugin'
|
|
3
|
+
import { defineConfig } from 'eslint/config'
|
|
4
|
+
import tseslint from 'typescript-eslint'
|
|
5
|
+
|
|
6
|
+
export default defineConfig(eslint.configs.recommended, tseslint.configs.recommendedTypeChecked, tseslint.configs.stylisticTypeChecked, {
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parserOptions: {
|
|
9
|
+
project: 'tsconfig.json',
|
|
10
|
+
tsconfigRootDir: import.meta.dirname
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
plugins: { '@stylistic': stylistic },
|
|
14
|
+
rules: {
|
|
15
|
+
'@stylistic/space-in-parens': ['error'],
|
|
16
|
+
'@stylistic/comma-spacing': ['error'],
|
|
17
|
+
'@stylistic/no-multi-spaces': ['error'],
|
|
18
|
+
'@stylistic/no-trailing-spaces': ['error'],
|
|
19
|
+
'@stylistic/no-whitespace-before-property': ['error'],
|
|
20
|
+
'@stylistic/array-bracket-newline': ['error', 'consistent'],
|
|
21
|
+
'@stylistic/array-bracket-spacing': ['error'],
|
|
22
|
+
'@stylistic/arrow-spacing': ['error'],
|
|
23
|
+
'@stylistic/arrow-parens': ['error', 'always'],
|
|
24
|
+
'@stylistic/block-spacing': ['error', 'always'],
|
|
25
|
+
'@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
|
|
26
|
+
'@stylistic/comma-dangle': ['error', 'never'],
|
|
27
|
+
'@stylistic/key-spacing': ['error'],
|
|
28
|
+
'@stylistic/keyword-spacing': ['error'],
|
|
29
|
+
'@stylistic/member-delimiter-style': ['error', { 'multiline': { 'delimiter': 'none' } }],
|
|
30
|
+
'@stylistic/no-extra-semi': ['error'],
|
|
31
|
+
'@stylistic/indent': ['error', 2],
|
|
32
|
+
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0, 'maxBOF': 0 }],
|
|
33
|
+
'@stylistic/object-curly-spacing': ['error', 'always'],
|
|
34
|
+
'@stylistic/quotes': ['error', 'single'],
|
|
35
|
+
'@stylistic/semi': ['error', 'never'],
|
|
36
|
+
'@stylistic/space-before-blocks': ['error', 'always'],
|
|
37
|
+
'@stylistic/space-before-function-paren': ['error', { 'anonymous': 'always', 'named': 'never', 'asyncArrow': 'always' }],
|
|
38
|
+
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
|
39
|
+
'@typescript-eslint/array-type': 'off',
|
|
40
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
41
|
+
'@typescript-eslint/ban-types': 'off',
|
|
42
|
+
'@typescript-eslint/consistent-type-assertions': 'off',
|
|
43
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
44
|
+
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
45
|
+
'@typescript-eslint/no-angle-bracket-type-assertion': 'off',
|
|
46
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
47
|
+
'@typescript-eslint/no-empty-interface': 'off',
|
|
48
|
+
'@typescript-eslint/no-extra-non-null-assertion': 'error',
|
|
49
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
|
50
|
+
'@typescript-eslint/no-misused-new': 'error',
|
|
51
|
+
'@typescript-eslint/no-misused-promises': 'off',
|
|
52
|
+
'@typescript-eslint/no-namespace': 'off',
|
|
53
|
+
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
|
54
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
55
|
+
'@typescript-eslint/no-object-literal-type-assertion': 'off',
|
|
56
|
+
'@typescript-eslint/no-parameter-properties': 'off',
|
|
57
|
+
'@typescript-eslint/no-shadow': 'error',
|
|
58
|
+
'@typescript-eslint/no-triple-slash-reference': 'off',
|
|
59
|
+
'@typescript-eslint/no-unused-vars': ['error', {
|
|
60
|
+
'args': 'all',
|
|
61
|
+
'argsIgnorePattern': '^_',
|
|
62
|
+
'caughtErrors': 'all',
|
|
63
|
+
'caughtErrorsIgnorePattern': '^_',
|
|
64
|
+
'destructuredArrayIgnorePattern': '^_',
|
|
65
|
+
'varsIgnorePattern': '^_',
|
|
66
|
+
'ignoreRestSiblings': true
|
|
67
|
+
}],
|
|
68
|
+
'@typescript-eslint/no-use-before-define': 'off',
|
|
69
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
70
|
+
'@typescript-eslint/prefer-for-of': 'error',
|
|
71
|
+
'@typescript-eslint/prefer-interface': 'off',
|
|
72
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
|
73
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
74
|
+
'@typescript-eslint/return-await': 'error',
|
|
75
|
+
'@typescript-eslint/unified-signatures': 'error',
|
|
76
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
77
|
+
'@typescript-eslint/no-redundant-type-constituents': 'off',
|
|
78
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
79
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
80
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
81
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
82
|
+
'@typescript-eslint/dot-notation': 'off',
|
|
83
|
+
'@typescript-eslint/prefer-regexp-exec': 'off',
|
|
84
|
+
'@typescript-eslint/require-await': 'off',
|
|
85
|
+
'@typescript-eslint/only-throw-error': ['error', {
|
|
86
|
+
'allow': [
|
|
87
|
+
{ from: 'package', name: 'TypedResponse', package: '@remix-run/server-runtime' },
|
|
88
|
+
{ from: 'lib', name: 'Response' }
|
|
89
|
+
]
|
|
90
|
+
}],
|
|
91
|
+
'@typescript-eslint/no-base-to-string': 'off',
|
|
92
|
+
'@typescript-eslint/restrict-template-expressions': 'off'
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
files: ['eslint.config.mjs'],
|
|
96
|
+
extends: [tseslint.configs.disableTypeChecked]
|
|
97
|
+
}, {
|
|
98
|
+
ignores: ['build', 'tsup.config.ts']
|
|
99
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcphero/logger",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "MCP Hero Logger",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+ssh://git@github.com/atomicbi/mcphero.git",
|
|
8
|
+
"directory": "packages/logger"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "build/index.js",
|
|
12
|
+
"types": "build/index.d.ts",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@clack/prompts": "^1.0.1",
|
|
15
|
+
"pino": "^9.6.0",
|
|
16
|
+
"zod": "^4.3.6"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@eslint/js": "^10.0.1",
|
|
20
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
21
|
+
"@types/node": "^22.0.0",
|
|
22
|
+
"rimraf": "^6.1.3",
|
|
23
|
+
"tsup": "^8.5.1",
|
|
24
|
+
"tsx": "^4.21.0",
|
|
25
|
+
"typescript": "^5.9.3",
|
|
26
|
+
"typescript-eslint": "^8.56.1"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "rimraf build",
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"watch": "tsup --watch",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"lint": "eslint",
|
|
34
|
+
"check": "pnpm lint && pnpm typecheck"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { log } from '@clack/prompts'
|
|
2
|
+
import { Logger } from './types.js'
|
|
3
|
+
|
|
4
|
+
export function createCLILogger(): Logger {
|
|
5
|
+
const toString = (value: unknown) => typeof value === 'string' ? value : JSON.stringify(value)
|
|
6
|
+
return {
|
|
7
|
+
error: (data) => { log.error(toString(data)) },
|
|
8
|
+
debug: (data) => { log.message(toString(data)) },
|
|
9
|
+
info: (data) => { log.info(toString(data)) },
|
|
10
|
+
notice: (data) => { log.message(toString(data)) },
|
|
11
|
+
warning: (data) => { log.warn(toString(data)) },
|
|
12
|
+
critical: (data) => { log.error(toString(data)) },
|
|
13
|
+
alert: (data) => { log.error(toString(data)) },
|
|
14
|
+
emergency: (data) => { log.error(toString(data)) },
|
|
15
|
+
progress: ({ progress, total, message }) => {
|
|
16
|
+
log.info(toString({ progress, total, message }))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/index.ts
ADDED
package/src/logger.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import pino from 'pino'
|
|
2
|
+
import { Logger, LogFn, LogLevel, LogLevels, ProgressOptions } from './types.js'
|
|
3
|
+
|
|
4
|
+
type PinoLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace'
|
|
5
|
+
|
|
6
|
+
const PINO_LEVEL_MAP: Record<LogLevel, PinoLevel> = {
|
|
7
|
+
emergency: 'fatal',
|
|
8
|
+
alert: 'fatal',
|
|
9
|
+
critical: 'fatal',
|
|
10
|
+
error: 'error',
|
|
11
|
+
warning: 'warn',
|
|
12
|
+
notice: 'info',
|
|
13
|
+
info: 'info',
|
|
14
|
+
debug: 'debug'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CreateLoggerOptions {
|
|
18
|
+
name?: string
|
|
19
|
+
level?: string
|
|
20
|
+
stream?: NodeJS.WritableStream | false
|
|
21
|
+
onLog?: (level: LogLevel, data: unknown) => void
|
|
22
|
+
onProgress?: (options: ProgressOptions) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createLogger(options: CreateLoggerOptions = {}): Logger {
|
|
26
|
+
const { name, level = 'debug', stream, onLog, onProgress } = options
|
|
27
|
+
|
|
28
|
+
const pinoOptions: pino.LoggerOptions = { name, level }
|
|
29
|
+
const instance = stream === false
|
|
30
|
+
? pino(pinoOptions, pino.destination('/dev/null'))
|
|
31
|
+
: stream
|
|
32
|
+
? pino(pinoOptions, stream)
|
|
33
|
+
: pino(pinoOptions)
|
|
34
|
+
|
|
35
|
+
const logLevels = Object.fromEntries(LogLevels.map((logLevel) => {
|
|
36
|
+
const pinoLevel = PINO_LEVEL_MAP[logLevel]
|
|
37
|
+
return [logLevel, (data: unknown) => {
|
|
38
|
+
instance[pinoLevel](data)
|
|
39
|
+
onLog?.(logLevel, data)
|
|
40
|
+
}]
|
|
41
|
+
})) as Record<LogLevel, LogFn>
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
...logLevels,
|
|
45
|
+
progress: (progressOptions) => {
|
|
46
|
+
if (onProgress) {
|
|
47
|
+
onProgress(progressOptions)
|
|
48
|
+
} else {
|
|
49
|
+
instance.info({ ...progressOptions }, progressOptions.message)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function buildLogLevels(fn: (level: LogLevel, data: unknown) => void): Record<LogLevel, LogFn> {
|
|
56
|
+
return Object.fromEntries(LogLevels.map((level) => [level, (data: unknown) => { fn(level, data) }])) as Record<LogLevel, LogFn>
|
|
57
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface MessageOptions {
|
|
2
|
+
message: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ProgressOptions {
|
|
6
|
+
progress: number
|
|
7
|
+
total?: number
|
|
8
|
+
message?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const LogLevels = ['error', 'debug', 'info', 'notice', 'warning', 'critical', 'alert', 'emergency'] as const
|
|
12
|
+
|
|
13
|
+
export type LogLevel = typeof LogLevels[number]
|
|
14
|
+
|
|
15
|
+
export type LogFn = (data: unknown) => void
|
|
16
|
+
|
|
17
|
+
export interface Logger extends Record<LogLevel, LogFn> {
|
|
18
|
+
progress: (options: ProgressOptions) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { LogLevels }
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"outDir": "build",
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"declarationMap": true,
|
|
17
|
+
"sourceMap": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src"],
|
|
20
|
+
"exclude": ["node_modules", "build"]
|
|
21
|
+
}
|
package/tsup.config.ts
ADDED