📣 Logtail is now part of Better Stack. Learn more ⇗
This package provides integration between your Homey app and Betterstack logging service. By using this package, you can easily log events, errors, and other information from your Homey app to Betterstack for monitoring and analysis.
- Create an account and project on Betterstack.
- Obtain the
source_token
provided by Betterstack. - Add the
source_token
asHOMEY_BETTERSTACK_TOKEN
in yourenv.json
file.
You can install the package via npm:
npm install homey-betterstack
or
yarn add homey-betterstack
const HomeyLog = require("homey-betterstack");
Edit the app class to extend HomeyLog
:
//From:
class App extends Homey.App {
// To
class App extends HomeyLog {
Use this.log
or this.error
etc within your app.js
:
this.trace("Event occurred");
this.debug("Event occurred");
this.info("Event occurred"); // log is the same as info
this.log("Event occurred"); // log is the same as info
this.warn("Warning occurred", error);
this.error("Error occurred", error);
this.fatal("Fatal error occurred", error);
Use this.homey.app.log
etc from within your devices and drivers:
this.homey.app.trace("Event occurred in device/driver");
this.homey.app.debug("Event occurred in device/driver");
this.homey.app.log("Event occurred in device/driver"); // log is the same as info
this.homey.app.log("Event occurred in device/driver"); // log is the same as info
this.homey.app.warn("Warning occurred in device/driver", error);
this.homey.app.error("Error occurred in device/driver", error);
this.homey.app.fatal("Fatal error occurred in device/driver", error);
Make sure to remove any log functions in your app as they will overwrite the log functionality of Homey-Betterstack
log() {
console.log.bind(this, '[log]').apply(this, arguments);
}
error() {
console.error.bind(this, '[error]').apply(this, arguments);
}
class App extends HomeyLog {
async onInit() {
try {
this.log(`${Homey.manifest.id} - ${Homey.manifest.version} started...`);
} catch (error) {
this.homey.app.log(error);
}
}
}
module.exports = App;
In the terminal:
[info] com.test.app - 0.0.1 started...
In Betterstack:
It is possible to alter the loglevels and change the enable/disable the output to console/betterstack. Add the following to your Homey app env.json:
"HOMEY_BETTERSTACK_CONFIG": {
"console_enabled": "1",
"publish_enabled": "1",
"console_level": "info",
"publish_level": "info"
}
Above values are also the default values of the app.
The following log levels are available:
trace: 6,
debug: 5,
info: 4,
warn: 3,
error: 2,
fatal: 1
E.G: When setting the level to warn
everything below warn
will be logged.