During the development of my new Homey-App S.A.R.A.H, I came across a simple solution for the topic “Global-Log”. The respective app-developer only has to integrate a few lines of code into his app and the app-user has to create 3 additional flows (for log, error and debug messages) by passing the log messages to the log app.
Chris
Change
- Prefix for Error & Debug message changed
Bdw: I haven’t migrated to Homey v2 yet, but it should work …
For App-Developers:
(Just Copy&Paste the code)
Add to app.js
onInit() {
// Initialize Homey-App Loggers
this.appLogListener = new Homey.FlowCardTrigger("app_log_listener");
this.appLogListener.register().registerRunListener(Promise.resolve(true));
this.appErrorListener = new Homey.FlowCardTrigger("app_error_listener");
this.appErrorListener.register().registerRunListener(Promise.resolve(true));
this.appDebugListener = new Homey.FlowCardTrigger("app_debug_listener");
this.appDebugListener.register().registerRunListener(Promise.resolve(true));
// Sample
// this.log("Log message");
// this.error("Error-Log message");
// this.debug("Debug-Log message");
this.log(`${Homey.app.manifest.name.en}-App - v${Homey.app.manifest.version} is running...`);
...
}
// Homey-App Loggers
log(msg) {
super.log(msg);
// Send to logger
if (this.appLogListener) {
this.appLogListener.trigger({ name: `${Homey.app.manifest.name.en}`, msg: msg }).catch(err => super.error(err.message));
}
}
error(msg) {
super.error(`### ${msg}`);
// Send to error logger
if (this.appErrorListener) {
this.appErrorListener.trigger({ name: `${Homey.app.manifest.name.en}`, msg: msg }).catch(err => super.error(err.message));
}
}
debug(msg) {
super.log(`»»» ${msg}`);
// Send to debug logger
if (this.appDebugListener) {
this.appDebugListener.trigger({ name: `${Homey.app.manifest.name.en}`, msg: msg }).catch(err => super.error(err.message));
}
}
Add to App.json
"flow": {
"triggers": [
......
{
"id": "app_log_listener",
"title": { "en": "Homey-App - Logger" },
"tokens": [
{
"name": "name",
"type": "string",
"title": {
"en": "name"
},
"example": {
"en": "App-Name"
}
},
{
"name": "msg",
"type": "string",
"title": {
"en": "msg"
},
"example": {
"en": "Log message"
}
}
]
},
{
"id": "app_error_listener",
"title": { "en": "Homey-App - Error-Logger" },
"tokens": [
{
"name": "name",
"type": "string",
"title": {
"en": "name"
},
"example": {
"en": "App-Name"
}
},
{
"name": "msg",
"type": "string",
"title": {
"en": "msg"
},
"example": {
"en": "Error message"
}
}
]
},
{
"id": "app_debug_listener",
"title": { "en": "Homey-App - Debug-Logger" },
"tokens": [
{
"name": "name",
"type": "string",
"title": {
"en": "name"
},
"example": {
"en": "App-Name"
}
},
{
"name": "msg",
"type": "string",
"title": {
"en": "msg"
},
"example": {
"en": "Debug message"
}
}
]
}
For App-User:
If you miss this feature in your app, ask the respective app developer if he can implement the “Homey-App Logger”.
Add Homey-App - Logger (with Simple LOG)
Create a Flow: [App-Name] Homey-App - Logger
Add Homey-App - Error-Logger (with Simple LOG)
Create a Flow: [App-Name] Homey-App - Error-Logger
Add Homey-App - Debug-Logger (with Simple LOG)
(Works only in debug-mode)
Create a Flow: [App-Name] Homey-App - Debug-Logger -Flow
Sample:
Basic:
Simple-LOG output:
2019-03-08 09:54:08 [S.A.R.A.H] Log message
2019-03-08 09:54:08 [S.A.R.A.H] ERROR: Error-Log message
2019-03-08 09:54:08 [S.A.R.A.H] DEBUG: Debug-Log message
Terminal output:
2019-03-08 09:54:08 [log] [SarahApp] Log message
2019-03-08 09:54:08 [err] [SarahApp] Error-Log message
2019-03-08 09:54:08 [log] [SarahApp] DEBUG: Debug-Log message
Real-World example:
Simple-LOG output:
2019-03-08 15:23:39 [Simple LOG] Cleared all logging data
2019-03-08 15:24:11 [S.A.R.A.H] S.A.R.A.H-App - v0.0.1 is running...
2019-03-08 15:24:11 [S.A.R.A.H] Initialize settings
2019-03-08 15:24:34 [Home::Internal] onSwitch-InitSarah
2019-03-08 15:24:34 [S.A.R.A.H] Event fired -> Home::Internal #initSarah ()
2019-03-08 15:24:34 [S.A.R.A.H] Event matched -> Home::Internal #initSarah ()
2019-03-08 15:24:34 [Home::Internal] at-InitSarah
2019-03-08 15:24:34 [S.A.R.A.H] Event fired -> Home::Internal #initHome ()
2019-03-08 15:24:34 [S.A.R.A.H] Event matched -> Home::Internal #initHome ()
2019-03-08 15:24:34 [LivingRoom::Light] Home::Internal::initHome
2019-03-08 15:24:34 [S.A.R.A.H] Event fired -> Wohnzimmer::Light #powerOff ()
2019-03-08 15:24:34 [S.A.R.A.H] Event matched -> Wohnzimmer::Light #powerOff ()
2019-03-08 15:24:35 [LivingRoom::Light] atPowerOff
2019-03-08 15:24:38 [Home::Internal] atInitSarah - ToD > Daytime
2019-03-08 15:24:38 [S.A.R.A.H] Event fired -> Home::ToD #atDaytime ()
2019-03-08 15:24:38 [S.A.R.A.H] Event matched -> Home::ToD #atDaytime ()
2019-03-08 15:24:38 [Home::ToD] atDaytime
2019-03-08 17:50:44 [Home::ToD] onAuto-Evening
2019-03-08 17:50:44 [S.A.R.A.H] Event fired -> Home::ToD #atEvening ()
2019-03-08 17:50:44 [S.A.R.A.H] Event matched -> Home::ToD #atEvening ()
2019-03-08 17:50:44 [S.A.R.A.H] Event matched -> Home::ToD #atEvening ()
2019-03-08 17:50:44 [S.A.R.A.H] Event matched -> Home::ToD #atEvening ()
2019-03-08 17:50:44 [LivingRoom::Light] Home::ToD::atEvening
2019-03-08 17:50:44 [Home::ToD] atEvening
2019-03-08 17:50:45 [S.A.R.A.H] Event fired -> Büro::Light #easyLight-mode ()
2019-03-08 17:50:45 [S.A.R.A.H] Event fired -> Wohnzimmer::Light #light-mode ()
2019-03-08 17:50:45 [S.A.R.A.H] State changed -> Home::ToD::timeOfDay Daytime [to] Evening
2019-03-08 17:50:45 [S.A.R.A.H] Event matched -> Büro::Light #easyLight-mode ()
2019-03-08 17:50:45 [Office::Light] atEasyLight-Mode
2019-03-08 17:50:45 [S.A.R.A.H] Event matched -> Wohnzimmer::Light #light-mode ()
2019-03-08 17:50:45 [LivingRoom::Light] atLight-Mode
2019-03-08 17:50:45 [S.A.R.A.H] State-Value matched -> Home::ToD::timeOfDay = Evening
2019-03-08 17:50:45 [S.A.R.A.H] State changed -> Büro::Light::power Off [to] On
2019-03-08 17:50:46 [S.A.R.A.H] State changed -> Wohnzimmer::Light::power Off [to] On
Terminal output:
2019-03-08 10:02:54 [log] [SarahApp] S.A.R.A.H-App - v0.0.1 is running...
2019-03-08 10:02:54 [log] [SarahApp] Initialize settings
2019-03-08 10:03:14 [log] [SarahApp] Event fired -> Home::Internal #initSarah ()
2019-03-08 10:03:14 [log] [SarahApp] Event matched -> Home::Internal #initSarah ()
2019-03-08 10:03:14 [log] [SarahApp] Event fired -> Home::Internal #initHome ()
2019-03-08 10:03:14 [log] [SarahApp] Event matched -> Home::Internal #initHome ()
2019-03-08 10:03:14 [log] [SarahApp] Event fired -> Wohnzimmer::Light #powerOff ()
2019-03-08 10:03:14 [log] [SarahApp] Event matched -> Wohnzimmer::Light #powerOff ()
2019-03-08 10:03:17 [log] [SarahApp] Event fired -> Home::ToD #atDaytime ()
2019-03-08 10:03:18 [log] [SarahApp] Event matched -> Home::ToD #atDaytime ()