From 1d3e0827bd50400acbf6ff2a9ee5521d9beb484b Mon Sep 17 00:00:00 2001 From: Roger Qiu Date: Sat, 12 Aug 2023 00:49:11 +1000 Subject: [PATCH 1/9] feat: migrate to ESM --- .eslintrc | 17 +- README.md | 2 +- benches/index.ts | 39 +- benches/logger_filtered.ts | 16 +- benches/logger_handlers.ts | 20 +- benches/logger_hierarchy.ts | 16 +- benches/logger_structured.ts | 16 +- benches/logger_text.ts | 14 +- benches/results/logger_filtered.chart.html | 14 +- benches/results/logger_filtered.json | 396 +- benches/results/logger_filtered_metrics.txt | 12 +- benches/results/logger_handlers.chart.html | 14 +- benches/results/logger_handlers.json | 412 +- benches/results/logger_handlers_metrics.txt | 12 +- benches/results/logger_hierarchy.chart.html | 14 +- benches/results/logger_hierarchy.json | 835 +- benches/results/logger_hierarchy_metrics.txt | 24 +- benches/results/logger_structured.chart.html | 14 +- benches/results/logger_structured.json | 830 +- benches/results/logger_structured_metrics.txt | 24 +- benches/results/logger_text.chart.html | 14 +- benches/results/logger_text.json | 1065 +- benches/results/logger_text_metrics.txt | 30 +- benches/results/metrics.txt | 102 +- benches/utils/index.ts | 4 +- benches/utils/utils.ts | 21 +- jest.config.js => jest.config.mjs | 29 +- package-lock.json | 10805 +++++----------- package.json | 48 +- src/Handler.ts | 4 +- src/Logger.ts | 10 +- src/formatting.ts | 4 +- src/handlers/ConsoleErrHandler.ts | 2 +- src/handlers/ConsoleOutHandler.ts | 2 +- src/handlers/StreamHandler.ts | 4 +- src/handlers/index.ts | 6 +- src/index.ts | 12 +- src/types.ts | 2 +- src/utils.ts | 4 +- tests/__snapshots__/index.test.ts.snap | 20 +- tests/index.test.ts | 8 +- tsconfig.json | 10 +- 42 files changed, 5641 insertions(+), 9306 deletions(-) rename jest.config.js => jest.config.mjs (74%) diff --git a/.eslintrc b/.eslintrc index 44a8d5a..ca2f535 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,19 +7,18 @@ "jest": true }, "parser": "@typescript-eslint/parser", - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - "prettier" - ], - "plugins": [ - "import" - ], "parserOptions": { "project": "tsconfig.json", "sourceType": "module" }, + "plugins": [ + "import" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" + ], "rules": { "linebreak-style": ["error", "unix"], "no-empty": 1, diff --git a/README.md b/README.md index ab0ae5a..20186df 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ npm install # build the dist npm run build # run the repl (this allows you to import from ./src) -npm run ts-node +npm run tsx # run the tests npm run test # lint the source code diff --git a/benches/index.ts b/benches/index.ts index 4def4d0..d26b4d3 100644 --- a/benches/index.ts +++ b/benches/index.ts @@ -1,33 +1,37 @@ -#!/usr/bin/env ts-node +#!/usr/bin/env tsx -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; +import url from 'node:url'; import si from 'systeminformation'; -import loggerText from './logger_text'; -import loggerStructured from './logger_structured'; -import loggerHierarchy from './logger_hierarchy'; -import loggerFiltered from './logger_filtered'; -import loggerHandlers from './logger_handlers'; +import { benchesPath } from './utils/utils.js'; +import loggerText from './logger_text.js'; +import loggerStructured from './logger_structured.js'; +import loggerHierarchy from './logger_hierarchy.js'; +import loggerFiltered from './logger_filtered.js'; +import loggerHandlers from './logger_handlers.js'; async function main(): Promise { - await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true }); + await fs.promises.mkdir(path.join(benchesPath, 'results'), { + recursive: true, + }); await loggerText(); await loggerStructured(); await loggerHierarchy(); await loggerFiltered(); await loggerHandlers(); const resultFilenames = await fs.promises.readdir( - path.join(__dirname, 'results'), + path.join(benchesPath, 'results'), ); const metricsFile = await fs.promises.open( - path.join(__dirname, 'results', 'metrics.txt'), + path.join(benchesPath, 'results', 'metrics.txt'), 'w', ); let concatenating = false; for (const resultFilename of resultFilenames) { if (/.+_metrics\.txt$/.test(resultFilename)) { const metricsData = await fs.promises.readFile( - path.join(__dirname, 'results', resultFilename), + path.join(benchesPath, 'results', resultFilename), ); if (concatenating) { await metricsFile.write('\n'); @@ -43,9 +47,16 @@ async function main(): Promise { system: 'model, manufacturer', }); await fs.promises.writeFile( - path.join(__dirname, 'results', 'system.json'), + path.join(benchesPath, 'results', 'system.json'), JSON.stringify(systemData, null, 2), ); } -void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } +} + +export default main; diff --git a/benches/logger_filtered.ts b/benches/logger_filtered.ts index 916d43a..20fe116 100644 --- a/benches/logger_filtered.ts +++ b/benches/logger_filtered.ts @@ -1,13 +1,16 @@ -import path from 'path'; +import path from 'node:path'; +import url from 'node:url'; import b from 'benny'; import Logger, { LogLevel, formatting } from '@'; -import { BenchHandler, suiteCommon } from './utils'; +import { BenchHandler, suiteCommon } from './utils/index.js'; + +const filePath = url.fileURLToPath(import.meta.url); async function main() { const msg = 'Hello World'; const data = { foo: 'bar', bar: () => 'foo' }; const summary = await b.suite( - path.basename(__filename, path.extname(__filename)), + path.basename(filePath, path.extname(filePath)), b.add('log level', () => { const logger = new Logger('root', LogLevel.WARN, [ new BenchHandler(formatting.formatter), @@ -30,8 +33,11 @@ async function main() { return summary; } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/logger_handlers.ts b/benches/logger_handlers.ts index e2a810d..aa1bc58 100644 --- a/benches/logger_handlers.ts +++ b/benches/logger_handlers.ts @@ -1,9 +1,12 @@ -import os from 'os'; -import path from 'path'; -import fs from 'fs'; +import os from 'node:os'; +import path from 'node:path'; +import url from 'node:url'; +import fs from 'node:fs'; import b from 'benny'; import Logger, { LogLevel, StreamHandler, ConsoleErrHandler } from '@'; -import { suiteCommon } from './utils'; +import { suiteCommon } from './utils/index.js'; + +const filePath = url.fileURLToPath(import.meta.url); async function main() { const msg = 'Hello World'; @@ -18,7 +21,7 @@ async function main() { const stderr = fs.createWriteStream(path.join(tmpDir, 'stderr')); process.stderr.write = stderr.write.bind(stderr); const summary = await b.suite( - path.basename(__filename, path.extname(__filename)), + path.basename(filePath, path.extname(filePath)), b.add('console.error', () => { const logger = new Logger('root', LogLevel.NOTSET, [ new ConsoleErrHandler(), @@ -43,8 +46,11 @@ async function main() { return summary; } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/logger_hierarchy.ts b/benches/logger_hierarchy.ts index 57e52ea..a843f91 100644 --- a/benches/logger_hierarchy.ts +++ b/benches/logger_hierarchy.ts @@ -1,13 +1,16 @@ -import path from 'path'; +import path from 'node:path'; +import url from 'node:url'; import b from 'benny'; import Logger, { LogLevel, formatting } from '@'; -import { BenchHandler, suiteCommon } from './utils'; +import { BenchHandler, suiteCommon } from './utils/index.js'; + +const filePath = url.fileURLToPath(import.meta.url); async function main() { const msg = 'Hello World'; const data = { foo: 'bar', bar: () => 'foo' }; const summary = await b.suite( - path.basename(__filename, path.extname(__filename)), + path.basename(filePath, path.extname(filePath)), b.add('1-levels', () => { const logger1 = new Logger('1', LogLevel.NOTSET, [ new BenchHandler(formatting.formatter), @@ -51,8 +54,11 @@ async function main() { return summary; } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/logger_structured.ts b/benches/logger_structured.ts index dc2a25d..09b77ac 100644 --- a/benches/logger_structured.ts +++ b/benches/logger_structured.ts @@ -1,5 +1,6 @@ import type { LogRecord } from '@/types'; -import path from 'path'; +import path from 'node:path'; +import url from 'node:url'; import b from 'benny'; import Logger, { LogLevel, @@ -7,13 +8,15 @@ import Logger, { levelToString, evalLogDataValue, } from '@'; -import { BenchHandler, suiteCommon } from './utils'; +import { BenchHandler, suiteCommon } from './utils/index.js'; + +const filePath = url.fileURLToPath(import.meta.url); async function main() { const msg = 'Hello World'; const data = { foo: 'bar', bar: () => 'foo' }; const summary = await b.suite( - path.basename(__filename, path.extname(__filename)), + path.basename(filePath, path.extname(filePath)), b.add('formatting default', () => { const logger = new Logger('root', LogLevel.NOTSET, [ new BenchHandler(formatting.jsonFormatter), @@ -82,8 +85,11 @@ async function main() { return summary; } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/logger_text.ts b/benches/logger_text.ts index 7fdee30..d30eae8 100644 --- a/benches/logger_text.ts +++ b/benches/logger_text.ts @@ -1,13 +1,16 @@ -import path from 'path'; +import path from 'node:path'; +import url from 'node:url'; import b from 'benny'; import Logger, { LogLevel, formatting } from '@'; import { BenchHandler, suiteCommon } from './utils'; +const filePath = url.fileURLToPath(import.meta.url); + async function main() { const msg = 'Hello World'; const data = { foo: 'bar', bar: () => 'foo' }; const summary = await b.suite( - path.basename(__filename, path.extname(__filename)), + path.basename(filePath, path.extname(filePath)), b.add('formatting default', () => { const logger = new Logger('root', LogLevel.NOTSET, [ new BenchHandler(formatting.formatter), @@ -62,8 +65,11 @@ async function main() { return summary; } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/results/logger_filtered.chart.html b/benches/results/logger_filtered.chart.html index f3c8df8..5b5dbe9 100644 --- a/benches/results/logger_filtered.chart.html +++ b/benches/results/logger_filtered.chart.html @@ -28,7 +28,7 @@
- +
+ConsoleErrHandler | @matrixai/logger
-
+

Hierarchy

Constructors

-
- -
+

Returns ConsoleErrHandler

Properties

-
- -
formatter: LogFormatter

Methods

-
- -
    - +
    + +
      +
    • Parameters

      • -
        output: string
      +
      output: string

Returns void

-
- -
-
- -
-
- -
- +
+

On This Page

- - + +

Generated using TypeDoc

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/classes/ConsoleOutHandler.html b/docs/classes/ConsoleOutHandler.html index 8f27001..237073f 100644 --- a/docs/classes/ConsoleOutHandler.html +++ b/docs/classes/ConsoleOutHandler.html @@ -1,4 +1,4 @@ -ConsoleOutHandler | @matrixai/logger
+ConsoleOutHandler | @matrixai/logger
-
+

Hierarchy

Constructors

-
- -
+

Returns ConsoleOutHandler

Properties

-
- -
formatter: LogFormatter

Methods

-
- -
    - +
    + +
      +
    • Parameters

      • -
        output: string
      +
      output: string

Returns void

-
- -
-
- -
-
- -
- +
+

On This Page

- - + +

Generated using TypeDoc

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/classes/Handler.html b/docs/classes/Handler.html index 5bf18f0..648fa7c 100644 --- a/docs/classes/Handler.html +++ b/docs/classes/Handler.html @@ -1,4 +1,4 @@ -Handler | @matrixai/logger
+Handler | @matrixai/logger
-
+

Constructors

-
- -
+

Returns Handler

Properties

-
- -
formatter: LogFormatter

Methods

-
- -
    - +
    + +
      +
    • Parameters

      • -
        output: string
      +
      output: string

Returns void

-
- -

Returns string

-
- -
-
- -
- +
+

On This Page

- - + +

Generated using TypeDoc

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/classes/StreamHandler.html b/docs/classes/StreamHandler.html index e8bb2df..890d150 100644 --- a/docs/classes/StreamHandler.html +++ b/docs/classes/StreamHandler.html @@ -1,4 +1,4 @@ -StreamHandler | @matrixai/logger
+StreamHandler | @matrixai/logger
-
+

Hierarchy

Constructors

-
- -
+

Returns StreamHandler

Properties

-
- -
formatter: LogFormatter

Methods

-
- -
    - +
    + +
      +
    • Parameters

      • -
        output: string
      +
      output: string

Returns void

-
- -
-
- -
-
- -
- +
+

On This Page

- - + +

Generated using TypeDoc

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/classes/default.html b/docs/classes/default.html index 7514607..7304206 100644 --- a/docs/classes/default.html +++ b/docs/classes/default.html @@ -1,4 +1,4 @@ -default | @matrixai/logger
+default | @matrixai/logger
-
+

Constructors

-
- -
+

Returns default

Properties

-
- -
filter?: RegExp
-
- -
parent?: default

Methods

-
- -
    - +
    + +
      +
    • Parameters

      +
      handler: Handler

Returns void

-
- -
-
- -
-
- -

Returns void

-
- -
-
- -
-

Theme

- - - + +

Generated using TypeDoc

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/enums/LogLevel.html b/docs/enums/LogLevel.html index 0307dff..3a088be 100644 --- a/docs/enums/LogLevel.html +++ b/docs/enums/LogLevel.html @@ -1,4 +1,4 @@ -LogLevel | @matrixai/logger
+LogLevel | @matrixai/logger
-
+

Enumeration Members

-
- -
DEBUG: 1
- + - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/functions/levelToString.html b/docs/functions/levelToString.html index 47ed398..ff7614f 100644 --- a/docs/functions/levelToString.html +++ b/docs/functions/levelToString.html @@ -1,4 +1,4 @@ -levelToString | @matrixai/logger
    +levelToString | @matrixai/logger
    -
    +

    Function levelToString

    -

    Returns string

    - + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index b994e8b..d0b5ee0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -@matrixai/logger
    +@matrixai/logger
    -
    +

    @matrixai/logger

    -
    - -

    js-logger

    -
    -

    staging:pipeline status +

    js-logger

    staging:pipeline status master:pipeline status

    This library provides a JavaScript/TypeScript logger inspired by Python's logger.

      @@ -31,52 +27,33 @@

      js-logger

    • Zero runtime dependencies!
    • Comprehensive continuous benchmarks in CI/CD
    - - -

    Installation

    -
    -
    npm install --save @matrixai/logger
    -
    - - -

    Usage

    -
    -
    import Logger, { LogLevel, StreamHandler, formatting } from '@matrixai/logger';

    const logger = new Logger('root', LogLevel.INFO, [
    new StreamHandler(
    formatting.format`${formatting.date}:${formatting.level}:${formatting.key}:${formatting.msg}:${formatting.data}`,
    ),
    ]);

    logger.debug('Hello world', { a: { b: [123, 456] } });
    logger.info('Hello world', { 123: { b: [123, 456] } });
    logger.warn('Hello world', { lazy: () => 'string' });
    logger.error('Hello world', formatting.format`my custom format`);

    const loggerChild = logger.getChild('child');

    loggerChild.info(
    'Hello world',
    { 123: { b: [123, 456] } },
    formatting.format`${formatting.keys}:${formatting.msg}:${formatting.data}`,
    ); -
    +

    Installation

    npm install --save @matrixai/logger
    +
    +

    Usage

    import Logger, { LogLevel, StreamHandler, formatting } from '@matrixai/logger';

    const logger = new Logger('root', LogLevel.INFO, [
    new StreamHandler(
    formatting.format`${formatting.date}:${formatting.level}:${formatting.key}:${formatting.msg}:${formatting.data}`,
    ),
    ]);

    logger.debug('Hello world', { a: { b: [123, 456] } });
    logger.info('Hello world', { 123: { b: [123, 456] } });
    logger.warn('Hello world', { lazy: () => 'string' });
    logger.error('Hello world', formatting.format`my custom format`);

    const loggerChild = logger.getChild('child');

    loggerChild.info(
    'Hello world',
    { 123: { b: [123, 456] } },
    formatting.format`${formatting.keys}:${formatting.msg}:${formatting.data}`,
    ); +

    There's lots more options available in the source code. See the docs and see the source code for more details.

    - - -

    Development

    -
    -

    Run nix-shell, and once you're inside, you can use:

    -
    # install (or reinstall packages from package.json)
    npm install
    # build the dist
    npm run build
    # run the repl (this allows you to import from ./src)
    npm run ts-node
    # run the tests
    npm run test
    # lint the source code
    npm run lint
    # automatically fix the source
    npm run lintfix -
    - - -

    Docs Generation

    -
    -
    npm run docs
    -
    +

    Development

    Run nix-shell, and once you're inside, you can use:

    +
    # install (or reinstall packages from package.json)
    npm install
    # build the dist
    npm run build
    # run the repl (this allows you to import from ./src)
    npm run tsx
    # run the tests
    npm run test
    # lint the source code
    npm run lint
    # automatically fix the source
    npm run lintfix +
    +

    Docs Generation

    npm run docs
    +

    See the docs at: https://matrixai.github.io/js-logger/

    - - -

    Publishing

    -
    -

    Publishing is handled automatically by the staging pipeline.

    +

    Publishing

    Publishing is handled automatically by the staging pipeline.

    Prerelease:

    # npm login
    npm version prepatch --preid alpha # premajor/preminor/prepatch
    git push --follow-tags -
    +

    Release:

    # npm login
    npm version patch # major/minor/patch
    git push --follow-tags -
    +

    Manually:

    # npm login
    npm version patch # major/minor/patch
    npm run build
    npm publish --access public
    git push
    git push --tags -
    +
    - +
    +

    On This Page

    -
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/interfaces/ToJSON.html b/docs/interfaces/ToJSON.html index b6b21b9..c294c6d 100644 --- a/docs/interfaces/ToJSON.html +++ b/docs/interfaces/ToJSON.html @@ -1,4 +1,4 @@ -ToJSON | @matrixai/logger
    +ToJSON | @matrixai/logger
    -
    +

    Properties

    -
    - -
    toJSON: ((key?: string) => string)
    +
    + +
    toJSON: ((key?) => string)

    Type declaration

    • -
        -
      • (key?: string): string
      • +
          +
        • (key?): string
        • Parameters

          • -
            Optional key: string
          +
          Optional key: string

    Returns string

    - +
    +

    On This Page

    -
    - + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/interfaces/ToString.html b/docs/interfaces/ToString.html index 63f9aee..b644c5c 100644 --- a/docs/interfaces/ToString.html +++ b/docs/interfaces/ToString.html @@ -1,4 +1,4 @@ -ToString | @matrixai/logger
    +ToString | @matrixai/logger
    -
    +

    Properties

    -
    - -
    toString: (() => string)
    +
    + +
    toString: (() => string)

    Type declaration

    • -
        +
        • (): string
        • Returns string

    - +
    +

    On This Page

    -
    - + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/modules.html b/docs/modules.html index 7e994c4..ec8530c 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,4 +1,4 @@ -@matrixai/logger
    +@matrixai/logger
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/modules/formatting.html b/docs/modules/formatting.html index c6f92cb..7b9bf4c 100644 --- a/docs/modules/formatting.html +++ b/docs/modules/formatting.html @@ -1,4 +1,4 @@ -formatting | @matrixai/logger
    +formatting | @matrixai/logger
    -
    +
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/types/LogData.html b/docs/types/LogData.html index f49b5df..8b889f4 100644 --- a/docs/types/LogData.html +++ b/docs/types/LogData.html @@ -1,4 +1,4 @@ -LogData | @matrixai/logger
    +LogData | @matrixai/logger
    -
    +

    Type alias LogData

    -
    LogData: Record<LogDataKey, LogDataValue>
    +
    LogData: Record<LogDataKey, LogDataValue>

    Custom log data

    -
    +
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/types/LogDataKey.html b/docs/types/LogDataKey.html index 5b2c48c..a14167b 100644 --- a/docs/types/LogDataKey.html +++ b/docs/types/LogDataKey.html @@ -1,4 +1,4 @@ -LogDataKey | @matrixai/logger
    +LogDataKey | @matrixai/logger
    -
    +

    Type alias LogDataKey

    -
    LogDataKey: string | number
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/types/LogDataValue.html b/docs/types/LogDataValue.html index 7e5deda..e15c877 100644 --- a/docs/types/LogDataValue.html +++ b/docs/types/LogDataValue.html @@ -1,4 +1,4 @@ -LogDataValue | @matrixai/logger
    +LogDataValue | @matrixai/logger
    -
    +

    Type alias LogDataValue

    -
    LogDataValue: number | string | boolean | null | undefined | ToJSON | (() => LogDataValue) | LogDataValue[] | {
        [key: LogDataKey]: LogDataValue;
    }
    +
    LogDataValue: number | string | boolean | null | undefined | ToJSON | (() => LogDataValue) | LogDataValue[] | {
        [key: LogDataKey]: LogDataValue;
    }

    Custom log data values Values can be made lazy by wrapping it as a lambda

    -
    +
    +

    Type declaration

    +
    +
    +

    Type declaration

    +
    +
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/types/LogFormatter.html b/docs/types/LogFormatter.html index ac176d2..fa95367 100644 --- a/docs/types/LogFormatter.html +++ b/docs/types/LogFormatter.html @@ -1,4 +1,4 @@ -LogFormatter | @matrixai/logger
    +LogFormatter | @matrixai/logger
    -
    +

    Type alias LogFormatter

    -
    LogFormatter: ((record: LogRecord) => string)
    +
    LogFormatter: ((record) => string)

    Type declaration

    Returns string

    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/types/LogRecord.html b/docs/types/LogRecord.html index c405adc..6f01015 100644 --- a/docs/types/LogRecord.html +++ b/docs/types/LogRecord.html @@ -1,4 +1,4 @@ -LogRecord | @matrixai/logger
    +LogRecord | @matrixai/logger
    -
    +

    Type alias LogRecord

    -
    LogRecord: {
        data: LogData;
        date: (() => Date);
        key: string;
        keys: string;
        level: LogLevel;
        logger: default;
        msg: string | undefined;
        stack: (() => string);
    }
    +
    LogRecord: {
        data: LogData;
        date: (() => Date);
        key: string;
        keys: string;
        level: LogLevel;
        logger: default;
        msg: string | undefined;
        stack: (() => string);
    }

    Finalised log records

    Type declaration

    • -
      data: LogData
    • +
      data: LogData
    • -
      date: (() => Date)
      +
      date: (() => Date)
      • -
          -
        • (): Date
        • +
            +
          • (): Date
          • -

            Returns Date

      • +

        Returns Date

  • -
    key: string
  • +
    key: string
  • -
    keys: string
  • +
    keys: string
  • -
    level: LogLevel
  • +
    level: LogLevel
  • -
    logger: default
  • +
    logger: default
  • -
    msg: string | undefined
  • +
    msg: string | undefined
  • -
    stack: (() => string)
    +
    stack: (() => string)
    • -
        +
        • (): string
        • -

          Returns string

  • +
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.data.html b/docs/variables/formatting.data.html index d707dfa..d89c118 100644 --- a/docs/variables/formatting.data.html +++ b/docs/variables/formatting.data.html @@ -1,4 +1,4 @@ -data | @matrixai/logger
    +data | @matrixai/logger
    -
    +

    Variable dataConst

    -
    data: typeof data = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.date.html b/docs/variables/formatting.date.html index 795fa09..f43d892 100644 --- a/docs/variables/formatting.date.html +++ b/docs/variables/formatting.date.html @@ -1,4 +1,4 @@ -date | @matrixai/logger
    +date | @matrixai/logger
    -
    +

    Variable dateConst

    -
    date: typeof date = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.key.html b/docs/variables/formatting.key.html index f769092..469a2d9 100644 --- a/docs/variables/formatting.key.html +++ b/docs/variables/formatting.key.html @@ -1,4 +1,4 @@ -key | @matrixai/logger
    +key | @matrixai/logger
    -
    +

    Variable keyConst

    -
    key: typeof key = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.keys.html b/docs/variables/formatting.keys.html index 2f00bc0..b64c404 100644 --- a/docs/variables/formatting.keys.html +++ b/docs/variables/formatting.keys.html @@ -1,4 +1,4 @@ -keys | @matrixai/logger
    +keys | @matrixai/logger
    -
    +

    Variable keysConst

    -
    keys: typeof keys = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.level.html b/docs/variables/formatting.level.html index 1b6a8a3..1f60d49 100644 --- a/docs/variables/formatting.level.html +++ b/docs/variables/formatting.level.html @@ -1,4 +1,4 @@ -level | @matrixai/logger
    +level | @matrixai/logger
    -
    +

    Variable levelConst

    -
    level: typeof level = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.msg.html b/docs/variables/formatting.msg.html index 73b68da..7e36049 100644 --- a/docs/variables/formatting.msg.html +++ b/docs/variables/formatting.msg.html @@ -1,4 +1,4 @@ -msg | @matrixai/logger
    +msg | @matrixai/logger
    -
    +

    Variable msgConst

    -
    msg: typeof msg = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/formatting.stack.html b/docs/variables/formatting.stack.html index cd85f59..c7be91d 100644 --- a/docs/variables/formatting.stack.html +++ b/docs/variables/formatting.stack.html @@ -1,4 +1,4 @@ -stack | @matrixai/logger
    +stack | @matrixai/logger
    -
    +

    Variable stackConst

    -
    stack: typeof stack = ...
    -
    +
    - +
  • LogLevel
  • +
  • ConsoleErrHandler
  • +
  • ConsoleOutHandler
  • +
  • Handler
  • +
  • StreamHandler
  • +
  • default
  • +
  • ToJSON
  • +
  • ToString
  • +
  • LogData
  • +
  • LogDataKey
  • +
  • LogDataValue
  • +
  • LogFormatter
  • +
  • LogRecord
  • +
  • hasCaptureStackTrace
  • +
  • hasStackTraceLimit
  • +
  • evalLogData
  • +
  • evalLogDataValue
  • +
  • levelToString
  • +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/hasCaptureStackTrace.html b/docs/variables/hasCaptureStackTrace.html index ba6647e..350ac53 100644 --- a/docs/variables/hasCaptureStackTrace.html +++ b/docs/variables/hasCaptureStackTrace.html @@ -1,4 +1,4 @@ -hasCaptureStackTrace | @matrixai/logger
    +hasCaptureStackTrace | @matrixai/logger
    -
    +

    Variable hasCaptureStackTraceConst

    -
    hasCaptureStackTrace: boolean = ...
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/hasStackTraceLimit.html b/docs/variables/hasStackTraceLimit.html index 9f02c06..ea1e5c2 100644 --- a/docs/variables/hasStackTraceLimit.html +++ b/docs/variables/hasStackTraceLimit.html @@ -1,4 +1,4 @@ -hasStackTraceLimit | @matrixai/logger
    +hasStackTraceLimit | @matrixai/logger
    -
    +

    Variable hasStackTraceLimitConst

    -
    hasStackTraceLimit: boolean = ...
    -
    + +

    Generated using TypeDoc

    -
    \ No newline at end of file +
    \ No newline at end of file From 22dc754acbd3a1dfe5963d344847a39af98e4594 Mon Sep 17 00:00:00 2001 From: Roger Qiu Date: Sat, 12 Aug 2023 02:30:56 +1000 Subject: [PATCH 3/9] feat: switch to using `"imports"` instead of `@` aliases --- benches/logger_filtered.ts | 2 +- benches/logger_handlers.ts | 2 +- benches/logger_hierarchy.ts | 2 +- benches/logger_structured.ts | 6 +- benches/logger_text.ts | 4 +- benches/results/logger_filtered.chart.html | 14 +- benches/results/logger_filtered.json | 401 ++++--- benches/results/logger_filtered_metrics.txt | 12 +- benches/results/logger_handlers.chart.html | 14 +- benches/results/logger_handlers.json | 401 ++++--- benches/results/logger_handlers_metrics.txt | 12 +- benches/results/logger_hierarchy.chart.html | 14 +- benches/results/logger_hierarchy.json | 825 ++++++------- benches/results/logger_hierarchy_metrics.txt | 24 +- benches/results/logger_structured.chart.html | 14 +- benches/results/logger_structured.json | 824 +++++++------ benches/results/logger_structured_metrics.txt | 24 +- benches/results/logger_text.chart.html | 14 +- benches/results/logger_text.json | 1038 ++++++++--------- benches/results/logger_text_metrics.txt | 28 +- benches/results/metrics.txt | 100 +- benches/utils/BenchHandler.ts | 2 +- jest.config.mjs | 9 - package-lock.json | 66 +- package.json | 8 +- tests/index.test.ts | 2 +- tsconfig.json | 4 +- 27 files changed, 1913 insertions(+), 1953 deletions(-) diff --git a/benches/logger_filtered.ts b/benches/logger_filtered.ts index 20fe116..89fee2b 100644 --- a/benches/logger_filtered.ts +++ b/benches/logger_filtered.ts @@ -1,8 +1,8 @@ import path from 'node:path'; import url from 'node:url'; import b from 'benny'; -import Logger, { LogLevel, formatting } from '@'; import { BenchHandler, suiteCommon } from './utils/index.js'; +import Logger, { LogLevel, formatting } from '#index.js'; const filePath = url.fileURLToPath(import.meta.url); diff --git a/benches/logger_handlers.ts b/benches/logger_handlers.ts index aa1bc58..3122b82 100644 --- a/benches/logger_handlers.ts +++ b/benches/logger_handlers.ts @@ -3,8 +3,8 @@ import path from 'node:path'; import url from 'node:url'; import fs from 'node:fs'; import b from 'benny'; -import Logger, { LogLevel, StreamHandler, ConsoleErrHandler } from '@'; import { suiteCommon } from './utils/index.js'; +import Logger, { LogLevel, StreamHandler, ConsoleErrHandler } from '#index.js'; const filePath = url.fileURLToPath(import.meta.url); diff --git a/benches/logger_hierarchy.ts b/benches/logger_hierarchy.ts index a843f91..5679b01 100644 --- a/benches/logger_hierarchy.ts +++ b/benches/logger_hierarchy.ts @@ -1,8 +1,8 @@ import path from 'node:path'; import url from 'node:url'; import b from 'benny'; -import Logger, { LogLevel, formatting } from '@'; import { BenchHandler, suiteCommon } from './utils/index.js'; +import Logger, { LogLevel, formatting } from '#index.js'; const filePath = url.fileURLToPath(import.meta.url); diff --git a/benches/logger_structured.ts b/benches/logger_structured.ts index 09b77ac..def33a9 100644 --- a/benches/logger_structured.ts +++ b/benches/logger_structured.ts @@ -1,14 +1,14 @@ -import type { LogRecord } from '@/types'; +import type { LogRecord } from '#types.js'; import path from 'node:path'; import url from 'node:url'; import b from 'benny'; +import { BenchHandler, suiteCommon } from './utils/index.js'; import Logger, { LogLevel, formatting, levelToString, evalLogDataValue, -} from '@'; -import { BenchHandler, suiteCommon } from './utils/index.js'; +} from '#index.js'; const filePath = url.fileURLToPath(import.meta.url); diff --git a/benches/logger_text.ts b/benches/logger_text.ts index d30eae8..d3cad1e 100644 --- a/benches/logger_text.ts +++ b/benches/logger_text.ts @@ -1,8 +1,8 @@ import path from 'node:path'; import url from 'node:url'; import b from 'benny'; -import Logger, { LogLevel, formatting } from '@'; -import { BenchHandler, suiteCommon } from './utils'; +import { BenchHandler, suiteCommon } from './utils/index.js'; +import Logger, { LogLevel, formatting } from '#index.js'; const filePath = url.fileURLToPath(import.meta.url); diff --git a/benches/results/logger_filtered.chart.html b/benches/results/logger_filtered.chart.html index 5b5dbe9..719c517 100644 --- a/benches/results/logger_filtered.chart.html +++ b/benches/results/logger_filtered.chart.html @@ -28,7 +28,7 @@
    - +