@pistonite/pure 0.26.6 → 0.26.7
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 +1 -1
- package/src/log/index.ts +2 -0
- package/src/log/internal.ts +7 -11
- package/src/log/logger.ts +34 -3
package/package.json
CHANGED
package/src/log/index.ts
CHANGED
package/src/log/internal.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resettableLogger } from "./logger.ts";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const { logger, off, debug, info } = resettableLogger("pure", "gray");
|
|
4
|
+
|
|
5
|
+
export const ilog = logger;
|
|
4
6
|
|
|
5
7
|
/** Set the internal log level of calls in this library to off */
|
|
6
|
-
export const internalLogOff =
|
|
7
|
-
ilog.level = LogLevel.Off;
|
|
8
|
-
};
|
|
8
|
+
export const internalLogOff = off;
|
|
9
9
|
|
|
10
10
|
/** Set the internal log level of calls in this library to debug */
|
|
11
|
-
export const internalLogDebug =
|
|
12
|
-
ilog.level = LogLevel.Debug;
|
|
13
|
-
};
|
|
11
|
+
export const internalLogDebug = debug;
|
|
14
12
|
|
|
15
13
|
/** Set the internal log level of calls in this library to info */
|
|
16
|
-
export const internalLogInfo =
|
|
17
|
-
ilog.level = LogLevel.Info;
|
|
18
|
-
};
|
|
14
|
+
export const internalLogInfo = info;
|
package/src/log/logger.ts
CHANGED
|
@@ -37,19 +37,25 @@ let globalLevel: LogLevel = LogLevel.High;
|
|
|
37
37
|
*
|
|
38
38
|
* This overrides logger-level settings
|
|
39
39
|
*/
|
|
40
|
-
export const globalLogOff = () =>
|
|
40
|
+
export const globalLogOff = () => {
|
|
41
|
+
globalLevel = LogLevel.Off;
|
|
42
|
+
};
|
|
41
43
|
/**
|
|
42
44
|
* Enable +info logging for ALL loggers
|
|
43
45
|
*
|
|
44
46
|
* This overrides logger-level settings
|
|
45
47
|
*/
|
|
46
|
-
export const globalLogInfo = () =>
|
|
48
|
+
export const globalLogInfo = () => {
|
|
49
|
+
globalLevel = LogLevel.Info;
|
|
50
|
+
};
|
|
47
51
|
/**
|
|
48
52
|
* Enable +debug logging for ALL loggers
|
|
49
53
|
*
|
|
50
54
|
* This overrides logger-level settings
|
|
51
55
|
*/
|
|
52
|
-
export const globalLogDebug = () =>
|
|
56
|
+
export const globalLogDebug = () => {
|
|
57
|
+
globalLevel = LogLevel.Debug;
|
|
58
|
+
};
|
|
53
59
|
|
|
54
60
|
/** Create a logger creator. Use the factory methods to finish making the logger */
|
|
55
61
|
export const logger = (name: string, color?: string): LoggerFactory => {
|
|
@@ -61,6 +67,31 @@ export const logger = (name: string, color?: string): LoggerFactory => {
|
|
|
61
67
|
};
|
|
62
68
|
};
|
|
63
69
|
|
|
70
|
+
/** Create a {@link ResettableLogger} that can be easily reconfigured */
|
|
71
|
+
export const resettableLogger = (
|
|
72
|
+
name: string,
|
|
73
|
+
color?: string,
|
|
74
|
+
): ResettableLogger => {
|
|
75
|
+
const logger = new LoggerImpl(name, color, LogLevel.High);
|
|
76
|
+
return {
|
|
77
|
+
logger,
|
|
78
|
+
debug: () => (logger.level = LogLevel.Debug),
|
|
79
|
+
info: () => (logger.level = LogLevel.Info),
|
|
80
|
+
off: () => (logger.level = LogLevel.Off),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A logger whose level can be changed later. Useful for libraries to expose,
|
|
86
|
+
* so users can easily debug calls in the library
|
|
87
|
+
*/
|
|
88
|
+
export type ResettableLogger = {
|
|
89
|
+
logger: Logger;
|
|
90
|
+
debug(): void;
|
|
91
|
+
info(): void;
|
|
92
|
+
off(): void;
|
|
93
|
+
};
|
|
94
|
+
|
|
64
95
|
export type LoggerFactory = {
|
|
65
96
|
/** Standard important logger (warning and errors) */
|
|
66
97
|
default(): Logger;
|