Skip to content

Commit

Permalink
fix(ignore): Improve performance when logging is disabled (#7955)
Browse files Browse the repository at this point in the history
* Improve logger performance

* Align package versions

* Fix eslint issue

* Align built-in logger with the main implementation

* Revert zigbee-herdsman package version so tests will run

* Fix prettier issue

* Fix CR comments

* Revert package changes
  • Loading branch information
tomer-w authored Sep 11, 2024
1 parent 3ef88dd commit decaa92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {Logger} from './types';

export let logger: Logger = {
debug: (message, namespace) => console.debug(`${namespace}: ${message}`),
info: (message, namespace) => console.info(`${namespace}: ${message}`),
warning: (message, namespace) => console.warn(`${namespace}: ${message}`),
error: (message, namespace) => console.error(`${namespace}: ${message}`),
debug: (messageOrLambda, namespace) =>
console.debug(`${namespace}: ${typeof messageOrLambda === 'function' ? messageOrLambda() : messageOrLambda}`),
info: (messageOrLambda, namespace) =>
console.info(`${namespace}: ${typeof messageOrLambda === 'function' ? messageOrLambda() : messageOrLambda}`),
warning: (messageOrLambda, namespace) =>
console.warn(`${namespace}: ${typeof messageOrLambda === 'function' ? messageOrLambda() : messageOrLambda}`),
error: (messageOrLambda, namespace) =>
console.error(`${namespace}: ${typeof messageOrLambda === 'function' ? messageOrLambda() : messageOrLambda}`),
};

export function setLogger(l: Logger): void {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type {FrameControl} from 'zigbee-herdsman/dist/zspec/zcl/definition/tstyp
import * as exposes from './exposes';

export interface Logger {
debug: (message: string, namespace: string) => void;
info: (message: string, namespace: string) => void;
warning: (message: string, namespace: string) => void;
error: (message: string, namespace: string) => void;
debug: (messageOrLambda: string | (() => string), namespace: string) => void;
info: (messageOrLambda: string | (() => string), namespace: string) => void;
warning: (messageOrLambda: string | (() => string), namespace: string) => void;
error: (messageOrLambda: string | (() => string), namespace: string) => void;
}

export type Range = [number, number];
Expand Down

0 comments on commit decaa92

Please sign in to comment.