Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Unified logging across z2m/zh/zhc #21984

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import stringify from 'json-stable-stringify-without-jsonify';
import assert from 'assert';
import bind from 'bind-decorator';
import * as zhc from 'zigbee-herdsman-converters';
import {setLogger as zhcSetLogger} from 'zigbee-herdsman-converters';
import {setLogger as zhSetLogger} from 'zigbee-herdsman';

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / ci

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

Check failure on line 12 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Module '"zigbee-herdsman"' has no exported member 'setLogger'.

// Extensions
import ExtensionFrontend from './extension/frontend';
Expand Down Expand Up @@ -60,6 +61,8 @@

constructor(restartCallback: () => void, exitCallback: (code: number, restart: boolean) => void) {
logger.init();
zhSetLogger(logger);
zhcSetLogger(logger);

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / ci

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 65 in lib/controller.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.
this.eventBus = new EventBus();
this.zigbee = new Zigbee(this.eventBus);
this.mqtt = new MQTT(this.eventBus);
Expand Down Expand Up @@ -92,8 +95,6 @@
/* istanbul ignore next */
settings.get().advanced.soft_reset_timeout !== 0 && new ExtensionSoftReset(...this.extensionArgs),
].filter((n) => n);

zhc.setLogger(logger);
}

async start(): Promise<void> {
Expand Down Expand Up @@ -138,9 +139,9 @@
// Enable zigbee join
try {
if (settings.get().permit_join) {
logger.warn('`permit_join` set to `true` in configuration.yaml.');
logger.warn('Allowing new devices to join.');
logger.warn('Set `permit_join` to `false` once you joined all devices.');
logger.warning('`permit_join` set to `true` in configuration.yaml.');
logger.warning('Allowing new devices to join.');
logger.warning('Set `permit_join` to `false` once you joined all devices.');
}

await this.zigbee.permitJoin(settings.get().permit_join);
Expand Down
2 changes: 1 addition & 1 deletion lib/extension/availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
logger.debug(`Successfully pinged '${device.name}' (attempt ${i + 1}/${attempts})`);
break;
} catch (error) {
logger.warn(`Failed to ping '${device.name}' (attempt ${i + 1}/${attempts}, ${error.message})`);
logger.warning(`Failed to ping '${device.name}' (attempt ${i + 1}/${attempts}, ${error.message})`);
// Try again in 3 seconds.
const lastAttempt = i - 1 === attempts;
!lastAttempt && await utils.sleep(3);
Expand Down Expand Up @@ -215,7 +215,7 @@
const options: KeyValue = device.options;
const state = this.state.get(device);
const meta: zhc.Tz.Meta = {
message: this.state.get(device), mapped: device.definition, logger, endpoint_name: null,

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / ci

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.

Check failure on line 218 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to type 'Logger'.
options, state, device: device.zh,
};
await converter?.convertGet?.(device.endpoint(), item.keys[0], meta)
Expand Down
4 changes: 2 additions & 2 deletions lib/extension/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export default class Bind extends Extension {
await endpoint.configureReporting(bind.cluster.name, items);
logger.info(`Successfully setup reporting for '${entity}' cluster '${bind.cluster.name}'`);
} catch (error) {
logger.warn(`Failed to setup reporting for '${entity}' cluster '${bind.cluster.name}'`);
logger.warning(`Failed to setup reporting for '${entity}' cluster '${bind.cluster.name}'`);
}
}
}
Expand Down Expand Up @@ -436,7 +436,7 @@ export default class Bind extends Extension {
await endpoint.configureReporting(cluster, items);
logger.info(`Successfully disabled reporting for '${entity}' cluster '${cluster}'`);
} catch (error) {
logger.warn(`Failed to disable reporting for '${entity}' cluster '${cluster}'`);
logger.warning(`Failed to disable reporting for '${entity}' cluster '${cluster}'`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/extension/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

if (!device.definition || !device.definition.configure) {
logger.warn(`Skipping configure of '${device.name}', device does not require this.`);
logger.warning(`Skipping configure of '${device.name}', device does not require this.`);
return;
}

Expand Down Expand Up @@ -119,7 +119,7 @@

logger.info(`Configuring '${device.name}'`);
try {
await device.definition.configure(device.zh, this.zigbee.firstCoordinatorEndpoint(), logger);

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / ci

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.

Check failure on line 122 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Argument of type '{ init: () => void; logOutput: () => void; warning: (message: string, namespace?: string) => void; error: (message: string, namespace?: string) => void; info: (message: string, namespace?: string) => void; ... 6 more ...; winston: () => winston.Logger; }' is not assignable to parameter of type 'Logger'.
logger.info(`Successfully configured '${device.name}'`);
device.zh.meta.configured = zhc.getConfigureKey(device.definition);
device.zh.save();
Expand Down
2 changes: 1 addition & 1 deletion lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class HomeAssistant extends Extension {

override async start(): Promise<void> {
if (!settings.get().advanced.cache_state) {
logger.warn('In order for Home Assistant integration to work properly set `cache_state: true');
logger.warning('In order for Home Assistant integration to work properly set `cache_state: true');
}

this.zigbee2MQTTVersion = (await utils.getZigbee2MQTTVersion(false)).version;
Expand Down
2 changes: 1 addition & 1 deletion lib/extension/legacy/bridgeLegacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export default class BridgeLegacy extends Extension {
stringify({type: `touchlink`, message: 'reset_success', meta: {status: 'success'}}),
);
} else {
logger.warn('Failed to factory reset device through Touchlink');
logger.warning('Failed to factory reset device through Touchlink');
this.mqtt.publish(
'bridge/log',
stringify({type: `touchlink`, message: 'reset_failed', meta: {status: 'failed'}}),
Expand Down
2 changes: 1 addition & 1 deletion lib/extension/legacy/deviceGroupMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class DeviceGroupMembership extends Extension {
);

if (!response) {
logger.warn(`Couldn't get group membership of ${device.ieeeAddr}`);
logger.warning(`Couldn't get group membership of ${device.ieeeAddr}`);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/extension/legacy/softReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ export default class SoftReset extends Extension {
}

private async handleTimeout(): Promise<void> {
logger.warn('Soft reset timeout triggered');
logger.warning('Soft reset timeout triggered');

try {
await this.zigbee.reset('soft');
logger.warn('Soft reset ZNP due to timeout');
logger.warning('Soft reset ZNP due to timeout');
} catch (error) {
logger.warn('Soft reset failed, trying stop/start');
logger.warning('Soft reset failed, trying stop/start');

await this.zigbee.stop();
logger.warn('Zigbee stopped');
logger.warning('Zigbee stopped');

try {
await this.zigbee.start();
Expand Down
Loading
Loading