@loglayer/log-level-manager-one-way 1.0.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 +21 -0
- package/README.md +42 -0
- package/dist/index.cjs +130 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +106 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Theo Gravity
|
|
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,42 @@
|
|
|
1
|
+
# One Way Log Level Manager for LogLayer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@loglayer/log-level-manager-one-way)
|
|
4
|
+
[](https://www.npmjs.com/package/@loglayer/log-level-manager-one-way)
|
|
5
|
+
[](http://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
A log level manager for [LogLayer](https://loglayer.dev) that keeps log levels synchronized between parent and children. Parent changes affect children, but child changes do not affect parents.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @loglayer/log-level-manager-one-way
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { LogLayer, ConsoleTransport, LogLevel } from "loglayer";
|
|
19
|
+
import { OneWayLogLevelManager } from '@loglayer/log-level-manager-one-way';
|
|
20
|
+
|
|
21
|
+
const parentLog = new LogLayer({
|
|
22
|
+
transport: new ConsoleTransport({
|
|
23
|
+
logger: console
|
|
24
|
+
}),
|
|
25
|
+
}).withLogLevelManager(new OneWayLogLevelManager());
|
|
26
|
+
|
|
27
|
+
const childLog = parentLog.child();
|
|
28
|
+
|
|
29
|
+
// Parent changes affect children
|
|
30
|
+
parentLog.setLevel(LogLevel.warn);
|
|
31
|
+
childLog.info('This will not be logged'); // Not logged (affected by parent)
|
|
32
|
+
|
|
33
|
+
// Child changes do not affect parent
|
|
34
|
+
childLog.setLevel(LogLevel.debug);
|
|
35
|
+
parentLog.debug('This will not be logged'); // Not logged (parent still at warn)
|
|
36
|
+
childLog.debug('This will be logged'); // Logged (child changed to debug)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
For more details, visit [https://loglayer.dev/log-level-managers/one-way](https://loglayer.dev/log-level-managers/one-way)
|
|
42
|
+
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let __loglayer_log_level_manager = require("@loglayer/log-level-manager");
|
|
25
|
+
__loglayer_log_level_manager = __toESM(__loglayer_log_level_manager);
|
|
26
|
+
|
|
27
|
+
//#region src/OneWayLogLevelManager.ts
|
|
28
|
+
/**
|
|
29
|
+
* A log level manager that keeps log levels synchronized between parent and children.
|
|
30
|
+
* Parent changes affect children, but child changes do not affect parents.
|
|
31
|
+
* Changes only apply to a parent and their children (not separate instances).
|
|
32
|
+
*/
|
|
33
|
+
var OneWayLogLevelManager = class OneWayLogLevelManager {
|
|
34
|
+
logLevelContainer = { status: {
|
|
35
|
+
info: true,
|
|
36
|
+
warn: true,
|
|
37
|
+
error: true,
|
|
38
|
+
debug: true,
|
|
39
|
+
trace: true,
|
|
40
|
+
fatal: true
|
|
41
|
+
} };
|
|
42
|
+
parentManager = null;
|
|
43
|
+
childManagers = /* @__PURE__ */ new Set();
|
|
44
|
+
/**
|
|
45
|
+
* Sets the minimum log level to be used by the logger. Only messages with
|
|
46
|
+
* this level or higher severity will be logged.
|
|
47
|
+
* If this is a parent, the change applies to all its children.
|
|
48
|
+
* If this is a child, the change only applies to this instance.
|
|
49
|
+
*/
|
|
50
|
+
setLevel(logLevel) {
|
|
51
|
+
const minLogValue = __loglayer_log_level_manager.LogLevelPriority[logLevel];
|
|
52
|
+
for (const level of Object.values(__loglayer_log_level_manager.LogLevel)) {
|
|
53
|
+
const levelKey = level;
|
|
54
|
+
const levelValue = __loglayer_log_level_manager.LogLevelPriority[level];
|
|
55
|
+
this.logLevelContainer.status[levelKey] = levelValue >= minLogValue;
|
|
56
|
+
}
|
|
57
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.setLevel(logLevel);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Enables a specific log level.
|
|
61
|
+
* If this is a parent, the change applies to all its children.
|
|
62
|
+
* If this is a child, the change only applies to this instance.
|
|
63
|
+
*/
|
|
64
|
+
enableIndividualLevel(logLevel) {
|
|
65
|
+
const level = logLevel;
|
|
66
|
+
if (level in this.logLevelContainer.status) this.logLevelContainer.status[level] = true;
|
|
67
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.enableIndividualLevel(logLevel);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Disables a specific log level.
|
|
71
|
+
* If this is a parent, the change applies to all its children.
|
|
72
|
+
* If this is a child, the change only applies to this instance.
|
|
73
|
+
*/
|
|
74
|
+
disableIndividualLevel(logLevel) {
|
|
75
|
+
const level = logLevel;
|
|
76
|
+
if (level in this.logLevelContainer.status) this.logLevelContainer.status[level] = false;
|
|
77
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.disableIndividualLevel(logLevel);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a specific log level is enabled
|
|
81
|
+
*/
|
|
82
|
+
isLevelEnabled(logLevel) {
|
|
83
|
+
const level = logLevel;
|
|
84
|
+
return this.logLevelContainer.status[level];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Enable sending logs to the logging library.
|
|
88
|
+
* If this is a parent, the change applies to all its children.
|
|
89
|
+
* If this is a child, the change only applies to this instance.
|
|
90
|
+
*/
|
|
91
|
+
enableLogging() {
|
|
92
|
+
for (const level of Object.keys(this.logLevelContainer.status)) this.logLevelContainer.status[level] = true;
|
|
93
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.enableLogging();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
97
|
+
* If this is a parent, the change applies to all its children.
|
|
98
|
+
* If this is a child, the change only applies to this instance.
|
|
99
|
+
*/
|
|
100
|
+
disableLogging() {
|
|
101
|
+
for (const level of Object.keys(this.logLevelContainer.status)) this.logLevelContainer.status[level] = false;
|
|
102
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.disableLogging();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Links the child log level manager to the parent.
|
|
106
|
+
* The child gets its own container initialized from the parent's status.
|
|
107
|
+
* Parent changes will propagate to children, but child changes won't affect the parent.
|
|
108
|
+
*/
|
|
109
|
+
onChildLoggerCreated({ parentLogLevelManager, childLogLevelManager }) {
|
|
110
|
+
if (childLogLevelManager instanceof OneWayLogLevelManager && parentLogLevelManager instanceof OneWayLogLevelManager) {
|
|
111
|
+
const child = childLogLevelManager;
|
|
112
|
+
const parent = parentLogLevelManager;
|
|
113
|
+
child.logLevelContainer.status = { ...parent.logLevelContainer.status };
|
|
114
|
+
child.parentManager = parent;
|
|
115
|
+
parent.childManagers.add(child);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new instance of the log level manager with its own container.
|
|
120
|
+
* The clone is independent and not linked to the original.
|
|
121
|
+
*/
|
|
122
|
+
clone() {
|
|
123
|
+
const clone = new OneWayLogLevelManager();
|
|
124
|
+
clone.logLevelContainer.status = { ...this.logLevelContainer.status };
|
|
125
|
+
return clone;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
exports.OneWayLogLevelManager = OneWayLogLevelManager;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ILogLevelManager, LogLevelType, OnChildLogLevelManagerCreatedParams } from "@loglayer/log-level-manager";
|
|
2
|
+
|
|
3
|
+
//#region src/OneWayLogLevelManager.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A log level manager that keeps log levels synchronized between parent and children.
|
|
7
|
+
* Parent changes affect children, but child changes do not affect parents.
|
|
8
|
+
* Changes only apply to a parent and their children (not separate instances).
|
|
9
|
+
*/
|
|
10
|
+
declare class OneWayLogLevelManager implements ILogLevelManager {
|
|
11
|
+
private logLevelContainer;
|
|
12
|
+
private parentManager;
|
|
13
|
+
private childManagers;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the minimum log level to be used by the logger. Only messages with
|
|
16
|
+
* this level or higher severity will be logged.
|
|
17
|
+
* If this is a parent, the change applies to all its children.
|
|
18
|
+
* If this is a child, the change only applies to this instance.
|
|
19
|
+
*/
|
|
20
|
+
setLevel(logLevel: LogLevelType): void;
|
|
21
|
+
/**
|
|
22
|
+
* Enables a specific log level.
|
|
23
|
+
* If this is a parent, the change applies to all its children.
|
|
24
|
+
* If this is a child, the change only applies to this instance.
|
|
25
|
+
*/
|
|
26
|
+
enableIndividualLevel(logLevel: LogLevelType): void;
|
|
27
|
+
/**
|
|
28
|
+
* Disables a specific log level.
|
|
29
|
+
* If this is a parent, the change applies to all its children.
|
|
30
|
+
* If this is a child, the change only applies to this instance.
|
|
31
|
+
*/
|
|
32
|
+
disableIndividualLevel(logLevel: LogLevelType): void;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a specific log level is enabled
|
|
35
|
+
*/
|
|
36
|
+
isLevelEnabled(logLevel: LogLevelType): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Enable sending logs to the logging library.
|
|
39
|
+
* If this is a parent, the change applies to all its children.
|
|
40
|
+
* If this is a child, the change only applies to this instance.
|
|
41
|
+
*/
|
|
42
|
+
enableLogging(): void;
|
|
43
|
+
/**
|
|
44
|
+
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
45
|
+
* If this is a parent, the change applies to all its children.
|
|
46
|
+
* If this is a child, the change only applies to this instance.
|
|
47
|
+
*/
|
|
48
|
+
disableLogging(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Links the child log level manager to the parent.
|
|
51
|
+
* The child gets its own container initialized from the parent's status.
|
|
52
|
+
* Parent changes will propagate to children, but child changes won't affect the parent.
|
|
53
|
+
*/
|
|
54
|
+
onChildLoggerCreated({
|
|
55
|
+
parentLogLevelManager,
|
|
56
|
+
childLogLevelManager
|
|
57
|
+
}: OnChildLogLevelManagerCreatedParams): void;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new instance of the log level manager with its own container.
|
|
60
|
+
* The clone is independent and not linked to the original.
|
|
61
|
+
*/
|
|
62
|
+
clone(): ILogLevelManager;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { OneWayLogLevelManager };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ILogLevelManager, LogLevelType, OnChildLogLevelManagerCreatedParams } from "@loglayer/log-level-manager";
|
|
2
|
+
|
|
3
|
+
//#region src/OneWayLogLevelManager.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A log level manager that keeps log levels synchronized between parent and children.
|
|
7
|
+
* Parent changes affect children, but child changes do not affect parents.
|
|
8
|
+
* Changes only apply to a parent and their children (not separate instances).
|
|
9
|
+
*/
|
|
10
|
+
declare class OneWayLogLevelManager implements ILogLevelManager {
|
|
11
|
+
private logLevelContainer;
|
|
12
|
+
private parentManager;
|
|
13
|
+
private childManagers;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the minimum log level to be used by the logger. Only messages with
|
|
16
|
+
* this level or higher severity will be logged.
|
|
17
|
+
* If this is a parent, the change applies to all its children.
|
|
18
|
+
* If this is a child, the change only applies to this instance.
|
|
19
|
+
*/
|
|
20
|
+
setLevel(logLevel: LogLevelType): void;
|
|
21
|
+
/**
|
|
22
|
+
* Enables a specific log level.
|
|
23
|
+
* If this is a parent, the change applies to all its children.
|
|
24
|
+
* If this is a child, the change only applies to this instance.
|
|
25
|
+
*/
|
|
26
|
+
enableIndividualLevel(logLevel: LogLevelType): void;
|
|
27
|
+
/**
|
|
28
|
+
* Disables a specific log level.
|
|
29
|
+
* If this is a parent, the change applies to all its children.
|
|
30
|
+
* If this is a child, the change only applies to this instance.
|
|
31
|
+
*/
|
|
32
|
+
disableIndividualLevel(logLevel: LogLevelType): void;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a specific log level is enabled
|
|
35
|
+
*/
|
|
36
|
+
isLevelEnabled(logLevel: LogLevelType): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Enable sending logs to the logging library.
|
|
39
|
+
* If this is a parent, the change applies to all its children.
|
|
40
|
+
* If this is a child, the change only applies to this instance.
|
|
41
|
+
*/
|
|
42
|
+
enableLogging(): void;
|
|
43
|
+
/**
|
|
44
|
+
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
45
|
+
* If this is a parent, the change applies to all its children.
|
|
46
|
+
* If this is a child, the change only applies to this instance.
|
|
47
|
+
*/
|
|
48
|
+
disableLogging(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Links the child log level manager to the parent.
|
|
51
|
+
* The child gets its own container initialized from the parent's status.
|
|
52
|
+
* Parent changes will propagate to children, but child changes won't affect the parent.
|
|
53
|
+
*/
|
|
54
|
+
onChildLoggerCreated({
|
|
55
|
+
parentLogLevelManager,
|
|
56
|
+
childLogLevelManager
|
|
57
|
+
}: OnChildLogLevelManagerCreatedParams): void;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new instance of the log level manager with its own container.
|
|
60
|
+
* The clone is independent and not linked to the original.
|
|
61
|
+
*/
|
|
62
|
+
clone(): ILogLevelManager;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { OneWayLogLevelManager };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { LogLevel, LogLevelPriority } from "@loglayer/log-level-manager";
|
|
2
|
+
|
|
3
|
+
//#region src/OneWayLogLevelManager.ts
|
|
4
|
+
/**
|
|
5
|
+
* A log level manager that keeps log levels synchronized between parent and children.
|
|
6
|
+
* Parent changes affect children, but child changes do not affect parents.
|
|
7
|
+
* Changes only apply to a parent and their children (not separate instances).
|
|
8
|
+
*/
|
|
9
|
+
var OneWayLogLevelManager = class OneWayLogLevelManager {
|
|
10
|
+
logLevelContainer = { status: {
|
|
11
|
+
info: true,
|
|
12
|
+
warn: true,
|
|
13
|
+
error: true,
|
|
14
|
+
debug: true,
|
|
15
|
+
trace: true,
|
|
16
|
+
fatal: true
|
|
17
|
+
} };
|
|
18
|
+
parentManager = null;
|
|
19
|
+
childManagers = /* @__PURE__ */ new Set();
|
|
20
|
+
/**
|
|
21
|
+
* Sets the minimum log level to be used by the logger. Only messages with
|
|
22
|
+
* this level or higher severity will be logged.
|
|
23
|
+
* If this is a parent, the change applies to all its children.
|
|
24
|
+
* If this is a child, the change only applies to this instance.
|
|
25
|
+
*/
|
|
26
|
+
setLevel(logLevel) {
|
|
27
|
+
const minLogValue = LogLevelPriority[logLevel];
|
|
28
|
+
for (const level of Object.values(LogLevel)) {
|
|
29
|
+
const levelKey = level;
|
|
30
|
+
const levelValue = LogLevelPriority[level];
|
|
31
|
+
this.logLevelContainer.status[levelKey] = levelValue >= minLogValue;
|
|
32
|
+
}
|
|
33
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.setLevel(logLevel);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Enables a specific log level.
|
|
37
|
+
* If this is a parent, the change applies to all its children.
|
|
38
|
+
* If this is a child, the change only applies to this instance.
|
|
39
|
+
*/
|
|
40
|
+
enableIndividualLevel(logLevel) {
|
|
41
|
+
const level = logLevel;
|
|
42
|
+
if (level in this.logLevelContainer.status) this.logLevelContainer.status[level] = true;
|
|
43
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.enableIndividualLevel(logLevel);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Disables a specific log level.
|
|
47
|
+
* If this is a parent, the change applies to all its children.
|
|
48
|
+
* If this is a child, the change only applies to this instance.
|
|
49
|
+
*/
|
|
50
|
+
disableIndividualLevel(logLevel) {
|
|
51
|
+
const level = logLevel;
|
|
52
|
+
if (level in this.logLevelContainer.status) this.logLevelContainer.status[level] = false;
|
|
53
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.disableIndividualLevel(logLevel);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a specific log level is enabled
|
|
57
|
+
*/
|
|
58
|
+
isLevelEnabled(logLevel) {
|
|
59
|
+
const level = logLevel;
|
|
60
|
+
return this.logLevelContainer.status[level];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Enable sending logs to the logging library.
|
|
64
|
+
* If this is a parent, the change applies to all its children.
|
|
65
|
+
* If this is a child, the change only applies to this instance.
|
|
66
|
+
*/
|
|
67
|
+
enableLogging() {
|
|
68
|
+
for (const level of Object.keys(this.logLevelContainer.status)) this.logLevelContainer.status[level] = true;
|
|
69
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.enableLogging();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
73
|
+
* If this is a parent, the change applies to all its children.
|
|
74
|
+
* If this is a child, the change only applies to this instance.
|
|
75
|
+
*/
|
|
76
|
+
disableLogging() {
|
|
77
|
+
for (const level of Object.keys(this.logLevelContainer.status)) this.logLevelContainer.status[level] = false;
|
|
78
|
+
if (this.childManagers.size > 0) for (const child of this.childManagers) child.disableLogging();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Links the child log level manager to the parent.
|
|
82
|
+
* The child gets its own container initialized from the parent's status.
|
|
83
|
+
* Parent changes will propagate to children, but child changes won't affect the parent.
|
|
84
|
+
*/
|
|
85
|
+
onChildLoggerCreated({ parentLogLevelManager, childLogLevelManager }) {
|
|
86
|
+
if (childLogLevelManager instanceof OneWayLogLevelManager && parentLogLevelManager instanceof OneWayLogLevelManager) {
|
|
87
|
+
const child = childLogLevelManager;
|
|
88
|
+
const parent = parentLogLevelManager;
|
|
89
|
+
child.logLevelContainer.status = { ...parent.logLevelContainer.status };
|
|
90
|
+
child.parentManager = parent;
|
|
91
|
+
parent.childManagers.add(child);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new instance of the log level manager with its own container.
|
|
96
|
+
* The clone is independent and not linked to the original.
|
|
97
|
+
*/
|
|
98
|
+
clone() {
|
|
99
|
+
const clone = new OneWayLogLevelManager();
|
|
100
|
+
clone.logLevelContainer.status = { ...this.logLevelContainer.status };
|
|
101
|
+
return clone;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { OneWayLogLevelManager };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loglayer/log-level-manager-one-way",
|
|
3
|
+
"description": "Log level manager for loglayer that keeps log levels synchronized between parent and children (parent changes affect children, but child changes don't affect parents).",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/loglayer/loglayer.git",
|
|
23
|
+
"directory": "packages/log-level-managers/one-way"
|
|
24
|
+
},
|
|
25
|
+
"author": "Theo Gravity <theo@suteki.nu>",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"logging",
|
|
28
|
+
"log",
|
|
29
|
+
"loglayer",
|
|
30
|
+
"log level",
|
|
31
|
+
"one-way",
|
|
32
|
+
"log level manager"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@loglayer/log-level-manager": "1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "24.10.1",
|
|
39
|
+
"tsdown": "0.15.12",
|
|
40
|
+
"typescript": "5.9.3",
|
|
41
|
+
"vitest": "4.0.9",
|
|
42
|
+
"@internal/tsconfig": "2.1.0",
|
|
43
|
+
"loglayer": "8.0.0"
|
|
44
|
+
},
|
|
45
|
+
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"homepage": "https://loglayer.dev",
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsdown src/index.ts",
|
|
55
|
+
"test": "vitest --run",
|
|
56
|
+
"clean": "rm -rf .turbo node_modules dist",
|
|
57
|
+
"lint": "biome check --no-errors-on-unmatched --write --unsafe src",
|
|
58
|
+
"lint:staged": "biome check --no-errors-on-unmatched --write --unsafe --staged src",
|
|
59
|
+
"verify-types": "tsc --noEmit"
|
|
60
|
+
}
|
|
61
|
+
}
|