This commit is contained in:
2025-11-11 00:04:55 -06:00
parent a76ad41fde
commit 40538eddfd
6405 changed files with 1289756 additions and 0 deletions

201
node_modules/typescript-logging/LICENSE generated vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

224
node_modules/typescript-logging/README.md generated vendored Normal file
View File

@ -0,0 +1,224 @@
# TypeScript Logging
TypeScript logging can be used to add logging to your web or node project.
**_Version 2 of typescript-logging has been written from scratch and is not compatible with version 1 (see migration)._**
There are two different flavors available to use. Please visit the **documentation** of the links below and pick the one you
prefer.
* The [typescript-logging-category-style](./category-style/README.MD) flavor.
* The [typescript-logging-log4ts-style](./log4ts-style/README.MD) flavor.
**Node Channel (NEW)**
Supports logging to files and file rollover. Please see [typescript-logging-node-channel](./node-channel/README.MD) for details.
**Documentation**
The following sections are available:
* [Getting started](#getting-started)
* [Build](#build)
* [Tests](#tests)
* [Bugs](#bugs)
* [Contributing](#contributing)
* [Migration](#migration)
* [Changelog](#changelog)
**Using typescript-logging version 1?**
Please visit
[https://github.com/vauxite-org/typescript-logging/tree/release-1.x](https://github.com/vauxite-org/typescript-logging/tree/release-1.x)
for more details. Consider upgrading to the latest version.
**Version 2 of typescript-logging is _not_ compatible with version 1**
Please check the [migration](#migration) guide for more information.
## Getting started
For all details and documentation please visit the links above. The following sections provide a quick start only for
both flavors.
### Category style flavor
*To install the category-style flavor use the following npm commands:*
```shell
npm install --save typescript-logging # Core is required for any style
npm install --save typescript-logging-category-style
```
*Usage*
The following section configures a provider and exposes a getLogger function for other modules to use. The getLogger in
this example is used to create root categories.
```typescript
/*--- LogConfig.ts ---*/
import {CategoryProvider, Category} from "typescript-logging-category-style";
const provider = CategoryProvider.createProvider("ExampleProvider");
export function getLogger(name: string): Category {
return provider.getCategory(name);
}
```
----
```typescript
/*--- Person.ts ---*/
import {getLogger} from "./LogConfig";
/* Root categories can and probably will be defined elsewhere, this is just an example */
const logModel = getLogger("model");
/* Create child categories based on a parent category, effectively allowing you to create a tree of loggers when needed */
const logPerson = logModel.getChildCategory("Person");
function example(value: string) {
logPerson.debug(() => `Example function called with value ${value}`);
try {
// Awesome code here...
logPerson.getChildCategory("example()").debug(() => "Child category again");
}
catch (e) {
logPerson.error(() => "Awesome code failed unexpectedly", e);
}
finally {
logPerson.debug(() => "Example function completed");
}
}
```
### Log4ts flavor
*To install the log4ts-style flavor use the following npm commands:*
```shell
npm install --save typescript-logging # Core is required for any style
npm install --save typescript-logging-log4ts-style
```
*Usage*
The following section configures a provider and exposes a getLogger function for other modules to use.
```typescript
/*--- LogConfig.ts ---*/
import {LogLevel} from "typescript-logging";
import {Log4TSProvider, Logger} from "typescript-logging-log4ts-style";
const provider = Log4TSProvider.createProvider("ExampleProvider", {
/* Specify the various group expressions to match against */
groups: [{
expression: new RegExp("model.+"),
level: LogLevel.Debug, /* This group will log on debug instead */
}, {
expression: new RegExp("service.+"),
}],
});
export function getLogger(name: string): Logger {
return provider.getLogger(name);
}
```
----
```typescript
/*--- Person.ts ---*/
import {getLogger} from "./LogConfig";
const log = getLogger("model.Person")
function example(value: string) {
log.debug(() => `Example function called with value ${value}`);
try {
// Awesome code here...
}
catch (e) {
log.error(() => "Awesome code failed unexpectedly", e);
}
finally {
log.debug(() => "Example function completed");
}
}
```
## Build
Please make sure to have node 18 LTS installed.
To locally build the logging flavors. The easiest is to run the ./initialize.sh script:
```shell
./initialize.sh # Clean, install and build everything.
```
This will cleanly install and build your branch from scratch.
You can also manually install things, by going into the respective directories and manually type:
```shell
# If not installed yet
npm run ci
# or for the test projects
npm install
```
Any project when you're in the respective directory can be built with:
```shell
npm run build
```
That will clean, build and test the project.
## Tests
To locally run the tests, in the respective directories:
```shell
npm run test
```
## Integration tests
If you're on linux or mac-os, it's easiest to run initialize.sh first. Otherwise, skip that and run `npm run install`
manually as shown below.
```shell
# Linux/MacOS only - Cleans everything and re-installs packages, including those for the integration projects.
./initialize.sh
# If not using ./initialize.sh, note that the dependent projects must be built first (core and the various styles, see above)
npm run install # Run inside respective test-integration project, e.g. tests-integration/rollup
npm run build # Run inside respective test-integration project. Builds test webapp and runs cypress tests.
```
## Bugs
If you encounter a bug please log it in the issue tracker of this repository and make sure to specify what flavor
(style) you are using.
## Contributing
Feel free to contribute or come up with great ideas, please use the issue tracker for that.
If you add/change new functionality and want it merged in a later release, please open a pull request. Also add tests
for it (see various "test" directories).
Please keep in mind that things may not fit the library and in such case will be rejected, so if you are unsure please
ask first before wasting your valuable time.
# Migration
Please check the [migration guide](documentation/migration.md) if you are on an old version and wish to use the latest
version available.
## Changelog
Please check the [changelog](documentation/change_log.md)

View File

@ -0,0 +1,93 @@
import { ExceptionType } from "./type/ExceptionType";
import { LogLevel } from "./LogLevel";
import { LogMessageType } from "./type/LogMessageType";
import { LogId } from "./LogId";
import { LogRuntime } from "./runtime/LogRuntime";
/**
* Represents a Logger, should be used to log your messages (and errors).
* All methods accept a message and optionally an error and additional arguments.
*/
export interface CoreLogger {
/**
* Id by which this logger is identified (not relevant for an end user).
*/
readonly id: LogId;
/**
* The current log level of this logger (this is a convenience property, it returns runtimeSettings.logLevel).
*/
readonly logLevel: LogLevel;
/**
* The current runtime settings for this Logger.
*/
readonly runtimeSettings: LogRuntime;
/**
* Log a message on trace, for details please see {@link debug}.
*/
trace(message: LogMessageType, ...args: unknown[]): void;
/**
* Log a message on info, for details please see {@link debug}.
*/
trace(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
/**
* Log a message on debug. Followed by an optional Error, and optional arguments.
* @example
* ```
* log.debug("Hello");
* log.debug(() => "Hello");
* log.debug(() => "Hello", new Error("SomeError"));
* log.debug("Hello", "Some", "Random", "Arguments", [], 123);
* log.debug("Hello", new Error("AnotherError"), "Some", "Random", "Arguments", [], 123);
* ```
* @param message Message
* @param args Optional arguments (note the first argument can be a (caught) Error which is treated as such then)
*/
debug(message: LogMessageType, ...args: unknown[]): void;
/**
* Log a message on debug. Followed by an optional Error, and optional arguments.
* @example
* ```
* log.debug("Hello");
* log.debug(() => "Hello");
* log.debug(() => "Hello", new Error("SomeError"));
* log.debug("Hello", "Some", "Random", "Arguments", [], 123);
* log.debug("Hello", new Error("AnotherError"), "Some", "Random", "Arguments", [], 123);
* ```
* @param message Message
* @param error Error type (Error or lambda returning an Error)
* @param args Optional arguments (note the first argument can be a (caught) Error which is treated as such then)
*/
debug(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
/**
* Log a message on info, for details please see {@link debug}.
*/
info(message: LogMessageType, ...args: unknown[]): void;
/**
* Log a message on info, for details please see {@link debug}.
*/
info(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
/**
* Log a message on warn, for details please see {@link debug}.
*/
warn(message: LogMessageType, ...args: unknown[]): void;
/**
* Log a message on warn, for details please see {@link debug}.
*/
warn(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
/**
* Log a message on error, for details please see {@link debug}.
*/
error(message: LogMessageType, ...args: unknown[]): void;
/**
* Log a message on error, for details please see {@link debug}.
*/
error(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
/**
* Log a message on fatal, for details please see {@link debug}.
*/
fatal(message: LogMessageType, ...args: unknown[]): void;
/**
* Log a message on fatal, for details please see {@link debug}.
*/
fatal(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
}
//# sourceMappingURL=CoreLogger.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CoreLogger.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/CoreLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,UAAU;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IAErC;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE/E;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEzD;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE/E;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAExD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE9E;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAExD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE9E;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE/E;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAChF"}

View File

@ -0,0 +1,14 @@
import { LogMessage } from "./LogMessage";
/**
* Used to write a log message to, this is the default type of channel in use.
* Can be used to write an already fully formatted message.
*/
export interface LogChannel {
readonly type: "LogChannel";
/**
* Write a complete LogMessage away, the LogMessage is
* ready and formatted.
*/
readonly write: (msg: LogMessage) => void;
}
//# sourceMappingURL=LogChannel.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogChannel.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/LogChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,UAAU;IAEzB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;CAC3C"}

View File

@ -0,0 +1,5 @@
/**
* Identifier used by a Logger.
*/
export type LogId = string;
//# sourceMappingURL=LogId.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogId.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/LogId.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC"}

View File

@ -0,0 +1,20 @@
/**
* Log level for a logger.
*/
export declare enum LogLevel {
Trace = 0,
Debug = 1,
Info = 2,
Warn = 3,
Error = 4,
Fatal = 5,
Off = 6
}
export declare namespace LogLevel {
/**
* Convert given value to LogLevel, if not matching returns undefined.
* @param val Value to convert
*/
function toLogLevel(val: string): LogLevel | undefined;
}
//# sourceMappingURL=LogLevel.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogLevel.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/LogLevel.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAElB,KAAK,IAAI;IACT,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAGD,yBAAiB,QAAQ,CAAC;IAExB;;;OAGG;IACH,SAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAmB5D;CACF"}

View File

@ -0,0 +1,16 @@
/**
* The LogMessage to write away to a LogChannel. LogMessage is pre-formatted and ready to be written
* away. This is the message created for a LogChannel.
*/
export interface LogMessage {
/**
* The complete message to write away, including log level, timestamp, log name and additional arguments if any.
*/
readonly message: string;
/**
* The error if present. Contains the name of the error, the message, finally followed by the stack of the error
* if present.
*/
readonly error?: string;
}
//# sourceMappingURL=LogMessage.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogMessage.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/LogMessage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,UAAU;IAEzB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB"}

View File

@ -0,0 +1,29 @@
import { LoggerNameType } from "./type/LoggerNameType";
import { CoreLogger } from "./CoreLogger";
import { RuntimeSettings } from "./runtime/RuntimeSettings";
import { LogConfig } from "./config/LogConfig";
/**
* The LogProvider provides the bare minimum that various implementations can use.
* It is not meant for end usage.
*/
export interface LogProvider {
/**
* Returns the current settings for this provider.
*/
readonly runtimeSettings: LogConfig;
/**
* Get or create a Logger with given name, if it already was created returns the existing Logger.
*/
readonly getLogger: (name: LoggerNameType) => CoreLogger;
/**
* Updates the given Logger's runtime settings, only applies settings given, leaves the rest as-is.
* Returns true when applied, false when the logger is not found (e.g. may not have originated from here).
*/
readonly updateLoggerRuntime: (log: CoreLogger, settings: RuntimeSettings) => boolean;
/**
* Updates the runtime settings for *all* loggers already created as well
* as for future created loggers.
*/
readonly updateRuntimeSettings: (settings: RuntimeSettings) => void;
}
//# sourceMappingURL=LogProvider.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogProvider.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/LogProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAE1B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,UAAU,CAAC;IAEzD;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC;IAEtF;;;OAGG;IACH,QAAQ,CAAC,qBAAqB,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CACrE"}

View File

@ -0,0 +1,15 @@
import { RawLogMessage } from "./RawLogMessage";
/**
* Used to write a raw log message to.
*/
export interface RawLogChannel {
readonly type: "RawLogChannel";
/**
* Write the RawLogMessage away. The formatArg function can be used to format
* arguments from the RawLogMessage if needed. By default the formatArg function will
* use JSON.stringify(..), unless a global format function was registered
* in which case it uses that.
*/
readonly write: (msg: RawLogMessage, formatArg: (arg: unknown) => string) => void;
}
//# sourceMappingURL=RawLogChannel.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"RawLogChannel.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/RawLogChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,aAAa;IAE5B,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAE/B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,KAAK,IAAI,CAAC;CACnF"}

View File

@ -0,0 +1,34 @@
import { LogLevel } from "./LogLevel";
/**
* The RawLogMessage to write away to a RawLogChannel. RawLogMessage contains
* the raw data, and allows one to format it in any way wanted. It is written
* to a RawLogChannel.
*/
export interface RawLogMessage {
/**
* The level it was logged with.
*/
readonly level: LogLevel;
/**
* Time of log statement in millis (since epoch)
*/
readonly timeInMillis: number;
/**
* Contains the log name involved when logging (logger name or category name), by default it's always 1
* but can be more in some advanced cases.
*/
readonly logNames: string | ReadonlyArray<string>;
/**
* Original user message, and only that. No log level, no timestamp etc.
*/
readonly message: string;
/**
* Error if present.
*/
readonly exception?: Error;
/**
* Additional arguments when they were logged, else undefined.
*/
readonly args?: ReadonlyArray<unknown>;
}
//# sourceMappingURL=RawLogMessage.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"RawLogMessage.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/api/RawLogMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAE5B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAElD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACxC"}

View File

@ -0,0 +1,36 @@
import { ArgumentFormatterType } from "../type/ArgumentFormatterType";
import { DateFormatterType } from "../type/DateFormatterType";
import { LogLevel } from "../LogLevel";
import { LogChannel } from "../LogChannel";
import { RawLogChannel } from "../RawLogChannel";
/**
* The LogConfig that must be provided to the core.
* These represent all the standard settings initially
* in use.
*/
export interface LogConfig {
/**
* Default LogLevel.
*/
readonly level: LogLevel;
/**
* What kind of channel to log to (a normal or raw channel).
* In some cases the flavor maybe it to be changed in a more
* fine-grained control where different channels can be used.
*
* However, by default this is the channel that is used without
* any specif configuration.
*
* The default channel logs to console.
*/
readonly channel: LogChannel | RawLogChannel;
/**
* The argument formatter to use.
*/
readonly argumentFormatter: ArgumentFormatterType;
/**
* The date formatter to use to format a timestamp in the log line.
*/
readonly dateFormatter: DateFormatterType;
}
//# sourceMappingURL=LogConfig.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogConfig.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/config/LogConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AACrC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAEzB;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,aAAa,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,iBAAiB,EAAE,qBAAqB,CAAC;IAElD;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;CAC3C"}

View File

@ -0,0 +1,11 @@
import { LoggerNameType } from "../type/LoggerNameType";
import { LogId } from "../LogId";
import { LogConfig } from "../config/LogConfig";
/**
* Represents runtime settings that are created for a {@link Logger} instance.
*/
export interface LogRuntime extends LogConfig {
readonly id: LogId;
readonly name: LoggerNameType;
}
//# sourceMappingURL=LogRuntime.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogRuntime.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/runtime/LogRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B"}

View File

@ -0,0 +1,11 @@
import { LogRuntime } from "./LogRuntime";
/**
* Represents the updatable part of the settings. Can be used to update
* the runtime settings for a logger or all loggers.
*/
export type RuntimeSettings = Partial<RuntimeSettingsRequired>;
/**
* Same as RuntimeSettings except all properties are required instead.
*/
export type RuntimeSettingsRequired = Pick<LogRuntime, "level" | "channel">;
//# sourceMappingURL=RuntimeSettings.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"RuntimeSettings.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/runtime/RuntimeSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC"}

View File

@ -0,0 +1,5 @@
/**
* Formatter function that is used to format additional arguments of a log message.
*/
export type ArgumentFormatterType = (arg: unknown) => string;
//# sourceMappingURL=ArgumentFormatterType.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ArgumentFormatterType.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/ArgumentFormatterType.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC"}

View File

@ -0,0 +1,6 @@
/**
* Formatter function to format the date in millis since epoch to a string.
* The result is used in a log line.
*/
export type DateFormatterType = (millisSinceEpoch: number) => string;
//# sourceMappingURL=DateFormatterType.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"DateFormatterType.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/DateFormatterType.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,gBAAgB,EAAE,MAAM,KAAK,MAAM,CAAC"}

View File

@ -0,0 +1,6 @@
/**
* Error type, when there is an Error to log this must be used either
* by giving an error directly or by returning an Error as function.
*/
export type ExceptionType = Error | (() => Error);
//# sourceMappingURL=ExceptionType.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ExceptionType.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/ExceptionType.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC"}

View File

@ -0,0 +1,12 @@
import { LogChannel } from "../LogChannel";
import { RawLogChannel } from "../RawLogChannel";
/**
* The type of the LogChannel. The channel is used to send
* log statements to. The channel must either be a normal LogChannel
* or a RawLogChannel. The normal one is the easiest one to use
* as it will receive complete log messages.
* The raw channel gets the raw log message, and allows complete
* control on how to log a message.
*/
export type LogChannelType = LogChannel | RawLogChannel;
//# sourceMappingURL=LogChannelType.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogChannelType.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/LogChannelType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,aAAa,CAAC"}

View File

@ -0,0 +1,9 @@
/**
* The LogMessage type represents the message that is logged. Either a string, or a lambda
* function returning a string. Note that the lambda function has a formatter
* available, which allows formatting of a message if needed.
*
* For example: log.debug(fmt => fmt("My name is a {}, and I am from {}.", "secret", "a country"));
*/
export type LogMessageType = string | (() => string);
//# sourceMappingURL=LogMessageType.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogMessageType.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/LogMessageType.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC"}

View File

@ -0,0 +1,5 @@
/**
* Name of a logger, either a string or an array of strings (if it has multiple names).
*/
export type LoggerNameType = string | ReadonlyArray<string>;
//# sourceMappingURL=LoggerNameType.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LoggerNameType.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/LoggerNameType.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC"}

View File

@ -0,0 +1,11 @@
/**
* Make all properties of type T partial, but the properties given as K (from T) remain as they are (e.g. required).
*/
export type PartialExcept<T, K extends keyof T> = Partial<T> & Pick<T, K>;
/**
* Make all properties of T mutable.
*/
export type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};
//# sourceMappingURL=TypeUtils.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"TypeUtils.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/api/type/TypeUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC/B,CAAC"}

View File

@ -0,0 +1,33 @@
import { CoreLogger } from "../api/CoreLogger";
import { ExceptionType } from "../api/type/ExceptionType";
import { LogLevel } from "../api/LogLevel";
import { LogMessageType } from "../api/type/LogMessageType";
import { LogRuntime } from "../api/runtime/LogRuntime";
/**
* Standard logger implementation that provides the basis for all loggers.
*/
export declare class CoreLoggerImpl implements CoreLogger {
private _runtime;
constructor(runtime: LogRuntime);
get id(): string;
get logLevel(): LogLevel;
get runtimeSettings(): LogRuntime;
set runtimeSettings(runtime: LogRuntime);
trace(message: LogMessageType, ...args: unknown[]): void;
trace(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
debug(message: LogMessageType, ...args: unknown[]): void;
debug(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
info(message: LogMessageType, ...args: unknown[]): void;
info(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
warn(message: LogMessageType, ...args: unknown[]): void;
warn(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
error(message: LogMessageType, ...args: unknown[]): void;
error(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
fatal(message: LogMessageType, ...args: unknown[]): void;
fatal(message: LogMessageType, error: ExceptionType, ...args: unknown[]): void;
private logMessage;
private formatArgValue;
private createLogMessage;
private static getErrorAndArgs;
}
//# sourceMappingURL=CoreLoggerImpl.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CoreLoggerImpl.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/impl/CoreLoggerImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAC;AAGrD;;GAEG;AACH,qBAAa,cAAe,YAAW,UAAU;IAE/C,OAAO,CAAC,QAAQ,CAAa;gBAEV,OAAO,EAAE,UAAU;IAItC,IAAW,EAAE,WAEZ;IAED,IAAW,QAAQ,IAAI,QAAQ,CAE9B;IAED,IAAW,eAAe,IAAI,UAAU,CAGvC;IAED,IAAW,eAAe,CAAC,OAAO,EAAE,UAAU,EAE7C;IAEM,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACxD,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAK9E,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACxD,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAK9E,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACvD,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAK7E,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACvD,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAK7E,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACxD,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAK9E,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACxD,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAKrF,OAAO,CAAC,UAAU;IA6BlB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,MAAM,CAAC,eAAe;CAyD/B"}

View File

@ -0,0 +1,15 @@
/**
* Default argument formatter function, used by the library, see {@link ArgumentFormatterType}.
* Can be used by an end user as well if needed.
* @param arg The argument to format
* @returns argument stringified to string (JSON.stringify), if arg is undefined returns "undefined" (without quotes).
*/
export declare function formatArgument(arg: unknown): string;
/**
* Default date formatter function, used by the library, see {@link DateFormatterType}.
* Can be used by an end user as well if needed.
* @param millisSinceEpoch Milliseconds since epoch
* @returns The date in format: yyyy-MM-dd HH:mm:ss,SSS (example: 2021-02-26 09:06:28,123)
*/
export declare function formatDate(millisSinceEpoch: number): string;
//# sourceMappingURL=DefaultFormatters.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"DefaultFormatters.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/impl/DefaultFormatters.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAKnD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAU3D"}

View File

@ -0,0 +1,44 @@
import { LogProvider } from "../api/LogProvider";
import { LoggerNameType } from "../api/type/LoggerNameType";
import { CoreLogger } from "../api/CoreLogger";
import { LogConfig } from "../api/config/LogConfig";
import { RuntimeSettings } from "../api/runtime/RuntimeSettings";
/**
* Implementation for {@link LogProvider}
*/
export declare class LogProviderImpl implements LogProvider {
private readonly _log;
private readonly _name;
/**
* Default settings that were taken on creation.
* @private
*/
private readonly _settings;
private readonly _loggers;
private readonly _idToKeyMap;
/**
* Current runtime settings (same as _settings on creation), but may be different if runtime settings are changed.
* Creation of loggers always use this.
* @private
*/
private _globalRuntimeSettings;
private _nextLoggerId;
constructor(name: string, settings: LogConfig);
get runtimeSettings(): LogConfig;
getLogger(name: LoggerNameType): CoreLogger;
updateLoggerRuntime(log: CoreLogger, settings: RuntimeSettings): boolean;
updateRuntimeSettings(settings: RuntimeSettings): void;
/**
* Removes all state and loggers, it reverts back to as it was after initial construction.
*/
clear(): void;
private getOrCreateLogger;
private nextLoggerId;
private static mergeRuntimeSettingsIntoLogRuntime;
private static createKey;
}
/**
* Creates a default LogConfig (should not be exported).
*/
export declare function createDefaultLogConfig(): LogConfig;
//# sourceMappingURL=LogProviderImpl.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"LogProviderImpl.d.ts","sourceRoot":"","sources":["../../../../../../../src/typescript/main/core/impl/LogProviderImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAC,eAAe,EAA0B,MAAM,gCAAgC,CAAC;AAQxF;;GAEG;AACH,qBAAa,eAAgB,YAAW,WAAW;IAEjD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkD;IAEvE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAEzD;;;;OAIG;IACH,OAAO,CAAC,sBAAsB,CAA0B;IACxD,OAAO,CAAC,aAAa,CAAS;gBAEX,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS;IAWpD,IAAW,eAAe,IAAI,SAAS,CAMtC;IAEM,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU;IAI3C,mBAAmB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO;IAiBxE,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAe7D;;OAEG;IACI,KAAK;IAOZ,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,MAAM,CAAC,kCAAkC;IAYjD,OAAO,CAAC,MAAM,CAAC,SAAS;CAMzB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,SAAS,CAOlD"}

View File

@ -0,0 +1,10 @@
import { LogChannel } from "../../api/LogChannel";
import { LogMessage } from "../../api/LogMessage";
/**
* Default standard LogChannel which logs to console.
*/
export declare class ConsoleLogChannel implements LogChannel {
readonly type: "LogChannel";
write(msg: LogMessage): void;
}
//# sourceMappingURL=ConsoleLogChannel.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ConsoleLogChannel.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/impl/channel/ConsoleLogChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAIhD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,UAAU;IAElD,SAAgB,IAAI,EAAE,YAAY,CAAgB;IAE3C,KAAK,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;CAKpC"}

View File

@ -0,0 +1,11 @@
import { LogChannel } from "../../api/LogChannel";
/**
* Provides access to various default channels provided by typescript logging.
*/
export declare namespace DefaultChannels {
/**
* Create a new standard LogChannel that logs to the console.
*/
function createConsoleChannel(): LogChannel;
}
//# sourceMappingURL=DefaultChannels.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"DefaultChannels.d.ts","sourceRoot":"","sources":["../../../../../../../../src/typescript/main/core/impl/channel/DefaultChannels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAKhD;;GAEG;AACH,yBAAiB,eAAe,CAAC;IAC/B;;OAEG;IACH,SAAgB,oBAAoB,IAAI,UAAU,CAEjD;CACF"}

View File

@ -0,0 +1,29 @@
import { LogConfig } from "./api/config/LogConfig";
import { LogProvider } from "./api/LogProvider";
export { CoreLogger } from "./api/CoreLogger";
export { LogChannel } from "./api/LogChannel";
export { LogId } from "./api/LogId";
export { LogLevel } from "./api/LogLevel";
export { LogMessage } from "./api/LogMessage";
export { LogProvider } from "./api/LogProvider";
export { LogRuntime } from "./api/runtime/LogRuntime";
export { RawLogChannel } from "./api/RawLogChannel";
export { RawLogMessage } from "./api/RawLogMessage";
export { LogConfig } from "./api/config/LogConfig";
export { RuntimeSettings } from "./api/runtime/RuntimeSettings";
export { ArgumentFormatterType } from "./api/type/ArgumentFormatterType";
export { DateFormatterType } from "./api/type/DateFormatterType";
export { ExceptionType } from "./api/type/ExceptionType";
export { LogChannelType } from "./api/type/LogChannelType";
export { LoggerNameType } from "./api/type/LoggerNameType";
export { LogMessageType } from "./api/type/LogMessageType";
export * from "./api/type/TypeUtils";
export * from "./impl/channel/DefaultChannels";
export * from "./impl/DefaultFormatters";
/**
* Create a new LogProvider, this is for flavor usage only. End users should not
* use this and instead use whatever the flavor offers to build some config and
* get loggers from there.
*/
export declare function createLogProvider(name: string, settings: LogConfig): LogProvider;
//# sourceMappingURL=index.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/typescript/main/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAK9C,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AAClC,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAC,qBAAqB,EAAC,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AACzD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,WAAW,CAEhF"}

View File

@ -0,0 +1,56 @@
/**
* Internal loggers are used by the library itself. It allows us to log
* on a few key points, which is useful when troubleshooting why
* things don't work as one expects.
*
* By default the internal provider logs at Error (so nothing will
* be shown unless there is an error in setup e.g.).
*/
export interface InternalLogger {
trace: (msg: () => string) => void;
debug: (msg: () => string) => void;
info: (msg: () => string) => void;
warn: (msg: () => string, error?: Error) => void;
error: (msg: () => string, error?: Error) => void;
}
/**
* Internal log level (note: do NOT use LogLevel, or we get circular loading issues!)
*/
export declare enum InternalLogLevel {
Trace = 0,
Debug = 1,
Info = 2,
Warn = 3,
Error = 4
}
/**
* Internal logger, this is NOT for end users. Instead this is used to enable logging for typescript-logging itself in case of problems.
*
* @param name Name of logger
*/
export declare function getInternalLogger(name: string): InternalLogger;
/**
* Can be used to change the *internal* logging of the library.
* Has no effect on end user logging.
*
* As such should normally not be used by end users.
*/
export declare const INTERNAL_LOGGING_SETTINGS: {
/**
* Changes the log level for the internal logging (for all new and existing loggers)
* @param level New log level
*/
setInternalLogLevel: (level: InternalLogLevel) => void;
/**
* Changes where messages are written to for all new and existing loggers),
* by default they are written to the console.
* @param fnOutput Function to write messages to
*/
setOutput: (fnOutput: (msg: string) => void) => void;
/**
* Resets the log level and output back to defaults (level to error and writing to console)
* for all new and existing loggers.
*/
reset: () => void;
};
//# sourceMappingURL=InternalLogger.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"InternalLogger.d.ts","sourceRoot":"","sources":["../../../../../../src/typescript/main/internal/InternalLogger.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;IAClC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IACjD,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CACnD;AAED;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,IAAI,IAAA;IACJ,KAAK,IAAA;CACN;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAE9D;AAED;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB;IACpC;;;OAGG;iCAC0B,gBAAgB;IAE7C;;;;OAIG;gCACyB,MAAM,KAAK,IAAI;IAE3C;;;OAGG;;CAEJ,CAAC"}

View File

@ -0,0 +1,5 @@
export * as $internal from "./internal/InternalLogger";
export * from "./core/index";
export * as util from "./util/index";
export * as $test from "../test/TestClasses";
//# sourceMappingURL=typescript-logging.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"typescript-logging.d.ts","sourceRoot":"","sources":["../../../../../src/typescript/main/typescript-logging.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD,cAAc,cAAc,CAAC;AAE7B,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AAGrC,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAC"}

View File

@ -0,0 +1,38 @@
/**
* Extends Map and adds a few convenient functions.
*/
export declare class EnhancedMap<K, V> extends Map<K, V> {
/**
* If key has a mapping already returns the currently associated value. If
* there is no mapping, calls the computer which must return a value V.
* The value is then stored for given key and returned.
* @param key Key
* @param computer Computer which is called only if key has no mapping yet.
* @return Existing value if the key already existed, or the newly computed value.
*/
computeIfAbsent(key: K, computer: (currentKey: K) => V): V;
/**
* If the key exists already calls given computer, if the key does not exist
* this method does nothing.
*
* The computer is called with current key and current value associated. The
* computer can return a (new) value V or undefined. When undefined is returned
* the key is removed from this map, when a V is returned the key is updated
* with the new value V.
* @param key Key
* @param computer Computer which is called only if the key has a mapping already
* @return Undefined if the key has no mapping, otherwise the value returned from computer
*/
computeIfPresent(key: K, computer: (currentKey: K, currentValue: V) => V | undefined): V | undefined;
/**
* Computes a value for given key, the computer can return a value V (in which case the map
* will set the value for given key), if it returns undefined the mapping for key K will be
* removed.
* @param key Key to compute
* @param computer Computer which is called, note that the currentValue argument contains the existing
* value or is undefined when no mapping exists for the key.
* @return The newly computed value
*/
compute(key: K, computer: (currentKey: K, currentValue: V | undefined) => V | undefined): V | undefined;
}
//# sourceMappingURL=EnhancedMap.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"EnhancedMap.d.ts","sourceRoot":"","sources":["../../../../../../src/typescript/main/util/EnhancedMap.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC,EAAC,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAE7C;;;;;;;OAOG;IACI,eAAe,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;IASjE;;;;;;;;;;;OAWG;IACI,gBAAgB,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS;IAgB3G;;;;;;;;OAQG;IACI,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS;CAW/F"}

View File

@ -0,0 +1,23 @@
/**
* Pad given value with given fillChar from the beginning (default is an empty space)
* @param value Value to pad
* @param length The length the string must be
* @param fillChar The padding char (1 char length allowed only)
* @return Padded string or the same string if it is already of given length (or larger).
*/
export declare function padStart(value: string, length: number, fillChar?: string): string;
/**
* Pad given value with given fillChar from the end (default is an empty space)
* @param value Value to pad
* @param length The length the string must be
* @param fillChar The padding char (1 char length allowed only)
* @return Padded string or the same string if it is already of given length (or larger).
*/
export declare function padEnd(value: string, length: number, fillChar?: string): string;
/**
* Returns the max length of a string value in given array
* @param arr Array to check
* @return Max length, 0 if array is empty
*/
export declare function maxLengthStringValueInArray(arr: string[]): number;
//# sourceMappingURL=StringUtil.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"StringUtil.d.ts","sourceRoot":"","sources":["../../../../../../src/typescript/main/util/StringUtil.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAY,UAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAY,UAE3E;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CASjE"}

View File

@ -0,0 +1,3 @@
export * from "./EnhancedMap";
export * from "./StringUtil";
//# sourceMappingURL=index.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/typescript/main/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}

View File

@ -0,0 +1,35 @@
import { LogChannel, LogMessage, RawLogChannel, RawLogMessage } from "../main/core";
/**
* LogChannel that pushes log messages to a buffer.
*/
export declare class ArrayLogChannel implements LogChannel {
private readonly _buffer;
readonly type = "LogChannel";
write(msg: LogMessage): void;
get logMessages(): LogMessage[];
get messages(): string[];
}
/**
* RawLogChannel that pushes raw log messages to a buffer.
*/
export declare class ArrayRawLogChannel implements RawLogChannel {
private _buffer;
readonly type = "RawLogChannel";
write(msg: RawLogMessage, _: (arg: unknown) => string): void;
get messages(): ReadonlyArray<string>;
get errors(): ReadonlyArray<Error | undefined>;
get size(): number;
get rawMessages(): ReadonlyArray<RawLogMessage>;
clear(): void;
}
/**
* Test class to help test the log control.
*/
export declare class TestControlMessage {
private _messages;
constructor();
get messages(): string[];
write(msg: string): void;
clear(): void;
}
//# sourceMappingURL=TestClasses.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"TestClasses.d.ts","sourceRoot":"","sources":["../../../../../src/typescript/test/TestClasses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,cAAc,CAAC;AAElF;;GAEG;AACH,qBAAa,eAAgB,YAAW,UAAU;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,SAAgB,IAAI,gBAAgB;IAE7B,KAAK,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAInC,IAAW,WAAW,iBAErB;IAED,IAAW,QAAQ,aAElB;CACF;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IAEtD,OAAO,CAAC,OAAO,CAAuB;IACtC,SAAgB,IAAI,mBAAmB;IAEhC,KAAK,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI;IAInE,IAAW,QAAQ,IAAI,aAAa,CAAC,MAAM,CAAC,CAE3C;IAED,IAAW,MAAM,IAAI,aAAa,CAAC,KAAK,GAAG,SAAS,CAAC,CAEpD;IAED,IAAW,IAAI,WAEd;IAED,IAAW,WAAW,IAAI,aAAa,CAAC,aAAa,CAAC,CAErD;IAEM,KAAK;CAGb;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,SAAS,CAAgB;;IAMjC,IAAW,QAAQ,IAAI,MAAM,EAAE,CAE9B;IAEM,KAAK,CAAC,GAAG,EAAE,MAAM;IAIjB,KAAK,IAAI,IAAI;CAGrB"}

View File

@ -0,0 +1,674 @@
/**
* Extends Map and adds a few convenient functions.
*/
class EnhancedMap extends Map {
/**
* If key has a mapping already returns the currently associated value. If
* there is no mapping, calls the computer which must return a value V.
* The value is then stored for given key and returned.
* @param key Key
* @param computer Computer which is called only if key has no mapping yet.
* @return Existing value if the key already existed, or the newly computed value.
*/
computeIfAbsent(key, computer) {
if (this.has(key)) {
return this.get(key);
}
const newValue = computer(key);
this.set(key, newValue);
return newValue;
}
/**
* If the key exists already calls given computer, if the key does not exist
* this method does nothing.
*
* The computer is called with current key and current value associated. The
* computer can return a (new) value V or undefined. When undefined is returned
* the key is removed from this map, when a V is returned the key is updated
* with the new value V.
* @param key Key
* @param computer Computer which is called only if the key has a mapping already
* @return Undefined if the key has no mapping, otherwise the value returned from computer
*/
computeIfPresent(key, computer) {
const currentValue = this.get(key);
if (currentValue === undefined) {
return undefined;
}
const newValue = computer(key, currentValue);
if (newValue !== undefined) {
this.set(key, newValue);
}
else {
this.delete(key);
}
return newValue;
}
/**
* Computes a value for given key, the computer can return a value V (in which case the map
* will set the value for given key), if it returns undefined the mapping for key K will be
* removed.
* @param key Key to compute
* @param computer Computer which is called, note that the currentValue argument contains the existing
* value or is undefined when no mapping exists for the key.
* @return The newly computed value
*/
compute(key, computer) {
const currentValue = this.get(key);
const newValue = computer(key, currentValue);
if (newValue) {
this.set(key, newValue);
}
else {
this.delete(key);
}
return newValue;
}
}
/**
* Internal log level (note: do NOT use LogLevel, or we get circular loading issues!)
*/
var InternalLogLevel;
(function (InternalLogLevel) {
InternalLogLevel[InternalLogLevel["Trace"] = 0] = "Trace";
InternalLogLevel[InternalLogLevel["Debug"] = 1] = "Debug";
InternalLogLevel[InternalLogLevel["Info"] = 2] = "Info";
InternalLogLevel[InternalLogLevel["Warn"] = 3] = "Warn";
InternalLogLevel[InternalLogLevel["Error"] = 4] = "Error";
})(InternalLogLevel || (InternalLogLevel = {}));
/**
* Internal logger, this is NOT for end users. Instead this is used to enable logging for typescript-logging itself in case of problems.
*
* @param name Name of logger
*/
function getInternalLogger(name) {
return provider.getLogger(name);
}
/**
* Can be used to change the *internal* logging of the library.
* Has no effect on end user logging.
*
* As such should normally not be used by end users.
*/
const INTERNAL_LOGGING_SETTINGS = {
/**
* Changes the log level for the internal logging (for all new and existing loggers)
* @param level New log level
*/
setInternalLogLevel: (level) => provider.changeLogLevel(level),
/**
* Changes where messages are written to for all new and existing loggers),
* by default they are written to the console.
* @param fnOutput Function to write messages to
*/
setOutput: (fnOutput) => provider.changeOutput(fnOutput),
/**
* Resets the log level and output back to defaults (level to error and writing to console)
* for all new and existing loggers.
*/
reset: () => provider.reset(),
};
class InternalLoggerImpl {
constructor(name, level, fnOutput) {
this._name = name;
this._level = level;
this._fnOutput = fnOutput;
}
trace(msg) {
this.log(InternalLogLevel.Trace, msg);
}
debug(msg) {
this.log(InternalLogLevel.Debug, msg);
}
error(msg, error) {
this.log(InternalLogLevel.Error, msg, error);
}
info(msg) {
this.log(InternalLogLevel.Info, msg);
}
warn(msg, error) {
this.log(InternalLogLevel.Warn, msg, error);
}
setLevel(level) {
this._level = level;
}
setOutput(fnOutput) {
this._fnOutput = fnOutput;
}
log(level, msg, error) {
if (this._level > level) {
return;
}
// tslint:disable-next-line:no-console
this._fnOutput(`${InternalLogLevel[this._level].toString()} <INTERNAL LOGGER> ${this._name} ${msg()}${error ? "\n" + error.stack : ""}`);
}
}
class InternalProviderImpl {
constructor() {
this._loggers = new EnhancedMap();
this._logLevel = InternalLogLevel.Error;
this._fnOutput = InternalProviderImpl.logConsole;
}
getLogger(name) {
return this._loggers.computeIfAbsent(name, key => new InternalLoggerImpl(key, this._logLevel, this._fnOutput));
}
changeLogLevel(level) {
this._logLevel = level;
this._loggers.forEach(logger => logger.setLevel(level));
}
changeOutput(_fnOutput) {
this._fnOutput = _fnOutput;
this._loggers.forEach(logger => logger.setOutput(this._fnOutput));
}
reset() {
this.changeLogLevel(InternalLogLevel.Error);
this._fnOutput = InternalProviderImpl.logConsole;
this._loggers.forEach(logger => logger.setOutput(this._fnOutput));
}
static logConsole(msg) {
// tslint:disable-next-line:no-console
if (console && console.log) {
// tslint:disable-next-line:no-console
console.log(msg);
}
}
}
const provider = new InternalProviderImpl();
var InternalLogger = /*#__PURE__*/Object.freeze({
__proto__: null,
INTERNAL_LOGGING_SETTINGS: INTERNAL_LOGGING_SETTINGS,
get InternalLogLevel () { return InternalLogLevel; },
getInternalLogger: getInternalLogger
});
/**
* Log level for a logger.
*/
var LogLevel;
(function (LogLevel) {
// Do not change values/order. Logging a message relies on this.
LogLevel[LogLevel["Trace"] = 0] = "Trace";
LogLevel[LogLevel["Debug"] = 1] = "Debug";
LogLevel[LogLevel["Info"] = 2] = "Info";
LogLevel[LogLevel["Warn"] = 3] = "Warn";
LogLevel[LogLevel["Error"] = 4] = "Error";
LogLevel[LogLevel["Fatal"] = 5] = "Fatal";
LogLevel[LogLevel["Off"] = 6] = "Off";
})(LogLevel || (LogLevel = {}));
/* tslint:disable:no-namespace */
(function (LogLevel) {
/**
* Convert given value to LogLevel, if not matching returns undefined.
* @param val Value to convert
*/
function toLogLevel(val) {
switch (val.toLowerCase()) {
case "trace":
return LogLevel.Trace;
case "debug":
return LogLevel.Debug;
case "info":
return LogLevel.Info;
case "warn":
return LogLevel.Warn;
case "error":
return LogLevel.Error;
case "fatal":
return LogLevel.Fatal;
case "off":
return LogLevel.Off;
default:
return undefined;
}
}
LogLevel.toLogLevel = toLogLevel;
})(LogLevel || (LogLevel = {}));
/* tslint:disable:enable-namespace */
/**
* Standard logger implementation that provides the basis for all loggers.
*/
class CoreLoggerImpl {
constructor(runtime) {
this._runtime = runtime;
}
get id() {
return this._runtime.id;
}
get logLevel() {
return this._runtime.level;
}
get runtimeSettings() {
/* Return it as new literal, we don't want people to play with our internal state */
return Object.assign({}, this._runtime);
}
set runtimeSettings(runtime) {
this._runtime = runtime;
}
trace(message, ...args) {
this.logMessage(LogLevel.Trace, message, args);
}
debug(message, ...args) {
this.logMessage(LogLevel.Debug, message, args);
}
info(message, ...args) {
this.logMessage(LogLevel.Info, message, args);
}
warn(message, ...args) {
this.logMessage(LogLevel.Warn, message, args);
}
error(message, ...args) {
this.logMessage(LogLevel.Error, message, args);
}
fatal(message, ...args) {
this.logMessage(LogLevel.Fatal, message, args);
}
logMessage(level, logMessageType, args) {
if (this._runtime.level > level) {
return;
}
const nowMillis = Date.now();
const message = typeof logMessageType === "string" ? logMessageType : logMessageType();
const errorAndArgs = CoreLoggerImpl.getErrorAndArgs(args);
/*
* Deal with raw message here.
*/
switch (this._runtime.channel.type) {
case "RawLogChannel":
this._runtime.channel.write({
message,
exception: errorAndArgs.error,
args: errorAndArgs.args,
timeInMillis: nowMillis,
level,
logNames: this._runtime.name,
}, this._runtime.argumentFormatter);
return;
case "LogChannel":
this._runtime.channel.write(this.createLogMessage(message, level, errorAndArgs, nowMillis));
break;
}
}
formatArgValue(value) {
try {
return this._runtime.argumentFormatter(value);
}
catch (e) {
// We don't really care what failed, except that the convert function failed.
return `>>ARG CONVERT FAILED: '${value !== undefined ? value.toString() : "undefined"}'<<`;
}
}
createLogMessage(message, level, errorAndArgs, nowMillis) {
let errorResult;
const error = errorAndArgs.error;
const args = errorAndArgs.args;
if (error) {
errorResult = `${error.name}: ${error.message}`;
if (error.stack) {
errorResult += `@\n${error.stack}`;
}
}
/*
* We need to add the date, and log names (in front of the now formatted message).
* Finally we also need to format any additional arguments and append after the message.
*/
const dateFormatted = this._runtime.dateFormatter(nowMillis);
let levelAsStr = LogLevel[level].toUpperCase();
if (levelAsStr.length < 5) {
levelAsStr += " ";
}
const names = typeof this._runtime.name === "string" ? this._runtime.name : this._runtime.name.join(", ");
const argsFormatted = typeof args !== "undefined" && args.length > 0 ? (" [" + (args.map(arg => this.formatArgValue(arg))).join(", ") + "]") : "";
const completedMessage = dateFormatted + " " + levelAsStr + " [" + names + "] " + message + argsFormatted;
return {
message: completedMessage,
error: errorResult,
};
}
static getErrorAndArgs(args) {
/*
The args are optional, but the first entry may be an Error or a function to an Error, or finally be a function to extra arguments.
The last is only true, if the length of args === 1, otherwise we expect args starting at pos 1 and further to be just that - args.
*/
if (args.length === 0) {
return {};
}
let error;
let actualArgs;
const value0 = args[0];
/* If the first argument is an Error, we can stop straight away, the rest are additional arguments then if any */
if (value0 instanceof Error) {
error = value0;
actualArgs = args.length > 1 ? args.slice(1) : undefined;
return { error, args: actualArgs };
}
/* If the first argument is a function, it means either it will return the Error, or if the array length === 1 a function, returning the arguments */
if (typeof value0 === "function") {
const errorOrArgs = value0();
if (errorOrArgs instanceof Error) {
error = errorOrArgs;
actualArgs = args.length > 1 ? args.slice(1) : undefined;
return { error, args: actualArgs };
}
if (args.length === 1) {
/* The first argument was a function, we assume it returned the extra argument(s) */
if (Array.isArray(errorOrArgs)) {
return { args: errorOrArgs.length > 0 ? errorOrArgs : undefined };
}
else {
/* No idea what was returned we just assume a single value */
return { args: errorOrArgs };
}
}
else {
/*
This is a weird situation but there's no way to avoid it, the first argument was a function but did not return an Error and the args are > 1,
so just add the args returned, as well as any remaining.
*/
if (Array.isArray(errorOrArgs)) {
return { args: [...errorOrArgs, ...args.slice(1)] };
}
return { args: [errorOrArgs, ...args.slice(1)] };
}
}
/* All args are ordinary arguments, or at least the first arg was not an Error or a Function, so we add all as args */
return { args };
}
}
/**
* Pad given value with given fillChar from the beginning (default is an empty space)
* @param value Value to pad
* @param length The length the string must be
* @param fillChar The padding char (1 char length allowed only)
* @return Padded string or the same string if it is already of given length (or larger).
*/
function padStart(value, length, fillChar = " ") {
return padInternal(value, length, "start", fillChar);
}
/**
* Pad given value with given fillChar from the end (default is an empty space)
* @param value Value to pad
* @param length The length the string must be
* @param fillChar The padding char (1 char length allowed only)
* @return Padded string or the same string if it is already of given length (or larger).
*/
function padEnd(value, length, fillChar = " ") {
return padInternal(value, length, "end", fillChar);
}
/**
* Returns the max length of a string value in given array
* @param arr Array to check
* @return Max length, 0 if array is empty
*/
function maxLengthStringValueInArray(arr) {
return arr
.map(v => v.length)
.reduce((previous, current) => {
if (current > previous) {
return current;
}
return previous;
}, 0);
}
function padInternal(value, length, padType, fillChar = " ") {
if (length <= value.length) {
return value;
}
if (fillChar.length > 1) {
throw new Error(`Fill char must be one char exactly, it is: ${fillChar.length}`);
}
const charsNeeded = length - value.length;
let padding = "";
for (let i = 0; i < charsNeeded; i++) {
padding += fillChar;
}
if (padType === "start") {
return padding + value;
}
return value + padding;
}
/**
* Default argument formatter function, used by the library, see {@link ArgumentFormatterType}.
* Can be used by an end user as well if needed.
* @param arg The argument to format
* @returns argument stringified to string (JSON.stringify), if arg is undefined returns "undefined" (without quotes).
*/
function formatArgument(arg) {
if (arg === undefined) {
return "undefined";
}
return JSON.stringify(arg);
}
/**
* Default date formatter function, used by the library, see {@link DateFormatterType}.
* Can be used by an end user as well if needed.
* @param millisSinceEpoch Milliseconds since epoch
* @returns The date in format: yyyy-MM-dd HH:mm:ss,SSS (example: 2021-02-26 09:06:28,123)
*/
function formatDate(millisSinceEpoch) {
const date = new Date(millisSinceEpoch);
const year = date.getFullYear();
const month = padStart((date.getMonth() + 1).toString(), 2, "0");
const day = padStart(date.getDate().toString(), 2, "0");
const hours = padStart(date.getHours().toString(), 2, "0");
const minutes = padStart(date.getMinutes().toString(), 2, "0");
const seconds = padStart(date.getSeconds().toString(), 2, "0");
const millis = padStart(date.getMilliseconds().toString(), 3, "0");
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds},${millis}`;
}
/* tslint:disable:no-console */
/**
* Default standard LogChannel which logs to console.
*/
class ConsoleLogChannel {
constructor() {
this.type = "LogChannel";
}
write(msg) {
if (console && console.log) {
console.log(msg.message + (msg.error ? `\n${msg.error}` : ""));
}
}
}
/* tslint:disable:no-namespace */
/**
* Provides access to various default channels provided by typescript logging.
*/
var DefaultChannels;
(function (DefaultChannels) {
/**
* Create a new standard LogChannel that logs to the console.
*/
function createConsoleChannel() {
return new ConsoleLogChannel();
}
DefaultChannels.createConsoleChannel = createConsoleChannel;
})(DefaultChannels || (DefaultChannels = {}));
/**
* Implementation for {@link LogProvider}
*/
class LogProviderImpl {
constructor(name, settings) {
this._log = getInternalLogger("core.impl.LogProviderImpl");
this._name = name;
this._settings = settings;
this._loggers = new EnhancedMap();
this._idToKeyMap = new EnhancedMap();
this._globalRuntimeSettings = { level: settings.level, channel: settings.channel };
this._nextLoggerId = 1;
this._log.trace(() => `Created LogProviderImpl with settings: ${JSON.stringify(this._settings)}`);
}
get runtimeSettings() {
return Object.assign(Object.assign({}, this._settings), { level: this._globalRuntimeSettings.level, channel: this._globalRuntimeSettings.channel });
}
getLogger(name) {
return this.getOrCreateLogger(name);
}
updateLoggerRuntime(log, settings) {
this._log.debug(() => `Updating logger ${log.id} runtime settings using: '${JSON.stringify(settings)}'`);
const key = this._idToKeyMap.get(log.id);
if (key === undefined) {
this._log.warn(() => `Cannot update logger with id: ${log.id}, it was not found.`);
return false;
}
this._loggers.computeIfPresent(key, (currentKey, currentValue) => {
currentValue.runtimeSettings = LogProviderImpl.mergeRuntimeSettingsIntoLogRuntime(currentValue.runtimeSettings, settings);
return currentValue;
});
return true;
}
updateRuntimeSettings(settings) {
this._log.debug(() => `Updating global runtime settings and updating existing loggers runtime settings using: '${JSON.stringify(settings)}'`);
this._globalRuntimeSettings = {
/*
* Undefined check is necessary, as level is a number (and LogLevel.Trace = 0), a ternary check otherwise results in the annoying "truthy/falsy"
* behavior of javascript where 0 is seen as false.
*/
level: settings.level !== undefined ? settings.level : this._globalRuntimeSettings.level,
channel: settings.channel !== undefined ? settings.channel : this._globalRuntimeSettings.channel,
};
this._loggers.forEach(logger => logger.runtimeSettings = LogProviderImpl.mergeRuntimeSettingsIntoLogRuntime(logger.runtimeSettings, settings));
}
/**
* Removes all state and loggers, it reverts back to as it was after initial construction.
*/
clear() {
this._loggers.clear();
this._idToKeyMap.clear();
this._globalRuntimeSettings = Object.assign({}, this._settings);
this._nextLoggerId = 1;
}
getOrCreateLogger(name) {
const key = LogProviderImpl.createKey(name);
const logger = this._loggers.computeIfAbsent(key, () => {
const runtime = {
level: this._globalRuntimeSettings.level,
channel: this._globalRuntimeSettings.channel,
id: this.nextLoggerId(),
name,
argumentFormatter: this._settings.argumentFormatter,
dateFormatter: this._settings.dateFormatter,
};
return new CoreLoggerImpl(runtime);
});
this._idToKeyMap.computeIfAbsent(logger.id, () => key);
return logger;
}
nextLoggerId() {
const result = this._name + "_" + this._nextLoggerId;
this._nextLoggerId++;
return result;
}
static mergeRuntimeSettingsIntoLogRuntime(currentSettings, settings) {
return Object.assign(Object.assign({}, currentSettings), {
/*
* Undefined check is necessary, as level is a number (and LogLevel.Trace = 0), a ternary check otherwise results in the annoying "truthy/falsy"
* behavior of javascript where 0 is seen as false.
*/
level: settings.level !== undefined ? settings.level : currentSettings.level, channel: settings.channel !== undefined ? settings.channel : currentSettings.channel });
}
static createKey(name) {
if (typeof name === "string") {
return name;
}
return name.join(",");
}
}
/**
* Create a new LogProvider, this is for flavor usage only. End users should not
* use this and instead use whatever the flavor offers to build some config and
* get loggers from there.
*/
function createLogProvider(name, settings) {
return new LogProviderImpl(name, settings);
}
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
EnhancedMap: EnhancedMap,
maxLengthStringValueInArray: maxLengthStringValueInArray,
padEnd: padEnd,
padStart: padStart
});
/**
* LogChannel that pushes log messages to a buffer.
*/
class ArrayLogChannel {
constructor() {
this._buffer = [];
this.type = "LogChannel";
}
write(msg) {
this._buffer.push(msg);
}
get logMessages() {
return this._buffer;
}
get messages() {
return this._buffer.map(msg => msg.message);
}
}
/**
* RawLogChannel that pushes raw log messages to a buffer.
*/
class ArrayRawLogChannel {
constructor() {
this._buffer = [];
this.type = "RawLogChannel";
}
write(msg, _) {
this._buffer.push(msg);
}
get messages() {
return this._buffer.map(m => m.message);
}
get errors() {
return this._buffer.map(m => m.exception);
}
get size() {
return this._buffer.length;
}
get rawMessages() {
return this._buffer;
}
clear() {
this._buffer = [];
}
}
/**
* Test class to help test the log control.
*/
class TestControlMessage {
constructor() {
this._messages = [];
this.write = this.write.bind(this);
}
get messages() {
return this._messages;
}
write(msg) {
this._messages.push(msg);
}
clear() {
this._messages = [];
}
}
var TestClasses = /*#__PURE__*/Object.freeze({
__proto__: null,
ArrayLogChannel: ArrayLogChannel,
ArrayRawLogChannel: ArrayRawLogChannel,
TestControlMessage: TestControlMessage
});
export { InternalLogger as $internal, TestClasses as $test, DefaultChannels, LogLevel, createLogProvider, formatArgument, formatDate, index as util };
//# sourceMappingURL=typescript-logging.esm.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,681 @@
'use strict';
/**
* Extends Map and adds a few convenient functions.
*/
class EnhancedMap extends Map {
/**
* If key has a mapping already returns the currently associated value. If
* there is no mapping, calls the computer which must return a value V.
* The value is then stored for given key and returned.
* @param key Key
* @param computer Computer which is called only if key has no mapping yet.
* @return Existing value if the key already existed, or the newly computed value.
*/
computeIfAbsent(key, computer) {
if (this.has(key)) {
return this.get(key);
}
const newValue = computer(key);
this.set(key, newValue);
return newValue;
}
/**
* If the key exists already calls given computer, if the key does not exist
* this method does nothing.
*
* The computer is called with current key and current value associated. The
* computer can return a (new) value V or undefined. When undefined is returned
* the key is removed from this map, when a V is returned the key is updated
* with the new value V.
* @param key Key
* @param computer Computer which is called only if the key has a mapping already
* @return Undefined if the key has no mapping, otherwise the value returned from computer
*/
computeIfPresent(key, computer) {
const currentValue = this.get(key);
if (currentValue === undefined) {
return undefined;
}
const newValue = computer(key, currentValue);
if (newValue !== undefined) {
this.set(key, newValue);
}
else {
this.delete(key);
}
return newValue;
}
/**
* Computes a value for given key, the computer can return a value V (in which case the map
* will set the value for given key), if it returns undefined the mapping for key K will be
* removed.
* @param key Key to compute
* @param computer Computer which is called, note that the currentValue argument contains the existing
* value or is undefined when no mapping exists for the key.
* @return The newly computed value
*/
compute(key, computer) {
const currentValue = this.get(key);
const newValue = computer(key, currentValue);
if (newValue) {
this.set(key, newValue);
}
else {
this.delete(key);
}
return newValue;
}
}
/**
* Internal log level (note: do NOT use LogLevel, or we get circular loading issues!)
*/
var InternalLogLevel;
(function (InternalLogLevel) {
InternalLogLevel[InternalLogLevel["Trace"] = 0] = "Trace";
InternalLogLevel[InternalLogLevel["Debug"] = 1] = "Debug";
InternalLogLevel[InternalLogLevel["Info"] = 2] = "Info";
InternalLogLevel[InternalLogLevel["Warn"] = 3] = "Warn";
InternalLogLevel[InternalLogLevel["Error"] = 4] = "Error";
})(InternalLogLevel || (InternalLogLevel = {}));
/**
* Internal logger, this is NOT for end users. Instead this is used to enable logging for typescript-logging itself in case of problems.
*
* @param name Name of logger
*/
function getInternalLogger(name) {
return provider.getLogger(name);
}
/**
* Can be used to change the *internal* logging of the library.
* Has no effect on end user logging.
*
* As such should normally not be used by end users.
*/
const INTERNAL_LOGGING_SETTINGS = {
/**
* Changes the log level for the internal logging (for all new and existing loggers)
* @param level New log level
*/
setInternalLogLevel: (level) => provider.changeLogLevel(level),
/**
* Changes where messages are written to for all new and existing loggers),
* by default they are written to the console.
* @param fnOutput Function to write messages to
*/
setOutput: (fnOutput) => provider.changeOutput(fnOutput),
/**
* Resets the log level and output back to defaults (level to error and writing to console)
* for all new and existing loggers.
*/
reset: () => provider.reset(),
};
class InternalLoggerImpl {
constructor(name, level, fnOutput) {
this._name = name;
this._level = level;
this._fnOutput = fnOutput;
}
trace(msg) {
this.log(InternalLogLevel.Trace, msg);
}
debug(msg) {
this.log(InternalLogLevel.Debug, msg);
}
error(msg, error) {
this.log(InternalLogLevel.Error, msg, error);
}
info(msg) {
this.log(InternalLogLevel.Info, msg);
}
warn(msg, error) {
this.log(InternalLogLevel.Warn, msg, error);
}
setLevel(level) {
this._level = level;
}
setOutput(fnOutput) {
this._fnOutput = fnOutput;
}
log(level, msg, error) {
if (this._level > level) {
return;
}
// tslint:disable-next-line:no-console
this._fnOutput(`${InternalLogLevel[this._level].toString()} <INTERNAL LOGGER> ${this._name} ${msg()}${error ? "\n" + error.stack : ""}`);
}
}
class InternalProviderImpl {
constructor() {
this._loggers = new EnhancedMap();
this._logLevel = InternalLogLevel.Error;
this._fnOutput = InternalProviderImpl.logConsole;
}
getLogger(name) {
return this._loggers.computeIfAbsent(name, key => new InternalLoggerImpl(key, this._logLevel, this._fnOutput));
}
changeLogLevel(level) {
this._logLevel = level;
this._loggers.forEach(logger => logger.setLevel(level));
}
changeOutput(_fnOutput) {
this._fnOutput = _fnOutput;
this._loggers.forEach(logger => logger.setOutput(this._fnOutput));
}
reset() {
this.changeLogLevel(InternalLogLevel.Error);
this._fnOutput = InternalProviderImpl.logConsole;
this._loggers.forEach(logger => logger.setOutput(this._fnOutput));
}
static logConsole(msg) {
// tslint:disable-next-line:no-console
if (console && console.log) {
// tslint:disable-next-line:no-console
console.log(msg);
}
}
}
const provider = new InternalProviderImpl();
var InternalLogger = /*#__PURE__*/Object.freeze({
__proto__: null,
INTERNAL_LOGGING_SETTINGS: INTERNAL_LOGGING_SETTINGS,
get InternalLogLevel () { return InternalLogLevel; },
getInternalLogger: getInternalLogger
});
/**
* Log level for a logger.
*/
exports.LogLevel = void 0;
(function (LogLevel) {
// Do not change values/order. Logging a message relies on this.
LogLevel[LogLevel["Trace"] = 0] = "Trace";
LogLevel[LogLevel["Debug"] = 1] = "Debug";
LogLevel[LogLevel["Info"] = 2] = "Info";
LogLevel[LogLevel["Warn"] = 3] = "Warn";
LogLevel[LogLevel["Error"] = 4] = "Error";
LogLevel[LogLevel["Fatal"] = 5] = "Fatal";
LogLevel[LogLevel["Off"] = 6] = "Off";
})(exports.LogLevel || (exports.LogLevel = {}));
/* tslint:disable:no-namespace */
(function (LogLevel) {
/**
* Convert given value to LogLevel, if not matching returns undefined.
* @param val Value to convert
*/
function toLogLevel(val) {
switch (val.toLowerCase()) {
case "trace":
return LogLevel.Trace;
case "debug":
return LogLevel.Debug;
case "info":
return LogLevel.Info;
case "warn":
return LogLevel.Warn;
case "error":
return LogLevel.Error;
case "fatal":
return LogLevel.Fatal;
case "off":
return LogLevel.Off;
default:
return undefined;
}
}
LogLevel.toLogLevel = toLogLevel;
})(exports.LogLevel || (exports.LogLevel = {}));
/* tslint:disable:enable-namespace */
/**
* Standard logger implementation that provides the basis for all loggers.
*/
class CoreLoggerImpl {
constructor(runtime) {
this._runtime = runtime;
}
get id() {
return this._runtime.id;
}
get logLevel() {
return this._runtime.level;
}
get runtimeSettings() {
/* Return it as new literal, we don't want people to play with our internal state */
return Object.assign({}, this._runtime);
}
set runtimeSettings(runtime) {
this._runtime = runtime;
}
trace(message, ...args) {
this.logMessage(exports.LogLevel.Trace, message, args);
}
debug(message, ...args) {
this.logMessage(exports.LogLevel.Debug, message, args);
}
info(message, ...args) {
this.logMessage(exports.LogLevel.Info, message, args);
}
warn(message, ...args) {
this.logMessage(exports.LogLevel.Warn, message, args);
}
error(message, ...args) {
this.logMessage(exports.LogLevel.Error, message, args);
}
fatal(message, ...args) {
this.logMessage(exports.LogLevel.Fatal, message, args);
}
logMessage(level, logMessageType, args) {
if (this._runtime.level > level) {
return;
}
const nowMillis = Date.now();
const message = typeof logMessageType === "string" ? logMessageType : logMessageType();
const errorAndArgs = CoreLoggerImpl.getErrorAndArgs(args);
/*
* Deal with raw message here.
*/
switch (this._runtime.channel.type) {
case "RawLogChannel":
this._runtime.channel.write({
message,
exception: errorAndArgs.error,
args: errorAndArgs.args,
timeInMillis: nowMillis,
level,
logNames: this._runtime.name,
}, this._runtime.argumentFormatter);
return;
case "LogChannel":
this._runtime.channel.write(this.createLogMessage(message, level, errorAndArgs, nowMillis));
break;
}
}
formatArgValue(value) {
try {
return this._runtime.argumentFormatter(value);
}
catch (e) {
// We don't really care what failed, except that the convert function failed.
return `>>ARG CONVERT FAILED: '${value !== undefined ? value.toString() : "undefined"}'<<`;
}
}
createLogMessage(message, level, errorAndArgs, nowMillis) {
let errorResult;
const error = errorAndArgs.error;
const args = errorAndArgs.args;
if (error) {
errorResult = `${error.name}: ${error.message}`;
if (error.stack) {
errorResult += `@\n${error.stack}`;
}
}
/*
* We need to add the date, and log names (in front of the now formatted message).
* Finally we also need to format any additional arguments and append after the message.
*/
const dateFormatted = this._runtime.dateFormatter(nowMillis);
let levelAsStr = exports.LogLevel[level].toUpperCase();
if (levelAsStr.length < 5) {
levelAsStr += " ";
}
const names = typeof this._runtime.name === "string" ? this._runtime.name : this._runtime.name.join(", ");
const argsFormatted = typeof args !== "undefined" && args.length > 0 ? (" [" + (args.map(arg => this.formatArgValue(arg))).join(", ") + "]") : "";
const completedMessage = dateFormatted + " " + levelAsStr + " [" + names + "] " + message + argsFormatted;
return {
message: completedMessage,
error: errorResult,
};
}
static getErrorAndArgs(args) {
/*
The args are optional, but the first entry may be an Error or a function to an Error, or finally be a function to extra arguments.
The last is only true, if the length of args === 1, otherwise we expect args starting at pos 1 and further to be just that - args.
*/
if (args.length === 0) {
return {};
}
let error;
let actualArgs;
const value0 = args[0];
/* If the first argument is an Error, we can stop straight away, the rest are additional arguments then if any */
if (value0 instanceof Error) {
error = value0;
actualArgs = args.length > 1 ? args.slice(1) : undefined;
return { error, args: actualArgs };
}
/* If the first argument is a function, it means either it will return the Error, or if the array length === 1 a function, returning the arguments */
if (typeof value0 === "function") {
const errorOrArgs = value0();
if (errorOrArgs instanceof Error) {
error = errorOrArgs;
actualArgs = args.length > 1 ? args.slice(1) : undefined;
return { error, args: actualArgs };
}
if (args.length === 1) {
/* The first argument was a function, we assume it returned the extra argument(s) */
if (Array.isArray(errorOrArgs)) {
return { args: errorOrArgs.length > 0 ? errorOrArgs : undefined };
}
else {
/* No idea what was returned we just assume a single value */
return { args: errorOrArgs };
}
}
else {
/*
This is a weird situation but there's no way to avoid it, the first argument was a function but did not return an Error and the args are > 1,
so just add the args returned, as well as any remaining.
*/
if (Array.isArray(errorOrArgs)) {
return { args: [...errorOrArgs, ...args.slice(1)] };
}
return { args: [errorOrArgs, ...args.slice(1)] };
}
}
/* All args are ordinary arguments, or at least the first arg was not an Error or a Function, so we add all as args */
return { args };
}
}
/**
* Pad given value with given fillChar from the beginning (default is an empty space)
* @param value Value to pad
* @param length The length the string must be
* @param fillChar The padding char (1 char length allowed only)
* @return Padded string or the same string if it is already of given length (or larger).
*/
function padStart(value, length, fillChar = " ") {
return padInternal(value, length, "start", fillChar);
}
/**
* Pad given value with given fillChar from the end (default is an empty space)
* @param value Value to pad
* @param length The length the string must be
* @param fillChar The padding char (1 char length allowed only)
* @return Padded string or the same string if it is already of given length (or larger).
*/
function padEnd(value, length, fillChar = " ") {
return padInternal(value, length, "end", fillChar);
}
/**
* Returns the max length of a string value in given array
* @param arr Array to check
* @return Max length, 0 if array is empty
*/
function maxLengthStringValueInArray(arr) {
return arr
.map(v => v.length)
.reduce((previous, current) => {
if (current > previous) {
return current;
}
return previous;
}, 0);
}
function padInternal(value, length, padType, fillChar = " ") {
if (length <= value.length) {
return value;
}
if (fillChar.length > 1) {
throw new Error(`Fill char must be one char exactly, it is: ${fillChar.length}`);
}
const charsNeeded = length - value.length;
let padding = "";
for (let i = 0; i < charsNeeded; i++) {
padding += fillChar;
}
if (padType === "start") {
return padding + value;
}
return value + padding;
}
/**
* Default argument formatter function, used by the library, see {@link ArgumentFormatterType}.
* Can be used by an end user as well if needed.
* @param arg The argument to format
* @returns argument stringified to string (JSON.stringify), if arg is undefined returns "undefined" (without quotes).
*/
function formatArgument(arg) {
if (arg === undefined) {
return "undefined";
}
return JSON.stringify(arg);
}
/**
* Default date formatter function, used by the library, see {@link DateFormatterType}.
* Can be used by an end user as well if needed.
* @param millisSinceEpoch Milliseconds since epoch
* @returns The date in format: yyyy-MM-dd HH:mm:ss,SSS (example: 2021-02-26 09:06:28,123)
*/
function formatDate(millisSinceEpoch) {
const date = new Date(millisSinceEpoch);
const year = date.getFullYear();
const month = padStart((date.getMonth() + 1).toString(), 2, "0");
const day = padStart(date.getDate().toString(), 2, "0");
const hours = padStart(date.getHours().toString(), 2, "0");
const minutes = padStart(date.getMinutes().toString(), 2, "0");
const seconds = padStart(date.getSeconds().toString(), 2, "0");
const millis = padStart(date.getMilliseconds().toString(), 3, "0");
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds},${millis}`;
}
/* tslint:disable:no-console */
/**
* Default standard LogChannel which logs to console.
*/
class ConsoleLogChannel {
constructor() {
this.type = "LogChannel";
}
write(msg) {
if (console && console.log) {
console.log(msg.message + (msg.error ? `\n${msg.error}` : ""));
}
}
}
/* tslint:disable:no-namespace */
/**
* Provides access to various default channels provided by typescript logging.
*/
exports.DefaultChannels = void 0;
(function (DefaultChannels) {
/**
* Create a new standard LogChannel that logs to the console.
*/
function createConsoleChannel() {
return new ConsoleLogChannel();
}
DefaultChannels.createConsoleChannel = createConsoleChannel;
})(exports.DefaultChannels || (exports.DefaultChannels = {}));
/**
* Implementation for {@link LogProvider}
*/
class LogProviderImpl {
constructor(name, settings) {
this._log = getInternalLogger("core.impl.LogProviderImpl");
this._name = name;
this._settings = settings;
this._loggers = new EnhancedMap();
this._idToKeyMap = new EnhancedMap();
this._globalRuntimeSettings = { level: settings.level, channel: settings.channel };
this._nextLoggerId = 1;
this._log.trace(() => `Created LogProviderImpl with settings: ${JSON.stringify(this._settings)}`);
}
get runtimeSettings() {
return Object.assign(Object.assign({}, this._settings), { level: this._globalRuntimeSettings.level, channel: this._globalRuntimeSettings.channel });
}
getLogger(name) {
return this.getOrCreateLogger(name);
}
updateLoggerRuntime(log, settings) {
this._log.debug(() => `Updating logger ${log.id} runtime settings using: '${JSON.stringify(settings)}'`);
const key = this._idToKeyMap.get(log.id);
if (key === undefined) {
this._log.warn(() => `Cannot update logger with id: ${log.id}, it was not found.`);
return false;
}
this._loggers.computeIfPresent(key, (currentKey, currentValue) => {
currentValue.runtimeSettings = LogProviderImpl.mergeRuntimeSettingsIntoLogRuntime(currentValue.runtimeSettings, settings);
return currentValue;
});
return true;
}
updateRuntimeSettings(settings) {
this._log.debug(() => `Updating global runtime settings and updating existing loggers runtime settings using: '${JSON.stringify(settings)}'`);
this._globalRuntimeSettings = {
/*
* Undefined check is necessary, as level is a number (and LogLevel.Trace = 0), a ternary check otherwise results in the annoying "truthy/falsy"
* behavior of javascript where 0 is seen as false.
*/
level: settings.level !== undefined ? settings.level : this._globalRuntimeSettings.level,
channel: settings.channel !== undefined ? settings.channel : this._globalRuntimeSettings.channel,
};
this._loggers.forEach(logger => logger.runtimeSettings = LogProviderImpl.mergeRuntimeSettingsIntoLogRuntime(logger.runtimeSettings, settings));
}
/**
* Removes all state and loggers, it reverts back to as it was after initial construction.
*/
clear() {
this._loggers.clear();
this._idToKeyMap.clear();
this._globalRuntimeSettings = Object.assign({}, this._settings);
this._nextLoggerId = 1;
}
getOrCreateLogger(name) {
const key = LogProviderImpl.createKey(name);
const logger = this._loggers.computeIfAbsent(key, () => {
const runtime = {
level: this._globalRuntimeSettings.level,
channel: this._globalRuntimeSettings.channel,
id: this.nextLoggerId(),
name,
argumentFormatter: this._settings.argumentFormatter,
dateFormatter: this._settings.dateFormatter,
};
return new CoreLoggerImpl(runtime);
});
this._idToKeyMap.computeIfAbsent(logger.id, () => key);
return logger;
}
nextLoggerId() {
const result = this._name + "_" + this._nextLoggerId;
this._nextLoggerId++;
return result;
}
static mergeRuntimeSettingsIntoLogRuntime(currentSettings, settings) {
return Object.assign(Object.assign({}, currentSettings), {
/*
* Undefined check is necessary, as level is a number (and LogLevel.Trace = 0), a ternary check otherwise results in the annoying "truthy/falsy"
* behavior of javascript where 0 is seen as false.
*/
level: settings.level !== undefined ? settings.level : currentSettings.level, channel: settings.channel !== undefined ? settings.channel : currentSettings.channel });
}
static createKey(name) {
if (typeof name === "string") {
return name;
}
return name.join(",");
}
}
/**
* Create a new LogProvider, this is for flavor usage only. End users should not
* use this and instead use whatever the flavor offers to build some config and
* get loggers from there.
*/
function createLogProvider(name, settings) {
return new LogProviderImpl(name, settings);
}
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
EnhancedMap: EnhancedMap,
maxLengthStringValueInArray: maxLengthStringValueInArray,
padEnd: padEnd,
padStart: padStart
});
/**
* LogChannel that pushes log messages to a buffer.
*/
class ArrayLogChannel {
constructor() {
this._buffer = [];
this.type = "LogChannel";
}
write(msg) {
this._buffer.push(msg);
}
get logMessages() {
return this._buffer;
}
get messages() {
return this._buffer.map(msg => msg.message);
}
}
/**
* RawLogChannel that pushes raw log messages to a buffer.
*/
class ArrayRawLogChannel {
constructor() {
this._buffer = [];
this.type = "RawLogChannel";
}
write(msg, _) {
this._buffer.push(msg);
}
get messages() {
return this._buffer.map(m => m.message);
}
get errors() {
return this._buffer.map(m => m.exception);
}
get size() {
return this._buffer.length;
}
get rawMessages() {
return this._buffer;
}
clear() {
this._buffer = [];
}
}
/**
* Test class to help test the log control.
*/
class TestControlMessage {
constructor() {
this._messages = [];
this.write = this.write.bind(this);
}
get messages() {
return this._messages;
}
write(msg) {
this._messages.push(msg);
}
clear() {
this._messages = [];
}
}
var TestClasses = /*#__PURE__*/Object.freeze({
__proto__: null,
ArrayLogChannel: ArrayLogChannel,
ArrayRawLogChannel: ArrayRawLogChannel,
TestControlMessage: TestControlMessage
});
exports.$internal = InternalLogger;
exports.$test = TestClasses;
exports.createLogProvider = createLogProvider;
exports.formatArgument = formatArgument;
exports.formatDate = formatDate;
exports.util = index;
//# sourceMappingURL=typescript-logging.js.map

File diff suppressed because one or more lines are too long

61
node_modules/typescript-logging/package.json generated vendored Normal file
View File

@ -0,0 +1,61 @@
{
"name": "typescript-logging",
"version": "2.2.0",
"description": "TypeScript Logging core written in and to be used by TypeScript (this is the core project, you need to install a flavor too).",
"main": "dist/bundle/typescript-logging.js",
"module": "dist/bundle/typescript-logging.esm.js",
"typings": "dist/bundle/src/typescript/main/typescript-logging.d.ts",
"scripts": {
"prepack": "shx cp ../README.md ./README.md",
"clean": "shx rm -rf ./dist",
"compile": "rollup -c",
"compile-watch": "rollup -cw",
"tslint": "tslint -c tslint.json -p tsconfig.json",
"test": "jest --no-cache",
"test-watch": "jest --watchAll",
"build": "npm run clean && npm run compile && npm run test && npm run tslint && npm pack --pack-destination dist"
},
"files": [
"dist/bundle",
"LICENSE",
"README.md"
],
"repository": {
"type": "git",
"url": "git+https://github.com/vauxite-org/typescript-logging.git"
},
"keywords": [
"typescript-logging",
"typescript logging",
"typescript-logging core",
"typescript logger",
"log4ts",
"log4ts-like",
"category",
"category-like",
"logging",
"log",
"logger"
],
"author": "Martijn Reuvers <martijnr.work@gmail.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/vauxite-org/typescript-logging/issues"
},
"homepage": "https://github.com/vauxite-org/typescript-logging/#readme",
"devDependencies": {
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-node-resolve": "15.2.3",
"@types/jest": "29.5.12",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"rollup": "4.13.2",
"rollup-plugin-typescript2": "0.36.0",
"shx": "0.3.4",
"ts-jest": "29.1.2",
"ts-loader": "9.5.1",
"ts-node": "10.9.2",
"tslint": "6.1.3",
"typescript": "5.1.6"
}
}