Skip to content

Commit

Permalink
Merge tag '0.3.1'
Browse files Browse the repository at this point in the history
LogTape 0.3.1
  • Loading branch information
dahlia committed May 7, 2024
2 parents 4695219 + 96140f5 commit 4b9dd75
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
30 changes: 30 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ To be released.
[#2]: https://github.com/dahlia/logtape/pull/2


Version 0.3.1
-------------

Released on May 7, 2024.

- Fixed a bug where two or more versions of LogTape were imported in the same
runtime, the `Logger` instances would not be shared between them. This was
caused by the `Logger` instances being stored in a module-level variable.


Version 0.3.0
-------------

Expand All @@ -26,6 +36,16 @@ Released on April 22, 2024.
- Added `withFilter()` function.


Version 0.2.3
-------------

Released on May 7, 2024.

- Fixed a bug where two or more versions of LogTape were imported in the same
runtime, the `Logger` instances would not be shared between them. This was
caused by the `Logger` instances being stored in a module-level variable.


Version 0.2.2
-------------

Expand Down Expand Up @@ -69,6 +89,16 @@ Released on April 20, 2024.
- Added `getRotatingFileSink()` function.


Version 0.1.2
-------------

Released on May 7, 2024.

- Fixed a bug where two or more versions of LogTape were imported in the same
runtime, the `Logger` instances would not be shared between them. This was
caused by the `Logger` instances being stored in a module-level variable.


Version 0.1.1
-------------

Expand Down
16 changes: 14 additions & 2 deletions logtape/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,16 @@ export function getLogger(category: string | readonly string[] = []): Logger {
}

/**
* The root logger.
* The symbol for the global root logger.
*/
let rootLogger: LoggerImpl | null = null;
const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");

/**
* The global root logger registry.
*/
interface GlobalRootLoggerRegistry {
[globalRootLoggerSymbol]?: LoggerImpl;
}

/**
* A logger implementation. Do not use this directly; use {@link getLogger}
Expand All @@ -373,8 +380,13 @@ export class LoggerImpl implements Logger {
readonly filters: Filter[];

static getLogger(category: string | readonly string[] = []): LoggerImpl {
let rootLogger: LoggerImpl | null = globalRootLoggerSymbol in globalThis
? (globalThis as GlobalRootLoggerRegistry)[globalRootLoggerSymbol] ?? null
: null;
if (rootLogger == null) {
rootLogger = new LoggerImpl(null, []);
(globalThis as GlobalRootLoggerRegistry)[globalRootLoggerSymbol] =
rootLogger;
}
if (typeof category === "string") return rootLogger.getChild(category);
if (category.length === 0) return rootLogger;
Expand Down

0 comments on commit 4b9dd75

Please sign in to comment.