Skip to content

Commit

Permalink
feat(platform): chalk for logging with colour
Browse files Browse the repository at this point in the history
- use `chalk` for colourted logging
  • Loading branch information
johannrichard committed Dec 4, 2020
1 parent 8bc6e02 commit e927e1d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/platform.ts
Expand Up @@ -12,6 +12,7 @@ import axios, { AxiosError } from 'axios';
import axiosRetry from 'axios-retry';
import * as bodyParser from 'body-parser';
import i4h from 'intervals-for-humans';
import chalk from 'chalk';
import isValidHost from 'is-valid-host';
import * as os from 'os';
import e = require('express');
Expand Down Expand Up @@ -92,7 +93,11 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
) {
axiosRetry(axios, { retries: 5, retryDelay: axiosRetry.exponentialDelay });

this.log.debug('Finished initializing platform:', this.config.name);
this.log.debug(
chalk.redBright('[Platform]'),
'Finished initializing platform:',
this.config.name,
);

// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
Expand Down Expand Up @@ -955,10 +960,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {

// Various types of callbacks
if (button) {
this.log.warn(
'-> dingz/Multi-button Action from',
request.connection.remoteAddress,
);
this.log.info(chalk.blueBright('[ACTION] dingz'), request.ip);
// attempt-auto add of either a dingz
if (
request.connection.remoteAddress &&
Expand All @@ -974,15 +976,15 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
);
} else {
if (action) {
this.log.warn('-> Simple Button action');
this.log.info(chalk.blueBright('[ACTION] Simple'), request.ip);
this.eb.emit(
PlatformEvent.ACTION,
mac,
action as ButtonAction,
battery as number,
);
} else {
this.log.warn('-> Button Heartbeat');
this.log.info(chalk.blueBright('[HEARTBEAT]'), request.ip);
this.eb.emit(
PlatformEvent.ACTION,
mac,
Expand Down

0 comments on commit e927e1d

Please sign in to comment.