@vlandoss/loggy 0.2.0 → 0.2.1-git-e775e2a.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/package.json +8 -3
- package/dist/index.d.mts +0 -53
- package/dist/index.mjs +0 -111
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vlandoss/loggy",
|
|
3
|
-
"version": "0.2.0",
|
|
3
|
+
"version": "0.2.1-git-e775e2a.0",
|
|
4
4
|
"description": "Console wrapper to make logging fun again",
|
|
5
5
|
"homepage": "https://github.com/variableland/dx/tree/main/packages/loggy#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
"directory": "packages/loggy"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"author":
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "rcrd",
|
|
17
|
+
"email": "rcrd@variable.land"
|
|
18
|
+
},
|
|
16
19
|
"type": "module",
|
|
17
20
|
"exports": {
|
|
18
21
|
".": {
|
|
@@ -40,8 +43,10 @@
|
|
|
40
43
|
"@types/debug": "4.1.12",
|
|
41
44
|
"@vlandoss/tsdown-config": "^0.0.1"
|
|
42
45
|
},
|
|
46
|
+
"readme": "ERROR: No README data found!",
|
|
47
|
+
"_id": "@vlandoss/loggy@0.2.0",
|
|
43
48
|
"scripts": {
|
|
44
49
|
"build": "tsdown",
|
|
45
50
|
"test:types": "rr tsc"
|
|
46
51
|
}
|
|
47
|
-
}
|
|
52
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { FormatOptions } from "consola";
|
|
2
|
-
import createDebug from "debug";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
type AnyLogFn = (...args: unknown[]) => void;
|
|
6
|
-
type Formatters = Record<string, (arg: unknown) => string>;
|
|
7
|
-
type AnyLogger = {
|
|
8
|
-
namespace: string;
|
|
9
|
-
debug: AnyLogFn;
|
|
10
|
-
error: AnyLogFn;
|
|
11
|
-
info: AnyLogFn;
|
|
12
|
-
trace: AnyLogFn;
|
|
13
|
-
warn: AnyLogFn;
|
|
14
|
-
child: (options: CreateOptions) => AnyLogger;
|
|
15
|
-
subdebug: (namespace: string) => AnyLogFn;
|
|
16
|
-
start: AnyLogFn;
|
|
17
|
-
success: AnyLogFn;
|
|
18
|
-
};
|
|
19
|
-
type CreateOptions = {
|
|
20
|
-
namespace: string;
|
|
21
|
-
tag?: string;
|
|
22
|
-
formatOptions?: FormatOptions;
|
|
23
|
-
formatters?: Formatters;
|
|
24
|
-
};
|
|
25
|
-
type LoggerOptions = {
|
|
26
|
-
tag?: string;
|
|
27
|
-
namespace: string;
|
|
28
|
-
formatOptions: FormatOptions;
|
|
29
|
-
formatters: Formatters;
|
|
30
|
-
};
|
|
31
|
-
type LogFnOptions = {
|
|
32
|
-
tag: string;
|
|
33
|
-
message: string;
|
|
34
|
-
};
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/loggy.d.ts
|
|
37
|
-
declare class Loggy implements AnyLogger {
|
|
38
|
-
#private;
|
|
39
|
-
constructor(options: LoggerOptions);
|
|
40
|
-
get namespace(): string;
|
|
41
|
-
debug(...args: unknown[]): void;
|
|
42
|
-
error(...args: unknown[]): void;
|
|
43
|
-
info(opts: LogFnOptions | unknown, ...args: unknown[]): void;
|
|
44
|
-
trace(opts: LogFnOptions | unknown, ...args: unknown[]): void;
|
|
45
|
-
warn(opts: LogFnOptions | unknown, ...args: unknown[]): void;
|
|
46
|
-
child(options: CreateOptions): Loggy;
|
|
47
|
-
start(opts: LogFnOptions | unknown, ...args: unknown[]): void;
|
|
48
|
-
success(opts: LogFnOptions | unknown, ...args: unknown[]): void;
|
|
49
|
-
subdebug(namespace: string): createDebug.Debugger;
|
|
50
|
-
}
|
|
51
|
-
declare function createLoggy(options: CreateOptions): Loggy;
|
|
52
|
-
//#endregion
|
|
53
|
-
export { AnyLogFn, AnyLogger, CreateOptions, type FormatOptions, Formatters, LogFnOptions, LoggerOptions, Loggy, createLoggy };
|
package/dist/index.mjs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import util from "node:util";
|
|
2
|
-
import { createConsola } from "consola";
|
|
3
|
-
import { colors } from "consola/utils";
|
|
4
|
-
import createDebug from "debug";
|
|
5
|
-
//#region src/const.ts
|
|
6
|
-
const DEFAULT_FORMAT_OPTIONS = {
|
|
7
|
-
colors: true,
|
|
8
|
-
depth: 3,
|
|
9
|
-
maxArrayLength: 50,
|
|
10
|
-
breakLength: 80,
|
|
11
|
-
date: false
|
|
12
|
-
};
|
|
13
|
-
const DEFAULT_FORMATTERS = {
|
|
14
|
-
o: (arg) => {
|
|
15
|
-
return util.inspect(arg, DEFAULT_FORMAT_OPTIONS).split("\n").map((str) => str.trim()).join(" ");
|
|
16
|
-
},
|
|
17
|
-
O: (arg) => {
|
|
18
|
-
return util.inspect(arg, DEFAULT_FORMAT_OPTIONS);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/loggy.ts
|
|
23
|
-
function isLogFnOptions(arg) {
|
|
24
|
-
try {
|
|
25
|
-
return typeof arg.message === "string" && typeof arg.tag === "string";
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
var Loggy = class Loggy {
|
|
31
|
-
#options;
|
|
32
|
-
#debug;
|
|
33
|
-
#consola;
|
|
34
|
-
constructor(options) {
|
|
35
|
-
this.#options = options;
|
|
36
|
-
this.#debug = createDebug(`${options.namespace}:root`);
|
|
37
|
-
this.#consola = createConsola({ formatOptions: options.formatOptions });
|
|
38
|
-
}
|
|
39
|
-
get namespace() {
|
|
40
|
-
return this.#options.namespace;
|
|
41
|
-
}
|
|
42
|
-
debug(...args) {
|
|
43
|
-
this.#debug(...args);
|
|
44
|
-
}
|
|
45
|
-
error(...args) {
|
|
46
|
-
this.#consola.error(this.#format(...args));
|
|
47
|
-
}
|
|
48
|
-
info(opts, ...args) {
|
|
49
|
-
this.#consola.info(this.#format(opts, ...args));
|
|
50
|
-
}
|
|
51
|
-
trace(opts, ...args) {
|
|
52
|
-
this.#consola.trace(this.#format(opts, ...args));
|
|
53
|
-
}
|
|
54
|
-
warn(opts, ...args) {
|
|
55
|
-
this.#consola.warn(this.#format(opts, ...args));
|
|
56
|
-
}
|
|
57
|
-
child(options) {
|
|
58
|
-
return new Loggy({
|
|
59
|
-
...this.#options,
|
|
60
|
-
...options,
|
|
61
|
-
namespace: `${this.#options.namespace}:${options.namespace}`
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
start(opts, ...args) {
|
|
65
|
-
this.#consola.start(this.#format(opts, ...args));
|
|
66
|
-
}
|
|
67
|
-
success(opts, ...args) {
|
|
68
|
-
this.#consola.success(this.#format(opts, ...args));
|
|
69
|
-
}
|
|
70
|
-
subdebug(namespace) {
|
|
71
|
-
return createDebug(`${this.#options.namespace}:${namespace}`);
|
|
72
|
-
}
|
|
73
|
-
#format(...args) {
|
|
74
|
-
const [firstArg, ...restArgs] = args;
|
|
75
|
-
const tag = isLogFnOptions(firstArg) ? firstArg.tag : this.#options.tag;
|
|
76
|
-
const formattedArgs = isLogFnOptions(firstArg) ? [firstArg.message, ...restArgs] : args;
|
|
77
|
-
if (typeof formattedArgs[0] !== "string") formattedArgs.unshift("%O");
|
|
78
|
-
const [message, ...replacements] = formattedArgs;
|
|
79
|
-
let replacementIndex = -1;
|
|
80
|
-
if (typeof message !== "string") throw new TypeError("message must be a string");
|
|
81
|
-
let formattedMessage = message.replace(/%([a-zA-Z%])/g, (match, formatKey) => {
|
|
82
|
-
if (formatKey === "%") return "%";
|
|
83
|
-
replacementIndex++;
|
|
84
|
-
const formatter = this.#options.formatters[formatKey];
|
|
85
|
-
if (typeof formatter !== "function") return match;
|
|
86
|
-
const replacement = replacements[replacementIndex];
|
|
87
|
-
const formattedMatch = formatter(replacement);
|
|
88
|
-
replacements.splice(replacementIndex, 1);
|
|
89
|
-
replacementIndex--;
|
|
90
|
-
return formattedMatch;
|
|
91
|
-
}).split("\n").join(`\n${" ".repeat(2)}`);
|
|
92
|
-
formattedMessage = !tag ? formattedMessage : `${colors.cyan(`[${tag}]`)} ${formattedMessage}`;
|
|
93
|
-
return util.formatWithOptions(this.#options.formatOptions, formattedMessage, ...replacements);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
function createLoggy(options) {
|
|
97
|
-
return new Loggy({
|
|
98
|
-
namespace: options.namespace,
|
|
99
|
-
tag: options.tag,
|
|
100
|
-
formatOptions: {
|
|
101
|
-
...DEFAULT_FORMAT_OPTIONS,
|
|
102
|
-
...options.formatOptions
|
|
103
|
-
},
|
|
104
|
-
formatters: {
|
|
105
|
-
...DEFAULT_FORMATTERS,
|
|
106
|
-
...options.formatters
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { Loggy, createLoggy };
|