@orieljs/log 0.1.0-alpha.1
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 +202 -0
- package/NOTICE +9 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.js +472 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Oriel
|
|
2
|
+
Copyright 2026 meeeet-dev and Oriel contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Oriel project
|
|
5
|
+
(https://orieljs.vercel.app, https://github.com/orieljs).
|
|
6
|
+
|
|
7
|
+
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
|
+
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
|
+
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Logger, LogLevel, OrielError, ErrorKind, LogManager as LogManager$1, Container } from '@orieljs/contracts';
|
|
2
|
+
import pino from 'pino';
|
|
3
|
+
import { WriteStream } from 'node:fs';
|
|
4
|
+
import { Writable } from 'node:stream';
|
|
5
|
+
import * as _orieljs_support from '@orieljs/support';
|
|
6
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Implements the full `Logger` contract on top of one `write()` method: level filtering, merging in the current
|
|
10
|
+
* scope's context (`context.ts`) and serializing `Error` values (`levels.ts`) all happen here, once.
|
|
11
|
+
*/
|
|
12
|
+
declare abstract class BaseLogger implements Logger {
|
|
13
|
+
protected readonly minimumLevel: LogLevel;
|
|
14
|
+
constructor(minimumLevel?: LogLevel);
|
|
15
|
+
log(level: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
16
|
+
emergency(message: string, context?: Record<string, unknown>): void;
|
|
17
|
+
alert(message: string, context?: Record<string, unknown>): void;
|
|
18
|
+
critical(message: string, context?: Record<string, unknown>): void;
|
|
19
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
20
|
+
warning(message: string, context?: Record<string, unknown>): void;
|
|
21
|
+
notice(message: string, context?: Record<string, unknown>): void;
|
|
22
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
23
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
24
|
+
withContext(context: Record<string, unknown>): this;
|
|
25
|
+
/** Called only when `level` already meets this logger's configured minimum, with context fully resolved. */
|
|
26
|
+
protected abstract write(level: LogLevel, message: string, context: Record<string, unknown>): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A channel backed by a pino logger writing to an arbitrary destination stream (file, stderr, ...). */
|
|
30
|
+
declare class PinoLogger extends BaseLogger {
|
|
31
|
+
private readonly pinoInstance;
|
|
32
|
+
constructor(pinoInstance: pino.Logger, minimumLevel?: LogLevel);
|
|
33
|
+
protected write(level: LogLevel, message: string, context: Record<string, unknown>): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `single` channel: everything appended to one file, e.g. `storage/logs/oriel.log`. */
|
|
37
|
+
declare function createSingleChannel(path: string, minimumLevel?: LogLevel): PinoLogger;
|
|
38
|
+
/** The `daily` channel: one file per day under the same directory, pruned after `days`. */
|
|
39
|
+
declare function createDailyChannel(path: string, days?: number, minimumLevel?: LogLevel, now?: () => Date): PinoLogger;
|
|
40
|
+
/** The `stderr` channel. */
|
|
41
|
+
declare function createStderrChannel(minimumLevel?: LogLevel): PinoLogger;
|
|
42
|
+
|
|
43
|
+
/** Merges `context` into the log context for the current scope (Laravel's `Log::withContext()`). */
|
|
44
|
+
declare function mergeLogContext(context: Record<string, unknown>): void;
|
|
45
|
+
/** The merged log context for the current scope, or `{}` if none has been added. */
|
|
46
|
+
declare function currentLogContext(): Record<string, unknown>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Writes to `<dir>/<stem>-<YYYY-MM-DD>.log`, switching files when the local calendar day changes and deleting files
|
|
50
|
+
* older than `days` each time it rolls over. `now` is injectable so tests can simulate day boundaries without a
|
|
51
|
+
* fake timer.
|
|
52
|
+
*/
|
|
53
|
+
declare class DailyRotatingStream extends Writable {
|
|
54
|
+
private readonly days;
|
|
55
|
+
private readonly now;
|
|
56
|
+
private readonly dir;
|
|
57
|
+
private readonly stem;
|
|
58
|
+
private currentDate;
|
|
59
|
+
private stream;
|
|
60
|
+
/**
|
|
61
|
+
* The in-flight `_write()`'s callback, if any, tagged with the exact child stream it was issued for. Resolved
|
|
62
|
+
* either by that stream's own write completing or by that same stream's `'error'` listener, whichever comes
|
|
63
|
+
* first, so a write can never hang on a broken destination. Scoping it to `stream` (rather than just tracking
|
|
64
|
+
* "the current callback") matters across a rollover: a superseded stream can still emit a late `'error'` (e.g.
|
|
65
|
+
* a failed flush during its fire-and-forget `end()`) after a write is already pending on the *new* stream, and
|
|
66
|
+
* that stale error must only produce its own stderr notice, never resolve someone else's pending write.
|
|
67
|
+
*/
|
|
68
|
+
private pending;
|
|
69
|
+
constructor(basePath: string, days: number, now?: () => Date);
|
|
70
|
+
private pathFor;
|
|
71
|
+
private today;
|
|
72
|
+
/**
|
|
73
|
+
* Opens the file at `path` and attaches an `'error'` listener so an I/O failure (disk full, EACCES, EISDIR, ...)
|
|
74
|
+
* on this one child stream can never crash the process: it's reported as a one-line notice on `process.stderr`,
|
|
75
|
+
* the stream is dropped (the next write reopens it), and it is never re-emitted on `this`.
|
|
76
|
+
*
|
|
77
|
+
* `protected` rather than `private` only so a test can subclass and capture the real child streams this opens
|
|
78
|
+
* (node:fs's ESM module namespace can't be `vi.spyOn()`'d), to simulate a stream retired by rollover emitting a
|
|
79
|
+
* late error while a write is already pending on its replacement.
|
|
80
|
+
*/
|
|
81
|
+
protected openStream(path: string): WriteStream;
|
|
82
|
+
private ensureStream;
|
|
83
|
+
/**
|
|
84
|
+
* Deletes this channel's files dated before the oldest of the `days` most recent local days (today included).
|
|
85
|
+
* Only names that are exactly `<stem>-<YYYY-MM-DD>.log` count, so a sibling channel sharing the prefix
|
|
86
|
+
* (e.g. `oriel-worker-<date>.log` next to `oriel-<date>.log`) is never touched.
|
|
87
|
+
*/
|
|
88
|
+
private prune;
|
|
89
|
+
_write(chunk: unknown, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
90
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare class UnknownLogChannelError extends Error implements OrielError {
|
|
94
|
+
readonly channel: string;
|
|
95
|
+
readonly kind: ErrorKind;
|
|
96
|
+
constructor(channel: string);
|
|
97
|
+
}
|
|
98
|
+
declare class UnknownLogDriverError extends Error implements OrielError {
|
|
99
|
+
readonly driver: string;
|
|
100
|
+
readonly kind: ErrorKind;
|
|
101
|
+
constructor(driver: string);
|
|
102
|
+
}
|
|
103
|
+
declare class LogChannelCycleError extends Error implements OrielError {
|
|
104
|
+
readonly channel: string;
|
|
105
|
+
readonly kind: ErrorKind;
|
|
106
|
+
constructor(channel: string);
|
|
107
|
+
}
|
|
108
|
+
declare class InvalidLogLevelError extends Error implements OrielError {
|
|
109
|
+
readonly level: string;
|
|
110
|
+
readonly kind: ErrorKind;
|
|
111
|
+
constructor(level: string);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The `Log` facade (Laravel's `Illuminate\Support\Facades\Log`). `Log.channel('single').info(...)`. */
|
|
115
|
+
declare const Log: _orieljs_support.Facade<LogManager$1, object>;
|
|
116
|
+
/** With no args, the LogManager itself. With a message, logs it at `debug` (Laravel's `logger()` helper). */
|
|
117
|
+
declare function logger(): LogManager$1;
|
|
118
|
+
declare function logger(message: string, context?: Record<string, unknown>): void;
|
|
119
|
+
|
|
120
|
+
/** RFC 5424 severities, most severe first. Higher numbers are more severe. */
|
|
121
|
+
declare const LEVEL_SEVERITY: Record<LogLevel, number>;
|
|
122
|
+
/** True when `level` is at least as severe as `minimum` (e.g. `error` meets a `warning` threshold). */
|
|
123
|
+
declare function meetsLevel(level: LogLevel, minimum: LogLevel): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* `Error` objects don't survive `JSON.stringify` (message/stack/name aren't own enumerable properties), so any
|
|
126
|
+
* `Error` values directly on the context object are expanded one level deep into a plain `{ name, message, stack }`.
|
|
127
|
+
* This is how `LogManager.error(message, { exception })` (Http's exception handler) ends up readable in log output.
|
|
128
|
+
*/
|
|
129
|
+
declare function serializeContext(context: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
130
|
+
|
|
131
|
+
/** `LogManager`: resolves channels by name from `config('logging')`, lazily and cached. */
|
|
132
|
+
declare class LogManager implements LogManager$1 {
|
|
133
|
+
private readonly container;
|
|
134
|
+
private readonly channels;
|
|
135
|
+
private readonly drivers;
|
|
136
|
+
private readonly resolving;
|
|
137
|
+
constructor(container: Container);
|
|
138
|
+
private loggingConfig;
|
|
139
|
+
channel(name?: string): Logger;
|
|
140
|
+
stack(channels: string[]): Logger;
|
|
141
|
+
log(logLevel: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
142
|
+
emergency(message: string, context?: Record<string, unknown>): void;
|
|
143
|
+
alert(message: string, context?: Record<string, unknown>): void;
|
|
144
|
+
critical(message: string, context?: Record<string, unknown>): void;
|
|
145
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
146
|
+
warning(message: string, context?: Record<string, unknown>): void;
|
|
147
|
+
notice(message: string, context?: Record<string, unknown>): void;
|
|
148
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
149
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
150
|
+
withContext(context: Record<string, unknown>): this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Binds the LogManager and merges Laravel 11's `logging` defaults (stack -> single, LOG_LEVEL=debug). */
|
|
154
|
+
declare class LogServiceProvider extends ServiceProvider {
|
|
155
|
+
register(): void;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The `null` channel: discards every entry (Laravel's `NullHandler`). */
|
|
159
|
+
declare class NullLogger extends BaseLogger {
|
|
160
|
+
protected write(): void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** `Log.stack([...])`: fans every entry out to each constituent channel, which does its own level filtering. */
|
|
164
|
+
declare class StackLogger implements Logger {
|
|
165
|
+
private readonly channels;
|
|
166
|
+
constructor(channels: Logger[]);
|
|
167
|
+
log(level: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
168
|
+
emergency(message: string, context?: Record<string, unknown>): void;
|
|
169
|
+
alert(message: string, context?: Record<string, unknown>): void;
|
|
170
|
+
critical(message: string, context?: Record<string, unknown>): void;
|
|
171
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
172
|
+
warning(message: string, context?: Record<string, unknown>): void;
|
|
173
|
+
notice(message: string, context?: Record<string, unknown>): void;
|
|
174
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
175
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
176
|
+
/** Context is scoped by the container (see context.ts), not per-instance, so this affects every channel. */
|
|
177
|
+
withContext(context: Record<string, unknown>): this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { BaseLogger, DailyRotatingStream, InvalidLogLevelError, LEVEL_SEVERITY, Log, LogChannelCycleError, LogManager, LogServiceProvider, NullLogger, PinoLogger, StackLogger, UnknownLogChannelError, UnknownLogDriverError, createDailyChannel, createSingleChannel, createStderrChannel, currentLogContext, logger, meetsLevel, mergeLogContext, serializeContext };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
// context.ts
|
|
2
|
+
import { currentContainer } from "@orieljs/container";
|
|
3
|
+
var rootKey = {};
|
|
4
|
+
var contexts = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function mergeLogContext(context) {
|
|
6
|
+
const key = currentContainer() ?? rootKey;
|
|
7
|
+
contexts.set(key, { ...contexts.get(key), ...context });
|
|
8
|
+
}
|
|
9
|
+
function currentLogContext() {
|
|
10
|
+
return contexts.get(currentContainer() ?? rootKey) ?? {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// errors.ts
|
|
14
|
+
var UnknownLogChannelError = class extends Error {
|
|
15
|
+
constructor(channel) {
|
|
16
|
+
super(`Log channel [${channel}] is not defined in config('logging.channels').`);
|
|
17
|
+
this.channel = channel;
|
|
18
|
+
this.name = "UnknownLogChannelError";
|
|
19
|
+
}
|
|
20
|
+
channel;
|
|
21
|
+
kind = "Server";
|
|
22
|
+
};
|
|
23
|
+
var UnknownLogDriverError = class extends Error {
|
|
24
|
+
constructor(driver) {
|
|
25
|
+
super(`Log driver [${driver}] is not registered.`);
|
|
26
|
+
this.driver = driver;
|
|
27
|
+
this.name = "UnknownLogDriverError";
|
|
28
|
+
}
|
|
29
|
+
driver;
|
|
30
|
+
kind = "Server";
|
|
31
|
+
};
|
|
32
|
+
var LogChannelCycleError = class extends Error {
|
|
33
|
+
constructor(channel) {
|
|
34
|
+
super(`Log channel [${channel}] includes itself.`);
|
|
35
|
+
this.channel = channel;
|
|
36
|
+
this.name = "LogChannelCycleError";
|
|
37
|
+
}
|
|
38
|
+
channel;
|
|
39
|
+
kind = "Server";
|
|
40
|
+
};
|
|
41
|
+
var InvalidLogLevelError = class extends Error {
|
|
42
|
+
constructor(level2) {
|
|
43
|
+
super(`Invalid log level [${level2}].`);
|
|
44
|
+
this.level = level2;
|
|
45
|
+
this.name = "InvalidLogLevelError";
|
|
46
|
+
}
|
|
47
|
+
level;
|
|
48
|
+
kind = "Server";
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// levels.ts
|
|
52
|
+
var LEVEL_SEVERITY = {
|
|
53
|
+
debug: 10,
|
|
54
|
+
info: 20,
|
|
55
|
+
notice: 30,
|
|
56
|
+
warning: 40,
|
|
57
|
+
error: 50,
|
|
58
|
+
critical: 60,
|
|
59
|
+
alert: 70,
|
|
60
|
+
emergency: 80
|
|
61
|
+
};
|
|
62
|
+
function assertLogLevel(level2) {
|
|
63
|
+
if (typeof level2 !== "string" || !Object.hasOwn(LEVEL_SEVERITY, level2)) throw new InvalidLogLevelError(String(level2));
|
|
64
|
+
}
|
|
65
|
+
function meetsLevel(level2, minimum) {
|
|
66
|
+
return LEVEL_SEVERITY[level2] >= LEVEL_SEVERITY[minimum];
|
|
67
|
+
}
|
|
68
|
+
function serializeContext(context) {
|
|
69
|
+
if (!context) return {};
|
|
70
|
+
const result = {};
|
|
71
|
+
for (const [key, value] of Object.entries(context)) {
|
|
72
|
+
result[key] = value instanceof Error ? { name: value.name, message: value.message, stack: value.stack } : value;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// BaseLogger.ts
|
|
78
|
+
var BaseLogger = class {
|
|
79
|
+
constructor(minimumLevel = "debug") {
|
|
80
|
+
this.minimumLevel = minimumLevel;
|
|
81
|
+
assertLogLevel(minimumLevel);
|
|
82
|
+
}
|
|
83
|
+
minimumLevel;
|
|
84
|
+
log(level2, message, context) {
|
|
85
|
+
if (!meetsLevel(level2, this.minimumLevel)) return;
|
|
86
|
+
this.write(level2, message, serializeContext({ ...currentLogContext(), ...context }));
|
|
87
|
+
}
|
|
88
|
+
emergency(message, context) {
|
|
89
|
+
this.log("emergency", message, context);
|
|
90
|
+
}
|
|
91
|
+
alert(message, context) {
|
|
92
|
+
this.log("alert", message, context);
|
|
93
|
+
}
|
|
94
|
+
critical(message, context) {
|
|
95
|
+
this.log("critical", message, context);
|
|
96
|
+
}
|
|
97
|
+
error(message, context) {
|
|
98
|
+
this.log("error", message, context);
|
|
99
|
+
}
|
|
100
|
+
warning(message, context) {
|
|
101
|
+
this.log("warning", message, context);
|
|
102
|
+
}
|
|
103
|
+
notice(message, context) {
|
|
104
|
+
this.log("notice", message, context);
|
|
105
|
+
}
|
|
106
|
+
info(message, context) {
|
|
107
|
+
this.log("info", message, context);
|
|
108
|
+
}
|
|
109
|
+
debug(message, context) {
|
|
110
|
+
this.log("debug", message, context);
|
|
111
|
+
}
|
|
112
|
+
withContext(context) {
|
|
113
|
+
mergeLogContext(context);
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// channels.ts
|
|
119
|
+
import pino2 from "pino";
|
|
120
|
+
|
|
121
|
+
// DailyRotatingStream.ts
|
|
122
|
+
import { createWriteStream, mkdirSync, readdirSync, rmSync } from "fs";
|
|
123
|
+
import { basename, dirname, extname, join } from "path";
|
|
124
|
+
import { Writable } from "stream";
|
|
125
|
+
|
|
126
|
+
// writeFailure.ts
|
|
127
|
+
function reportLogWriteFailure(path, error) {
|
|
128
|
+
process.stderr.write(`Unable to write log file ${path}: ${error.message}
|
|
129
|
+
`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// DailyRotatingStream.ts
|
|
133
|
+
function localDay(date) {
|
|
134
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
135
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
136
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
137
|
+
}
|
|
138
|
+
var DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
139
|
+
var DailyRotatingStream = class extends Writable {
|
|
140
|
+
constructor(basePath, days, now = () => /* @__PURE__ */ new Date()) {
|
|
141
|
+
super();
|
|
142
|
+
this.days = days;
|
|
143
|
+
this.now = now;
|
|
144
|
+
this.dir = dirname(basePath);
|
|
145
|
+
this.stem = basename(basePath, extname(basePath) || void 0);
|
|
146
|
+
mkdirSync(this.dir, { recursive: true });
|
|
147
|
+
}
|
|
148
|
+
days;
|
|
149
|
+
now;
|
|
150
|
+
dir;
|
|
151
|
+
stem;
|
|
152
|
+
currentDate = "";
|
|
153
|
+
stream;
|
|
154
|
+
/**
|
|
155
|
+
* The in-flight `_write()`'s callback, if any, tagged with the exact child stream it was issued for. Resolved
|
|
156
|
+
* either by that stream's own write completing or by that same stream's `'error'` listener, whichever comes
|
|
157
|
+
* first, so a write can never hang on a broken destination. Scoping it to `stream` (rather than just tracking
|
|
158
|
+
* "the current callback") matters across a rollover: a superseded stream can still emit a late `'error'` (e.g.
|
|
159
|
+
* a failed flush during its fire-and-forget `end()`) after a write is already pending on the *new* stream, and
|
|
160
|
+
* that stale error must only produce its own stderr notice, never resolve someone else's pending write.
|
|
161
|
+
*/
|
|
162
|
+
pending;
|
|
163
|
+
pathFor(date) {
|
|
164
|
+
return join(this.dir, `${this.stem}-${date}.log`);
|
|
165
|
+
}
|
|
166
|
+
today() {
|
|
167
|
+
return localDay(this.now());
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Opens the file at `path` and attaches an `'error'` listener so an I/O failure (disk full, EACCES, EISDIR, ...)
|
|
171
|
+
* on this one child stream can never crash the process: it's reported as a one-line notice on `process.stderr`,
|
|
172
|
+
* the stream is dropped (the next write reopens it), and it is never re-emitted on `this`.
|
|
173
|
+
*
|
|
174
|
+
* `protected` rather than `private` only so a test can subclass and capture the real child streams this opens
|
|
175
|
+
* (node:fs's ESM module namespace can't be `vi.spyOn()`'d), to simulate a stream retired by rollover emitting a
|
|
176
|
+
* late error while a write is already pending on its replacement.
|
|
177
|
+
*/
|
|
178
|
+
openStream(path) {
|
|
179
|
+
const stream = createWriteStream(path, { flags: "a" });
|
|
180
|
+
stream.on("error", (error) => {
|
|
181
|
+
reportLogWriteFailure(path, error);
|
|
182
|
+
if (this.stream === stream) this.stream = void 0;
|
|
183
|
+
if (this.pending?.stream === stream) {
|
|
184
|
+
const { callback } = this.pending;
|
|
185
|
+
this.pending = void 0;
|
|
186
|
+
callback();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return stream;
|
|
190
|
+
}
|
|
191
|
+
ensureStream() {
|
|
192
|
+
const date = this.today();
|
|
193
|
+
const dateChanged = date !== this.currentDate;
|
|
194
|
+
if (dateChanged || !this.stream) {
|
|
195
|
+
this.stream?.end();
|
|
196
|
+
this.currentDate = date;
|
|
197
|
+
this.stream = this.openStream(this.pathFor(date));
|
|
198
|
+
if (dateChanged) this.prune();
|
|
199
|
+
}
|
|
200
|
+
return this.stream;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Deletes this channel's files dated before the oldest of the `days` most recent local days (today included).
|
|
204
|
+
* Only names that are exactly `<stem>-<YYYY-MM-DD>.log` count, so a sibling channel sharing the prefix
|
|
205
|
+
* (e.g. `oriel-worker-<date>.log` next to `oriel-<date>.log`) is never touched.
|
|
206
|
+
*/
|
|
207
|
+
prune() {
|
|
208
|
+
if (this.days <= 0) return;
|
|
209
|
+
const prefix = `${this.stem}-`;
|
|
210
|
+
const now = this.now();
|
|
211
|
+
const cutoff = new Date(now.getFullYear(), now.getMonth(), now.getDate() - (this.days - 1)).getTime();
|
|
212
|
+
for (const file of readdirSync(this.dir)) {
|
|
213
|
+
if (!file.startsWith(prefix) || !file.endsWith(".log")) continue;
|
|
214
|
+
const match = DATE_PATTERN.exec(file.slice(prefix.length, -".log".length));
|
|
215
|
+
if (!match) continue;
|
|
216
|
+
const time = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3])).getTime();
|
|
217
|
+
if (time < cutoff) rmSync(join(this.dir, file), { force: true });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
_write(chunk, encoding, callback) {
|
|
221
|
+
const stream = this.ensureStream();
|
|
222
|
+
this.pending = { stream, callback: () => callback() };
|
|
223
|
+
stream.write(chunk, encoding, () => {
|
|
224
|
+
if (this.pending?.stream === stream) {
|
|
225
|
+
this.pending = void 0;
|
|
226
|
+
callback();
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
_final(callback) {
|
|
231
|
+
const stream = this.stream;
|
|
232
|
+
if (!stream) {
|
|
233
|
+
callback();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
let done = false;
|
|
237
|
+
const finish = () => {
|
|
238
|
+
if (done) return;
|
|
239
|
+
done = true;
|
|
240
|
+
callback();
|
|
241
|
+
};
|
|
242
|
+
stream.once("finish", finish);
|
|
243
|
+
stream.once("error", finish);
|
|
244
|
+
stream.end();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// PinoLogger.ts
|
|
249
|
+
import "pino";
|
|
250
|
+
var PINO_METHOD = {
|
|
251
|
+
emergency: "fatal",
|
|
252
|
+
alert: "fatal",
|
|
253
|
+
critical: "fatal",
|
|
254
|
+
error: "error",
|
|
255
|
+
warning: "warn",
|
|
256
|
+
notice: "info",
|
|
257
|
+
info: "info",
|
|
258
|
+
debug: "debug"
|
|
259
|
+
};
|
|
260
|
+
var PinoLogger = class extends BaseLogger {
|
|
261
|
+
constructor(pinoInstance, minimumLevel = "debug") {
|
|
262
|
+
super(minimumLevel);
|
|
263
|
+
this.pinoInstance = pinoInstance;
|
|
264
|
+
}
|
|
265
|
+
pinoInstance;
|
|
266
|
+
write(level2, message, context) {
|
|
267
|
+
this.pinoInstance[PINO_METHOD[level2]]({ ...context, rfc5424Level: level2 }, message);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// channels.ts
|
|
272
|
+
var PINO_OPTIONS = { level: "debug" };
|
|
273
|
+
function createSingleChannel(path, minimumLevel = "debug") {
|
|
274
|
+
assertLogLevel(minimumLevel);
|
|
275
|
+
const destination = pino2.destination({ dest: path, mkdir: true, sync: false });
|
|
276
|
+
destination.on("error", (error) => reportLogWriteFailure(path, error));
|
|
277
|
+
return new PinoLogger(pino2(PINO_OPTIONS, destination), minimumLevel);
|
|
278
|
+
}
|
|
279
|
+
function createDailyChannel(path, days = 14, minimumLevel = "debug", now) {
|
|
280
|
+
assertLogLevel(minimumLevel);
|
|
281
|
+
const stream = new DailyRotatingStream(path, days, now);
|
|
282
|
+
return new PinoLogger(pino2(PINO_OPTIONS, stream), minimumLevel);
|
|
283
|
+
}
|
|
284
|
+
function createStderrChannel(minimumLevel = "debug") {
|
|
285
|
+
assertLogLevel(minimumLevel);
|
|
286
|
+
const destination = pino2.destination({ dest: 2, sync: false });
|
|
287
|
+
destination.on("error", () => {
|
|
288
|
+
});
|
|
289
|
+
return new PinoLogger(pino2(PINO_OPTIONS, destination), minimumLevel);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// facade.ts
|
|
293
|
+
import { LogManager as LogManagerToken } from "@orieljs/contracts";
|
|
294
|
+
import { inject } from "@orieljs/container";
|
|
295
|
+
import { facade } from "@orieljs/support";
|
|
296
|
+
var Log = facade(LogManagerToken);
|
|
297
|
+
function logger(message, context) {
|
|
298
|
+
const manager = inject(LogManagerToken);
|
|
299
|
+
if (message === void 0) return manager;
|
|
300
|
+
manager.debug(message, context);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// LogManager.ts
|
|
304
|
+
import { ConfigRepository } from "@orieljs/contracts";
|
|
305
|
+
|
|
306
|
+
// NullLogger.ts
|
|
307
|
+
var NullLogger = class extends BaseLogger {
|
|
308
|
+
write() {
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// StackLogger.ts
|
|
313
|
+
var StackLogger = class {
|
|
314
|
+
constructor(channels) {
|
|
315
|
+
this.channels = channels;
|
|
316
|
+
}
|
|
317
|
+
channels;
|
|
318
|
+
log(level2, message, context) {
|
|
319
|
+
for (const channel of this.channels) channel.log(level2, message, context);
|
|
320
|
+
}
|
|
321
|
+
emergency(message, context) {
|
|
322
|
+
this.log("emergency", message, context);
|
|
323
|
+
}
|
|
324
|
+
alert(message, context) {
|
|
325
|
+
this.log("alert", message, context);
|
|
326
|
+
}
|
|
327
|
+
critical(message, context) {
|
|
328
|
+
this.log("critical", message, context);
|
|
329
|
+
}
|
|
330
|
+
error(message, context) {
|
|
331
|
+
this.log("error", message, context);
|
|
332
|
+
}
|
|
333
|
+
warning(message, context) {
|
|
334
|
+
this.log("warning", message, context);
|
|
335
|
+
}
|
|
336
|
+
notice(message, context) {
|
|
337
|
+
this.log("notice", message, context);
|
|
338
|
+
}
|
|
339
|
+
info(message, context) {
|
|
340
|
+
this.log("info", message, context);
|
|
341
|
+
}
|
|
342
|
+
debug(message, context) {
|
|
343
|
+
this.log("debug", message, context);
|
|
344
|
+
}
|
|
345
|
+
/** Context is scoped by the container (see context.ts), not per-instance, so this affects every channel. */
|
|
346
|
+
withContext(context) {
|
|
347
|
+
mergeLogContext(context);
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// LogManager.ts
|
|
353
|
+
var level = (config) => config.level ?? "debug";
|
|
354
|
+
var LogManager = class {
|
|
355
|
+
constructor(container) {
|
|
356
|
+
this.container = container;
|
|
357
|
+
this.drivers.set("single", (config) => createSingleChannel(String(config.path ?? ""), level(config)));
|
|
358
|
+
this.drivers.set("daily", (config) => createDailyChannel(String(config.path ?? ""), Number(config.days ?? 14), level(config)));
|
|
359
|
+
this.drivers.set("stderr", (config) => createStderrChannel(level(config)));
|
|
360
|
+
this.drivers.set("null", () => new NullLogger());
|
|
361
|
+
this.drivers.set("stack", (config) => this.stack(config.channels ?? []));
|
|
362
|
+
}
|
|
363
|
+
container;
|
|
364
|
+
channels = /* @__PURE__ */ new Map();
|
|
365
|
+
drivers = /* @__PURE__ */ new Map();
|
|
366
|
+
resolving = /* @__PURE__ */ new Set();
|
|
367
|
+
loggingConfig() {
|
|
368
|
+
return this.container.make(ConfigRepository).get("logging", { default: "stack", channels: {} });
|
|
369
|
+
}
|
|
370
|
+
channel(name) {
|
|
371
|
+
const loggingConfig = this.loggingConfig();
|
|
372
|
+
const channelName = name ?? loggingConfig.default;
|
|
373
|
+
let channel = this.channels.get(channelName);
|
|
374
|
+
if (!channel) {
|
|
375
|
+
if (this.resolving.has(channelName)) throw new LogChannelCycleError(channelName);
|
|
376
|
+
const channelConfig = loggingConfig.channels[channelName];
|
|
377
|
+
if (!channelConfig) throw new UnknownLogChannelError(channelName);
|
|
378
|
+
const driverName = channelConfig.driver;
|
|
379
|
+
const driver = driverName ? this.drivers.get(driverName) : void 0;
|
|
380
|
+
if (!driver) throw new UnknownLogDriverError(String(driverName));
|
|
381
|
+
this.resolving.add(channelName);
|
|
382
|
+
try {
|
|
383
|
+
channel = driver(channelConfig);
|
|
384
|
+
} finally {
|
|
385
|
+
this.resolving.delete(channelName);
|
|
386
|
+
}
|
|
387
|
+
this.channels.set(channelName, channel);
|
|
388
|
+
}
|
|
389
|
+
return channel;
|
|
390
|
+
}
|
|
391
|
+
stack(channels) {
|
|
392
|
+
return new StackLogger(channels.map((name) => this.channel(name)));
|
|
393
|
+
}
|
|
394
|
+
log(logLevel, message, context) {
|
|
395
|
+
this.channel().log(logLevel, message, context);
|
|
396
|
+
}
|
|
397
|
+
emergency(message, context) {
|
|
398
|
+
this.channel().emergency(message, context);
|
|
399
|
+
}
|
|
400
|
+
alert(message, context) {
|
|
401
|
+
this.channel().alert(message, context);
|
|
402
|
+
}
|
|
403
|
+
critical(message, context) {
|
|
404
|
+
this.channel().critical(message, context);
|
|
405
|
+
}
|
|
406
|
+
error(message, context) {
|
|
407
|
+
this.channel().error(message, context);
|
|
408
|
+
}
|
|
409
|
+
warning(message, context) {
|
|
410
|
+
this.channel().warning(message, context);
|
|
411
|
+
}
|
|
412
|
+
notice(message, context) {
|
|
413
|
+
this.channel().notice(message, context);
|
|
414
|
+
}
|
|
415
|
+
info(message, context) {
|
|
416
|
+
this.channel().info(message, context);
|
|
417
|
+
}
|
|
418
|
+
debug(message, context) {
|
|
419
|
+
this.channel().debug(message, context);
|
|
420
|
+
}
|
|
421
|
+
withContext(context) {
|
|
422
|
+
mergeLogContext(context);
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// LogServiceProvider.ts
|
|
428
|
+
import { LogManager as LogManagerToken3 } from "@orieljs/contracts";
|
|
429
|
+
import { ServiceProvider } from "@orieljs/support";
|
|
430
|
+
var LogServiceProvider = class extends ServiceProvider {
|
|
431
|
+
register() {
|
|
432
|
+
const level2 = process.env.LOG_LEVEL ?? "debug";
|
|
433
|
+
this.mergeConfigFrom(
|
|
434
|
+
{
|
|
435
|
+
default: process.env.LOG_CHANNEL ?? "stack",
|
|
436
|
+
channels: {
|
|
437
|
+
stack: { driver: "stack", channels: (process.env.LOG_STACK ?? "single").split(",") },
|
|
438
|
+
single: { driver: "single", path: this.app.storagePath("logs/oriel.log"), level: level2 },
|
|
439
|
+
daily: { driver: "daily", path: this.app.storagePath("logs/oriel.log"), level: level2, days: 14 },
|
|
440
|
+
stderr: { driver: "stderr", level: level2 },
|
|
441
|
+
null: { driver: "null" }
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
"logging"
|
|
445
|
+
);
|
|
446
|
+
this.app.singleton(LogManagerToken3, (container) => new LogManager(container));
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
export {
|
|
450
|
+
BaseLogger,
|
|
451
|
+
DailyRotatingStream,
|
|
452
|
+
InvalidLogLevelError,
|
|
453
|
+
LEVEL_SEVERITY,
|
|
454
|
+
Log,
|
|
455
|
+
LogChannelCycleError,
|
|
456
|
+
LogManager,
|
|
457
|
+
LogServiceProvider,
|
|
458
|
+
NullLogger,
|
|
459
|
+
PinoLogger,
|
|
460
|
+
StackLogger,
|
|
461
|
+
UnknownLogChannelError,
|
|
462
|
+
UnknownLogDriverError,
|
|
463
|
+
createDailyChannel,
|
|
464
|
+
createSingleChannel,
|
|
465
|
+
createStderrChannel,
|
|
466
|
+
currentLogContext,
|
|
467
|
+
logger,
|
|
468
|
+
meetsLevel,
|
|
469
|
+
mergeLogContext,
|
|
470
|
+
serializeContext
|
|
471
|
+
};
|
|
472
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../context.ts","../errors.ts","../levels.ts","../BaseLogger.ts","../channels.ts","../DailyRotatingStream.ts","../writeFailure.ts","../PinoLogger.ts","../facade.ts","../LogManager.ts","../NullLogger.ts","../StackLogger.ts","../LogServiceProvider.ts"],"sourcesContent":["import { currentContainer } from '@orieljs/container'\n\n/** Used as the WeakMap key when there is no current container at all (context added outside any scope). */\nconst rootKey: object = {}\n\n/**\n * Log context, keyed by the current scope. `Application.handle()` creates a fresh child container per request\n * (`this.createScope()`) and runs the kernel inside `scope.run(...)`, so `currentContainer()` returns a distinct\n * object per in-flight request; two concurrent requests never share a key here, so context added during one never\n * leaks into the other. Outside of any scope (CLI, boot), everything shares `rootKey`.\n */\nconst contexts = new WeakMap<object, Record<string, unknown>>()\n\n/** Merges `context` into the log context for the current scope (Laravel's `Log::withContext()`). */\nexport function mergeLogContext(context: Record<string, unknown>): void {\n const key = currentContainer() ?? rootKey\n contexts.set(key, { ...contexts.get(key), ...context })\n}\n\n/** The merged log context for the current scope, or `{}` if none has been added. */\nexport function currentLogContext(): Record<string, unknown> {\n return contexts.get(currentContainer() ?? rootKey) ?? {}\n}\n","import type { ErrorKind, OrielError } from '@orieljs/contracts'\n\nexport class UnknownLogChannelError extends Error implements OrielError {\n readonly kind: ErrorKind = 'Server'\n constructor(readonly channel: string) {\n super(`Log channel [${channel}] is not defined in config('logging.channels').`)\n this.name = 'UnknownLogChannelError'\n }\n}\n\nexport class UnknownLogDriverError extends Error implements OrielError {\n readonly kind: ErrorKind = 'Server'\n constructor(readonly driver: string) {\n super(`Log driver [${driver}] is not registered.`)\n this.name = 'UnknownLogDriverError'\n }\n}\n\nexport class LogChannelCycleError extends Error implements OrielError {\n readonly kind: ErrorKind = 'Server'\n constructor(readonly channel: string) {\n super(`Log channel [${channel}] includes itself.`)\n this.name = 'LogChannelCycleError'\n }\n}\n\nexport class InvalidLogLevelError extends Error implements OrielError {\n readonly kind: ErrorKind = 'Server'\n constructor(readonly level: string) {\n super(`Invalid log level [${level}].`)\n this.name = 'InvalidLogLevelError'\n }\n}\n","import type { LogLevel } from '@orieljs/contracts'\nimport { InvalidLogLevelError } from './errors'\n\n/** RFC 5424 severities, most severe first. Higher numbers are more severe. */\nexport const LEVEL_SEVERITY: Record<LogLevel, number> = {\n debug: 10,\n info: 20,\n notice: 30,\n warning: 40,\n error: 50,\n critical: 60,\n alert: 70,\n emergency: 80,\n}\n\n/** Throws `InvalidLogLevelError` unless `level` is one of the eight RFC 5424 names (no aliases like `warn`). */\nexport function assertLogLevel(level: unknown): asserts level is LogLevel {\n if (typeof level !== 'string' || !Object.hasOwn(LEVEL_SEVERITY, level)) throw new InvalidLogLevelError(String(level))\n}\n\n/** True when `level` is at least as severe as `minimum` (e.g. `error` meets a `warning` threshold). */\nexport function meetsLevel(level: LogLevel, minimum: LogLevel): boolean {\n return LEVEL_SEVERITY[level] >= LEVEL_SEVERITY[minimum]\n}\n\n/**\n * `Error` objects don't survive `JSON.stringify` (message/stack/name aren't own enumerable properties), so any\n * `Error` values directly on the context object are expanded one level deep into a plain `{ name, message, stack }`.\n * This is how `LogManager.error(message, { exception })` (Http's exception handler) ends up readable in log output.\n */\nexport function serializeContext(context: Record<string, unknown> | undefined): Record<string, unknown> {\n if (!context) return {}\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(context)) {\n result[key] = value instanceof Error ? { name: value.name, message: value.message, stack: value.stack } : value\n }\n return result\n}\n","import type { Logger, LogLevel } from '@orieljs/contracts'\nimport { currentLogContext, mergeLogContext } from './context'\nimport { assertLogLevel, meetsLevel, serializeContext } from './levels'\n\n/**\n * Implements the full `Logger` contract on top of one `write()` method: level filtering, merging in the current\n * scope's context (`context.ts`) and serializing `Error` values (`levels.ts`) all happen here, once.\n */\nexport abstract class BaseLogger implements Logger {\n constructor(protected readonly minimumLevel: LogLevel = 'debug') {\n assertLogLevel(minimumLevel)\n }\n\n log(level: LogLevel, message: string, context?: Record<string, unknown>): void {\n if (!meetsLevel(level, this.minimumLevel)) return\n this.write(level, message, serializeContext({ ...currentLogContext(), ...context }))\n }\n\n emergency(message: string, context?: Record<string, unknown>): void {\n this.log('emergency', message, context)\n }\n alert(message: string, context?: Record<string, unknown>): void {\n this.log('alert', message, context)\n }\n critical(message: string, context?: Record<string, unknown>): void {\n this.log('critical', message, context)\n }\n error(message: string, context?: Record<string, unknown>): void {\n this.log('error', message, context)\n }\n warning(message: string, context?: Record<string, unknown>): void {\n this.log('warning', message, context)\n }\n notice(message: string, context?: Record<string, unknown>): void {\n this.log('notice', message, context)\n }\n info(message: string, context?: Record<string, unknown>): void {\n this.log('info', message, context)\n }\n debug(message: string, context?: Record<string, unknown>): void {\n this.log('debug', message, context)\n }\n\n withContext(context: Record<string, unknown>): this {\n mergeLogContext(context)\n return this\n }\n\n /** Called only when `level` already meets this logger's configured minimum, with context fully resolved. */\n protected abstract write(level: LogLevel, message: string, context: Record<string, unknown>): void\n}\n","import pino from 'pino'\nimport type { LogLevel } from '@orieljs/contracts'\nimport { DailyRotatingStream } from './DailyRotatingStream'\nimport { assertLogLevel } from './levels'\nimport { PinoLogger } from './PinoLogger'\nimport { reportLogWriteFailure } from './writeFailure'\n\n/** Pino passes everything through; `BaseLogger` already filtered by the channel's own minimum level. */\nconst PINO_OPTIONS = { level: 'debug' } as const\n\n/** The `single` channel: everything appended to one file, e.g. `storage/logs/oriel.log`. */\nexport function createSingleChannel(path: string, minimumLevel: LogLevel = 'debug'): PinoLogger {\n assertLogLevel(minimumLevel) // before opening the file, so a rejected channel leaves nothing open\n const destination = pino.destination({ dest: path, mkdir: true, sync: false })\n // Without a listener, an I/O error on the destination (EACCES, ENOTDIR, disk full, ...) is re-emitted as an\n // unhandled 'error' event and takes the process down.\n destination.on('error', (error: Error) => reportLogWriteFailure(path, error))\n return new PinoLogger(pino(PINO_OPTIONS, destination), minimumLevel)\n}\n\n/** The `daily` channel: one file per day under the same directory, pruned after `days`. */\nexport function createDailyChannel(path: string, days = 14, minimumLevel: LogLevel = 'debug', now?: () => Date): PinoLogger {\n assertLogLevel(minimumLevel)\n const stream = new DailyRotatingStream(path, days, now)\n return new PinoLogger(pino(PINO_OPTIONS, stream), minimumLevel)\n}\n\n/** The `stderr` channel. */\nexport function createStderrChannel(minimumLevel: LogLevel = 'debug'): PinoLogger {\n assertLogLevel(minimumLevel)\n const destination = pino.destination({ dest: 2, sync: false })\n // Nowhere left to report a failure writing to stderr itself, so it's swallowed rather than crashing the process.\n destination.on('error', () => {})\n return new PinoLogger(pino(PINO_OPTIONS, destination), minimumLevel)\n}\n","import { createWriteStream, mkdirSync, readdirSync, rmSync, type WriteStream } from 'node:fs'\nimport { basename, dirname, extname, join } from 'node:path'\nimport { Writable } from 'node:stream'\nimport { reportLogWriteFailure } from './writeFailure'\n\n/** `YYYY-MM-DD` for the local calendar day of `date`. */\nfunction localDay(date: Date): string {\n const month = String(date.getMonth() + 1).padStart(2, '0')\n const day = String(date.getDate()).padStart(2, '0')\n return `${date.getFullYear()}-${month}-${day}`\n}\n\nconst DATE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/\n\n/**\n * Writes to `<dir>/<stem>-<YYYY-MM-DD>.log`, switching files when the local calendar day changes and deleting files\n * older than `days` each time it rolls over. `now` is injectable so tests can simulate day boundaries without a\n * fake timer.\n */\nexport class DailyRotatingStream extends Writable {\n private readonly dir: string\n private readonly stem: string\n private currentDate = ''\n private stream: WriteStream | undefined\n /**\n * The in-flight `_write()`'s callback, if any, tagged with the exact child stream it was issued for. Resolved\n * either by that stream's own write completing or by that same stream's `'error'` listener, whichever comes\n * first, so a write can never hang on a broken destination. Scoping it to `stream` (rather than just tracking\n * \"the current callback\") matters across a rollover: a superseded stream can still emit a late `'error'` (e.g.\n * a failed flush during its fire-and-forget `end()`) after a write is already pending on the *new* stream, and\n * that stale error must only produce its own stderr notice, never resolve someone else's pending write.\n */\n private pending: { readonly stream: WriteStream; readonly callback: () => void } | undefined\n\n constructor(\n basePath: string,\n private readonly days: number,\n private readonly now: () => Date = () => new Date(),\n ) {\n super()\n this.dir = dirname(basePath)\n this.stem = basename(basePath, extname(basePath) || undefined)\n mkdirSync(this.dir, { recursive: true })\n }\n\n private pathFor(date: string): string {\n return join(this.dir, `${this.stem}-${date}.log`)\n }\n\n private today(): string {\n return localDay(this.now())\n }\n\n /**\n * Opens the file at `path` and attaches an `'error'` listener so an I/O failure (disk full, EACCES, EISDIR, ...)\n * on this one child stream can never crash the process: it's reported as a one-line notice on `process.stderr`,\n * the stream is dropped (the next write reopens it), and it is never re-emitted on `this`.\n *\n * `protected` rather than `private` only so a test can subclass and capture the real child streams this opens\n * (node:fs's ESM module namespace can't be `vi.spyOn()`'d), to simulate a stream retired by rollover emitting a\n * late error while a write is already pending on its replacement.\n */\n protected openStream(path: string): WriteStream {\n const stream = createWriteStream(path, { flags: 'a' })\n stream.on('error', (error: Error) => {\n reportLogWriteFailure(path, error)\n if (this.stream === stream) this.stream = undefined\n if (this.pending?.stream === stream) {\n const { callback } = this.pending\n this.pending = undefined\n callback()\n }\n })\n return stream\n }\n\n private ensureStream(): WriteStream {\n const date = this.today()\n const dateChanged = date !== this.currentDate\n if (dateChanged || !this.stream) {\n this.stream?.end()\n this.currentDate = date\n this.stream = this.openStream(this.pathFor(date))\n if (dateChanged) this.prune()\n }\n return this.stream\n }\n\n /**\n * Deletes this channel's files dated before the oldest of the `days` most recent local days (today included).\n * Only names that are exactly `<stem>-<YYYY-MM-DD>.log` count, so a sibling channel sharing the prefix\n * (e.g. `oriel-worker-<date>.log` next to `oriel-<date>.log`) is never touched.\n */\n private prune(): void {\n if (this.days <= 0) return\n const prefix = `${this.stem}-`\n const now = this.now()\n const cutoff = new Date(now.getFullYear(), now.getMonth(), now.getDate() - (this.days - 1)).getTime()\n for (const file of readdirSync(this.dir)) {\n if (!file.startsWith(prefix) || !file.endsWith('.log')) continue\n const match = DATE_PATTERN.exec(file.slice(prefix.length, -'.log'.length))\n if (!match) continue\n const time = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3])).getTime()\n if (time < cutoff) rmSync(join(this.dir, file), { force: true })\n }\n }\n\n override _write(chunk: unknown, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n const stream = this.ensureStream()\n this.pending = { stream, callback: () => callback() }\n stream.write(chunk as Uint8Array, encoding, () => {\n if (this.pending?.stream === stream) {\n this.pending = undefined\n callback()\n }\n })\n }\n\n override _final(callback: (error?: Error | null) => void): void {\n const stream = this.stream\n if (!stream) {\n callback()\n return\n }\n let done = false\n const finish = () => {\n if (done) return\n done = true\n callback()\n }\n stream.once('finish', finish)\n stream.once('error', finish)\n stream.end()\n }\n}\n","/** Reports a log destination I/O failure as one line on `process.stderr`, so it never crashes the process. */\nexport function reportLogWriteFailure(path: string, error: Error): void {\n process.stderr.write(`Unable to write log file ${path}: ${error.message}\\n`)\n}\n","import pino from 'pino'\nimport type { LogLevel } from '@orieljs/contracts'\nimport { BaseLogger } from './BaseLogger'\n\n/** Maps an RFC 5424 level onto pino's own (narrower) level methods. The real level is kept in the payload. */\nconst PINO_METHOD: Record<LogLevel, 'fatal' | 'error' | 'warn' | 'info' | 'debug'> = {\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\n/** A channel backed by a pino logger writing to an arbitrary destination stream (file, stderr, ...). */\nexport class PinoLogger extends BaseLogger {\n constructor(\n private readonly pinoInstance: pino.Logger,\n minimumLevel: LogLevel = 'debug',\n ) {\n super(minimumLevel)\n }\n\n protected write(level: LogLevel, message: string, context: Record<string, unknown>): void {\n this.pinoInstance[PINO_METHOD[level]]({ ...context, rfc5424Level: level }, message)\n }\n}\n","import type { LogManager } from '@orieljs/contracts'\nimport { LogManager as LogManagerToken } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { facade } from '@orieljs/support'\n\n/** The `Log` facade (Laravel's `Illuminate\\Support\\Facades\\Log`). `Log.channel('single').info(...)`. */\nexport const Log = facade<LogManager>(LogManagerToken)\n\n/** With no args, the LogManager itself. With a message, logs it at `debug` (Laravel's `logger()` helper). */\nexport function logger(): LogManager\nexport function logger(message: string, context?: Record<string, unknown>): void\nexport function logger(message?: string, context?: Record<string, unknown>): LogManager | void {\n const manager = inject(LogManagerToken)\n if (message === undefined) return manager\n manager.debug(message, context)\n}\n","import type { Container, Logger, LogLevel } from '@orieljs/contracts'\nimport { ConfigRepository, LogManager as LogManagerToken } from '@orieljs/contracts'\nimport { createDailyChannel, createSingleChannel, createStderrChannel } from './channels'\nimport { mergeLogContext } from './context'\nimport { LogChannelCycleError, UnknownLogChannelError, UnknownLogDriverError } from './errors'\nimport { NullLogger } from './NullLogger'\nimport { StackLogger } from './StackLogger'\n\ntype ChannelConfig = Record<string, unknown>\ntype Driver = (config: ChannelConfig) => Logger\n\ninterface LoggingConfig {\n default: string\n channels: Record<string, ChannelConfig>\n}\n\nconst level = (config: ChannelConfig): LogLevel => (config.level as LogLevel | undefined) ?? 'debug'\n\n/** `LogManager`: resolves channels by name from `config('logging')`, lazily and cached. */\nexport class LogManager implements LogManagerToken {\n private readonly channels = new Map<string, Logger>()\n private readonly drivers = new Map<string, Driver>()\n private readonly resolving = new Set<string>()\n\n constructor(private readonly container: Container) {\n this.drivers.set('single', (config) => createSingleChannel(String(config.path ?? ''), level(config)))\n this.drivers.set('daily', (config) => createDailyChannel(String(config.path ?? ''), Number(config.days ?? 14), level(config)))\n this.drivers.set('stderr', (config) => createStderrChannel(level(config)))\n this.drivers.set('null', () => new NullLogger())\n this.drivers.set('stack', (config) => this.stack((config.channels as string[] | undefined) ?? []))\n }\n\n private loggingConfig(): LoggingConfig {\n return this.container.make(ConfigRepository).get<LoggingConfig>('logging', { default: 'stack', channels: {} })\n }\n\n channel(name?: string): Logger {\n const loggingConfig = this.loggingConfig()\n const channelName = name ?? loggingConfig.default\n let channel = this.channels.get(channelName)\n if (!channel) {\n if (this.resolving.has(channelName)) throw new LogChannelCycleError(channelName)\n const channelConfig = loggingConfig.channels[channelName]\n if (!channelConfig) throw new UnknownLogChannelError(channelName)\n const driverName = channelConfig.driver as string | undefined\n const driver = driverName ? this.drivers.get(driverName) : undefined\n if (!driver) throw new UnknownLogDriverError(String(driverName))\n this.resolving.add(channelName)\n try {\n channel = driver(channelConfig)\n } finally {\n this.resolving.delete(channelName)\n }\n this.channels.set(channelName, channel)\n }\n return channel\n }\n\n stack(channels: string[]): Logger {\n return new StackLogger(channels.map((name) => this.channel(name)))\n }\n\n log(logLevel: LogLevel, message: string, context?: Record<string, unknown>): void {\n this.channel().log(logLevel, message, context)\n }\n emergency(message: string, context?: Record<string, unknown>): void {\n this.channel().emergency(message, context)\n }\n alert(message: string, context?: Record<string, unknown>): void {\n this.channel().alert(message, context)\n }\n critical(message: string, context?: Record<string, unknown>): void {\n this.channel().critical(message, context)\n }\n error(message: string, context?: Record<string, unknown>): void {\n this.channel().error(message, context)\n }\n warning(message: string, context?: Record<string, unknown>): void {\n this.channel().warning(message, context)\n }\n notice(message: string, context?: Record<string, unknown>): void {\n this.channel().notice(message, context)\n }\n info(message: string, context?: Record<string, unknown>): void {\n this.channel().info(message, context)\n }\n debug(message: string, context?: Record<string, unknown>): void {\n this.channel().debug(message, context)\n }\n\n withContext(context: Record<string, unknown>): this {\n mergeLogContext(context)\n return this\n }\n}\n","import { BaseLogger } from './BaseLogger'\n\n/** The `null` channel: discards every entry (Laravel's `NullHandler`). */\nexport class NullLogger extends BaseLogger {\n protected write(): void {\n // Intentionally does nothing.\n }\n}\n","import type { Logger, LogLevel } from '@orieljs/contracts'\nimport { mergeLogContext } from './context'\n\n/** `Log.stack([...])`: fans every entry out to each constituent channel, which does its own level filtering. */\nexport class StackLogger implements Logger {\n constructor(private readonly channels: Logger[]) {}\n\n log(level: LogLevel, message: string, context?: Record<string, unknown>): void {\n for (const channel of this.channels) channel.log(level, message, context)\n }\n emergency(message: string, context?: Record<string, unknown>): void {\n this.log('emergency', message, context)\n }\n alert(message: string, context?: Record<string, unknown>): void {\n this.log('alert', message, context)\n }\n critical(message: string, context?: Record<string, unknown>): void {\n this.log('critical', message, context)\n }\n error(message: string, context?: Record<string, unknown>): void {\n this.log('error', message, context)\n }\n warning(message: string, context?: Record<string, unknown>): void {\n this.log('warning', message, context)\n }\n notice(message: string, context?: Record<string, unknown>): void {\n this.log('notice', message, context)\n }\n info(message: string, context?: Record<string, unknown>): void {\n this.log('info', message, context)\n }\n debug(message: string, context?: Record<string, unknown>): void {\n this.log('debug', message, context)\n }\n\n /** Context is scoped by the container (see context.ts), not per-instance, so this affects every channel. */\n withContext(context: Record<string, unknown>): this {\n mergeLogContext(context)\n return this\n }\n}\n","import { LogManager as LogManagerToken } from '@orieljs/contracts'\nimport { ServiceProvider } from '@orieljs/support'\nimport { LogManager } from './LogManager'\n\n/** Binds the LogManager and merges Laravel 11's `logging` defaults (stack -> single, LOG_LEVEL=debug). */\nexport class LogServiceProvider extends ServiceProvider {\n override register(): void {\n const level = process.env.LOG_LEVEL ?? 'debug'\n this.mergeConfigFrom(\n {\n default: process.env.LOG_CHANNEL ?? 'stack',\n channels: {\n stack: { driver: 'stack', channels: (process.env.LOG_STACK ?? 'single').split(',') },\n single: { driver: 'single', path: this.app.storagePath('logs/oriel.log'), level },\n daily: { driver: 'daily', path: this.app.storagePath('logs/oriel.log'), level, days: 14 },\n stderr: { driver: 'stderr', level },\n null: { driver: 'null' },\n },\n },\n 'logging',\n )\n this.app.singleton(LogManagerToken, (container) => new LogManager(container))\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAGjC,IAAM,UAAkB,CAAC;AAQzB,IAAM,WAAW,oBAAI,QAAyC;AAGvD,SAAS,gBAAgB,SAAwC;AACtE,QAAM,MAAM,iBAAiB,KAAK;AAClC,WAAS,IAAI,KAAK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AM,EAAE,QAAQ,OAAO;AAAA,QACzB;AAAA,MACF;AAAA,MACA;AAAA,IACF;AACA,SAAK,IAAI,UAAUC,kBAAiB,CAAC,cAAc,IAAI,WAAW,SAAS,CAAC;AAAA,EAC9E;AACF;","names":["level","level","level","pino","level","pino","level","LogManagerToken","level","LogManagerToken"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orieljs/log",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "The Oriel Log component.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/orieljs/framework.git",
|
|
11
|
+
"directory": "src/Oriel/Log"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"NOTICE"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"pino": "10.3.1",
|
|
33
|
+
"@orieljs/contracts": "0.1.0-alpha.1",
|
|
34
|
+
"@orieljs/support": "0.1.0-alpha.1",
|
|
35
|
+
"@orieljs/container": "0.1.0-alpha.1"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup && node ../../../scripts/copy-license.mjs"
|
|
39
|
+
}
|
|
40
|
+
}
|