@wireio/shared 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/guards/applyTypeGuardExtras.d.ts +3 -0
- package/lib/guards/applyTypeGuardExtras.d.ts.map +1 -0
- package/lib/guards/applyTypeGuardExtras.js +5 -0
- package/lib/guards/applyTypeGuardExtras.js.map +1 -0
- package/lib/guards/array.d.ts +2 -0
- package/lib/guards/array.d.ts.map +1 -0
- package/lib/guards/array.js +4 -0
- package/lib/guards/array.js.map +1 -0
- package/lib/guards/assert.d.ts +19 -0
- package/lib/guards/assert.d.ts.map +1 -0
- package/lib/guards/assert.js +50 -0
- package/lib/guards/assert.js.map +1 -0
- package/lib/guards/class.d.ts +27 -0
- package/lib/guards/class.d.ts.map +1 -0
- package/lib/guards/class.js +34 -0
- package/lib/guards/class.js.map +1 -0
- package/lib/guards/guard-tools.d.ts +20 -0
- package/lib/guards/guard-tools.d.ts.map +1 -0
- package/lib/guards/guard-tools.js +50 -0
- package/lib/guards/guard-tools.js.map +1 -0
- package/lib/guards/index.d.ts +8 -0
- package/lib/guards/index.d.ts.map +1 -0
- package/lib/guards/index.js +8 -0
- package/lib/guards/index.js.map +1 -0
- package/lib/guards/primitive.d.ts +26 -0
- package/lib/guards/primitive.d.ts.map +1 -0
- package/lib/guards/primitive.js +47 -0
- package/lib/guards/primitive.js.map +1 -0
- package/lib/guards/types.d.ts +10 -0
- package/lib/guards/types.d.ts.map +1 -0
- package/lib/guards/types.js +2 -0
- package/lib/guards/types.js.map +1 -0
- package/lib/helpers/Deferred.d.ts +31 -0
- package/lib/helpers/Deferred.d.ts.map +1 -0
- package/lib/helpers/Deferred.js +111 -0
- package/lib/helpers/Deferred.js.map +1 -0
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.d.ts.map +1 -0
- package/lib/helpers/index.js +2 -0
- package/lib/helpers/index.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib/logging/Appender.d.ts +5 -0
- package/lib/logging/Appender.d.ts.map +1 -0
- package/lib/logging/Appender.js +2 -0
- package/lib/logging/Appender.js.map +1 -0
- package/lib/logging/Formatter.d.ts +3 -0
- package/lib/logging/Formatter.d.ts.map +1 -0
- package/lib/logging/Formatter.js +2 -0
- package/lib/logging/Formatter.js.map +1 -0
- package/lib/logging/InternalLogger.d.ts +2 -0
- package/lib/logging/InternalLogger.d.ts.map +1 -0
- package/lib/logging/InternalLogger.js +6 -0
- package/lib/logging/InternalLogger.js.map +1 -0
- package/lib/logging/Level.d.ts +14 -0
- package/lib/logging/Level.d.ts.map +1 -0
- package/lib/logging/Level.js +13 -0
- package/lib/logging/Level.js.map +1 -0
- package/lib/logging/LogRecord.d.ts +16 -0
- package/lib/logging/LogRecord.d.ts.map +1 -0
- package/lib/logging/LogRecord.js +2 -0
- package/lib/logging/LogRecord.js.map +1 -0
- package/lib/logging/Logger.d.ts +77 -0
- package/lib/logging/Logger.d.ts.map +1 -0
- package/lib/logging/Logger.js +158 -0
- package/lib/logging/Logger.js.map +1 -0
- package/lib/logging/LoggingManager.d.ts +128 -0
- package/lib/logging/LoggingManager.d.ts.map +1 -0
- package/lib/logging/LoggingManager.js +236 -0
- package/lib/logging/LoggingManager.js.map +1 -0
- package/lib/logging/appenders/ConsoleAppender.d.ts +55 -0
- package/lib/logging/appenders/ConsoleAppender.d.ts.map +1 -0
- package/lib/logging/appenders/ConsoleAppender.js +72 -0
- package/lib/logging/appenders/ConsoleAppender.js.map +1 -0
- package/lib/logging/appenders/DebugAppender.d.ts +53 -0
- package/lib/logging/appenders/DebugAppender.d.ts.map +1 -0
- package/lib/logging/appenders/DebugAppender.js +183 -0
- package/lib/logging/appenders/DebugAppender.js.map +1 -0
- package/lib/logging/appenders/FileAppender.d.ts +65 -0
- package/lib/logging/appenders/FileAppender.d.ts.map +1 -0
- package/lib/logging/appenders/FileAppender.js +212 -0
- package/lib/logging/appenders/FileAppender.js.map +1 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseAppender.d.ts +27 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseAppender.d.ts.map +1 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseAppender.js +135 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseAppender.js.map +1 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseCredentialManager.d.ts +27 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseCredentialManager.d.ts.map +1 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseCredentialManager.js +94 -0
- package/lib/logging/appenders/aws-firehose/AWSFirehoseCredentialManager.js.map +1 -0
- package/lib/logging/appenders/index.d.ts +4 -0
- package/lib/logging/appenders/index.d.ts.map +1 -0
- package/lib/logging/appenders/index.js +4 -0
- package/lib/logging/appenders/index.js.map +1 -0
- package/lib/logging/context/LogContext.d.ts +48 -0
- package/lib/logging/context/LogContext.d.ts.map +1 -0
- package/lib/logging/context/LogContext.js +58 -0
- package/lib/logging/context/LogContext.js.map +1 -0
- package/lib/logging/context/LogContextContainer.d.ts +9 -0
- package/lib/logging/context/LogContextContainer.d.ts.map +1 -0
- package/lib/logging/context/LogContextContainer.js +25 -0
- package/lib/logging/context/LogContextContainer.js.map +1 -0
- package/lib/logging/context/LogContextProvider.d.ts +24 -0
- package/lib/logging/context/LogContextProvider.d.ts.map +1 -0
- package/lib/logging/context/LogContextProvider.js +18 -0
- package/lib/logging/context/LogContextProvider.js.map +1 -0
- package/lib/logging/context/index.d.ts +4 -0
- package/lib/logging/context/index.d.ts.map +1 -0
- package/lib/logging/context/index.js +4 -0
- package/lib/logging/context/index.js.map +1 -0
- package/lib/logging/context/providers/node/NodeContextProvider.d.ts +2 -0
- package/lib/logging/context/providers/node/NodeContextProvider.d.ts.map +1 -0
- package/lib/logging/context/providers/node/NodeContextProvider.js +31 -0
- package/lib/logging/context/providers/node/NodeContextProvider.js.map +1 -0
- package/lib/logging/context/providers/node/index.d.ts +3 -0
- package/lib/logging/context/providers/node/index.d.ts.map +1 -0
- package/lib/logging/context/providers/node/index.js +2 -0
- package/lib/logging/context/providers/node/index.js.map +1 -0
- package/lib/logging/examples/example-debug-appender.d.ts +2 -0
- package/lib/logging/examples/example-debug-appender.d.ts.map +1 -0
- package/lib/logging/examples/example-debug-appender.js +14 -0
- package/lib/logging/examples/example-debug-appender.js.map +1 -0
- package/lib/logging/examples/example-file-appender.d.ts +2 -0
- package/lib/logging/examples/example-file-appender.d.ts.map +1 -0
- package/lib/logging/examples/example-file-appender.js +16 -0
- package/lib/logging/examples/example-file-appender.js.map +1 -0
- package/lib/logging/getLogger.d.ts +3 -0
- package/lib/logging/getLogger.d.ts.map +1 -0
- package/lib/logging/getLogger.js +5 -0
- package/lib/logging/getLogger.js.map +1 -0
- package/lib/logging/index-node.d.ts +3 -0
- package/lib/logging/index-node.d.ts.map +1 -0
- package/lib/logging/index-node.js +3 -0
- package/lib/logging/index-node.js.map +1 -0
- package/lib/logging/index.d.ts +11 -0
- package/lib/logging/index.d.ts.map +1 -0
- package/lib/logging/index.js +11 -0
- package/lib/logging/index.js.map +1 -0
- package/lib/logging/util.d.ts +3 -0
- package/lib/logging/util.d.ts.map +1 -0
- package/lib/logging/util.js +6 -0
- package/lib/logging/util.js.map +1 -0
- package/package.json +31 -0
- package/src/guards/applyTypeGuardExtras.ts +9 -0
- package/src/guards/array.ts +5 -0
- package/src/guards/assert.ts +83 -0
- package/src/guards/class.ts +56 -0
- package/src/guards/guard-tools.ts +78 -0
- package/src/guards/index.ts +7 -0
- package/src/guards/primitive.ts +77 -0
- package/src/guards/types.ts +15 -0
- package/src/helpers/Deferred.ts +149 -0
- package/src/helpers/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/logging/Appender.ts +5 -0
- package/src/logging/Formatter.ts +8 -0
- package/src/logging/InternalLogger.ts +6 -0
- package/src/logging/Level.ts +19 -0
- package/src/logging/LogRecord.ts +17 -0
- package/src/logging/Logger.ts +222 -0
- package/src/logging/LoggingManager.ts +306 -0
- package/src/logging/appenders/ConsoleAppender.ts +110 -0
- package/src/logging/appenders/DebugAppender.ts +254 -0
- package/src/logging/appenders/FileAppender.ts +281 -0
- package/src/logging/appenders/aws-firehose/AWSFirehoseAppender.ts +176 -0
- package/src/logging/appenders/aws-firehose/AWSFirehoseCredentialManager.ts +132 -0
- package/src/logging/appenders/index.ts +3 -0
- package/src/logging/context/LogContext.ts +74 -0
- package/src/logging/context/LogContextContainer.ts +28 -0
- package/src/logging/context/LogContextProvider.ts +43 -0
- package/src/logging/context/index.ts +3 -0
- package/src/logging/context/providers/node/NodeContextProvider.ts +45 -0
- package/src/logging/context/providers/node/index.ts +3 -0
- package/src/logging/examples/example-debug-appender.ts +19 -0
- package/src/logging/examples/example-file-appender.ts +19 -0
- package/src/logging/getLogger.ts +9 -0
- package/src/logging/index-node.ts +2 -0
- package/src/logging/index.ts +11 -0
- package/src/logging/util.ts +6 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// noinspection JSValidateJSDoc
|
|
2
|
+
|
|
3
|
+
import type { LogContext } from "./LogContext"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export interface LogContextProvider {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get current context stack
|
|
11
|
+
*
|
|
12
|
+
* @returns {any[]}
|
|
13
|
+
*/
|
|
14
|
+
currentContext(): Array<LogContext>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Run in context
|
|
18
|
+
*
|
|
19
|
+
* @param {LogContext} context
|
|
20
|
+
* @param {() => Promise<T>} fn
|
|
21
|
+
* @returns {Promise<T>}
|
|
22
|
+
*/
|
|
23
|
+
runInContext<T = unknown>(context: LogContext, fn: () => Promise<T>): Promise<T>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Dummy/Noop context provider
|
|
29
|
+
*
|
|
30
|
+
* @type {{currentContext(): Array<LogContext>, runInContext<T=unknown>(context: LogContext, fn: () => Promise<T>): Promise<T>}}
|
|
31
|
+
*/
|
|
32
|
+
export const DefaultLogContextProvider:LogContextProvider = {
|
|
33
|
+
currentContext(): Array<LogContext> {
|
|
34
|
+
return []
|
|
35
|
+
},
|
|
36
|
+
runInContext<T = unknown>(context: LogContext, fn: () => Promise<T>): Promise<T> {
|
|
37
|
+
if (process.env.NODE_ENV === "development") {
|
|
38
|
+
console.warn(`Attempting to use LogContext without any installed provider`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return fn()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "async_hooks"
|
|
2
|
+
import { uniq } from "lodash"
|
|
3
|
+
import type { LogContext } from "../../LogContext"
|
|
4
|
+
import type { LogContextProvider } from "../../LogContextProvider"
|
|
5
|
+
import { LogContextContainer } from "../../LogContextContainer.js"
|
|
6
|
+
|
|
7
|
+
const contextStorage = new AsyncLocalStorage<Array<LogContext>>()
|
|
8
|
+
|
|
9
|
+
function currentContextStore(): Array<LogContext> {
|
|
10
|
+
return contextStorage.getStore() ?? []
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class NodeContextProvider implements LogContextProvider {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get current context stack
|
|
18
|
+
*
|
|
19
|
+
* @returns {any[]}
|
|
20
|
+
*/
|
|
21
|
+
currentContext(): Array<LogContext> {
|
|
22
|
+
return currentContextStore() ?? []
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Run in context
|
|
27
|
+
*
|
|
28
|
+
* @param {LogContext} context
|
|
29
|
+
* @param {() => Promise<T>} fn
|
|
30
|
+
* @returns {Promise<T>}
|
|
31
|
+
*/
|
|
32
|
+
runInContext<T = unknown>(
|
|
33
|
+
context: LogContext,
|
|
34
|
+
fn: () => Promise<T>
|
|
35
|
+
): Promise<T> {
|
|
36
|
+
const contexts = currentContextStore()
|
|
37
|
+
return contextStorage.run<Promise<T>, []>(uniq([...contexts, context]), fn)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const instance = new NodeContextProvider()
|
|
42
|
+
|
|
43
|
+
LogContextContainer.setProvider(instance)
|
|
44
|
+
|
|
45
|
+
export {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getLogger } from "../getLogger.js"
|
|
2
|
+
import { LevelNames } from "../Level.js"
|
|
3
|
+
import { getLoggingManager } from "../LoggingManager.js"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
getLoggingManager().configure({
|
|
7
|
+
// Default appenders list is [ConsoleAppender],
|
|
8
|
+
// so the following is not needed and only
|
|
9
|
+
// remains as an example:
|
|
10
|
+
//
|
|
11
|
+
// appenders: [new ConsoleAppender()],
|
|
12
|
+
rootLevel: "trace"
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const log = getLogger(__filename)
|
|
16
|
+
|
|
17
|
+
LevelNames.forEach((name) =>
|
|
18
|
+
log[name].call(log, `example %s`, name)
|
|
19
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileAppender } from "../appenders/FileAppender.js"
|
|
2
|
+
import { getLogger } from "../getLogger.js"
|
|
3
|
+
import { LevelNames } from "../Level.js"
|
|
4
|
+
import { getLoggingManager } from "../LoggingManager.js"
|
|
5
|
+
|
|
6
|
+
async function run() {
|
|
7
|
+
const manager = getLoggingManager()
|
|
8
|
+
const fileAppender = new FileAppender({
|
|
9
|
+
enableRolling: true,
|
|
10
|
+
maxFiles: 4,
|
|
11
|
+
maxSize: 20480
|
|
12
|
+
})
|
|
13
|
+
manager.setAppenders(fileAppender).setRootLevel("trace")
|
|
14
|
+
|
|
15
|
+
const log = getLogger(__filename)
|
|
16
|
+
await fileAppender.close()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
run().catch((err) => console.error(`failed`, err))
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger, LoggerOptions } from "./Logger"
|
|
2
|
+
import { getLoggingManager } from "./LoggingManager.js"
|
|
3
|
+
|
|
4
|
+
export function getLogger(
|
|
5
|
+
category: string,
|
|
6
|
+
options: Partial<LoggerOptions> = {}
|
|
7
|
+
): Logger {
|
|
8
|
+
return getLoggingManager().getLogger(category, options)
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./Appender.js"
|
|
2
|
+
export * from "./Formatter.js"
|
|
3
|
+
export * from "./Level.js"
|
|
4
|
+
export * from "./LogRecord.js"
|
|
5
|
+
export * from "./Logger.js"
|
|
6
|
+
export * from "./LoggingManager.js"
|
|
7
|
+
export * from "./appenders/index.js"
|
|
8
|
+
export * from "./getLogger.js"
|
|
9
|
+
export * from "./util.js"
|
|
10
|
+
export * from "./context/index.js"
|
|
11
|
+
|