# TelemetryCollector-Api for developers

**URL:** <https://community.homey.app/t/telemetrycollector-api-for-developers/131548>\
**Category:** Developers\
**Tags:** app, homey-pro\
**Created:** [February 25, 2025, 6:36am UTC](https://community.homey.app/t/telemetrycollector-api-for-developers/131548 "2025-02-25T06:36:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisg/32/8825_2.png) [@ChrisG](https://community.homey.app/u/ChrisG)\
**Post date:** [February 25, 2025, 6:36am UTC](https://community.homey.app/t/telemetrycollector-api-for-developers/131548/1 "2025-02-25T06:36:17Z")

</div>

Minimal lightweight logging for Homey Apps

This [module](https://www.npmjs.com/package/homey-telemetrycollector-api) will be used in a Homey app to send logs to the [TelemetryCollector App](https://community.homey.app/t/131546).

This module is implemented as a mixin pattern to simplify the use of the interface.

(For more information about mixins, see: \> Useful Links \> Mixins)

* * *

## Setting it up

### Install

```bash
npm install homey-telemetrycollector-api

```

### Add permission

```json
"permissions": ["homey:app:org.cflat-inc.telemetryCollector"]

```

### Install TelemetryCollector-Api

```js
require('homey-telemetrycollector-api').install;

```

### Use it

```js
this.logDebug('So easy it goes');

```

* * *

## API

**Error:** error conditions

```js
this.logError('logError-Message');

```

**Warning:** warning conditions

```js
this.logWarning('logWarning-Message');

```

**Notice:** normal but significant condition

```js
this.logNotice('logNotice-Message');

```

**Informational:** informational messages

```js
this.logInfo('logInfo-Message');

```

**Debug:** debug-level messages

```js
this.logDebug('logDebug-Message');

```

* * *

## Code examples

### Homey.App

```js

'use strict';

const Homey = require('homey');

// Install the TelemetryCollector Api
require('homey-telemetrycollector-api').install;

// Development
const inspector = require('node:inspector');

if (process.env.DEBUG === '1') {
  try {
    inspector.waitForDebugger();
  } catch (err) {
    inspector.open(9229, '0.0.0.0', true);
  }
}

module.exports = class MyApp extends Homey.App {
  async onInit() {
    // ...
    this.logInfo('App has been initialized');
  }
};

```

## Migrations guide

### Preferred

Rename the methods, it’s fast (global search & replace), the code is more readable and **the method calls the console message at the end anyway**.

- this.log() \> (renameTo) \> this.logInfo()

- this.error() \> (renameTo) \> this.logError()

- this.debug() \> (renameTo) \> this.logDebug()

* * *

## Useful Links

### Logging

- [11 Best Practices for Logging in Node.js](https://betterstack.com/community/guides/logging/nodejs-logging-best-practices/)

### Mixins

- [Understanding mixins in javascript](https://basescripts.com/understanding-mixins-in-javascript)

* * *

## ToDo

- 

* * *

## Thanks

Special thanks to all for the help in testing the new version.

* * *

## Disclaimer

Use at your own risk. I accept no responsibility for any damages caused by using this app.

* * *

## Copyright

© Chris Gross / cflat-inc.org, 2025

---

<div class="post-metadata">

**Author:** ![ChrisG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisg/32/8825_2.png) [@ChrisG](https://community.homey.app/u/ChrisG)\
**Post date:** [February 25, 2025, 6:36am UTC](https://community.homey.app/t/telemetrycollector-api-for-developers/131548/2 "2025-02-25T06:36:30Z")

</div>

## Good to know

### Not all console messages are output in debug mode.

During the HP2023 beta phase, I already noticed that no console message is output for classes that inherit directly from the “Homey.SimpleClass”. I reported this to Athom and received the response “It works as designed”.

**But the TelemetryCollector-Api sends the message to the agents in any case.**

### Enhancement of the log message

Each message text is automatically enhanced by the api with the class name and, if available, the name of the device.

```js
this.logInfo('Initialized')

```

> ‘[ClassName] \> [Message]’ result: ’ MyApp \> Initialized’

> ‘[ClassName] \> [DeviceName] \> [Message]’ result: ‘MyDevice \> Sample Device \> Initialized’

## Log message and metadata.

Metadata is added to each log message. These can be used by the observability servers as filters (labels).

Example:

```json
{
  level: "debug",
  message: "PlayerDevice > Büro 31 Audio > setUnavailable()",
  timestamp: "2025-03-01T09:20:28.364Z",
  metadata: {
    id: "89e4cf57-29b0-4f38-89ff-0269e04271ea",
    app: "WiiM",
    appID: "org.cflat-inc.wiim",
    facility: "17",
    facilityName: "Device",
    class: "PlayerDevice",
    deviceID: "FF98F09C-74E9-46A5-07FF-155EFF98F09C",
    deviceName: "Büro 31 Audio",
  },
}

```

---

<div class="post-metadata">

**Author:** ![ChrisG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisg/32/8825_2.png) [@ChrisG](https://community.homey.app/u/ChrisG)\
**Post date:** [February 25, 2025, 6:36am UTC](https://community.homey.app/t/telemetrycollector-api-for-developers/131548/3 "2025-02-25T06:36:48Z")

</div>

1. For later use

---

<div class="post-metadata">

**Author:** ![ChrisG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisg/32/8825_2.png) [@ChrisG](https://community.homey.app/u/ChrisG)\
**Post date:** [February 25, 2025, 6:37am UTC](https://community.homey.app/t/telemetrycollector-api-for-developers/131548/4 "2025-02-25T06:37:00Z")

</div>

1. For later use
