Skip to content

Commit

Permalink
feat: using local timezone for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
avbentem committed Jun 1, 2018
1 parent afda115 commit c2eccc4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Support to count specific messages during a configurable interval, to report basic statistics (and to implicitly
ensure the monitor itself is still operational).

- Displaying times in Slack and Telegram notifications in the local timezone rather than UTC.

- The log file's directory name can either be specified in `filename`, or in `dirname` (default: current folder).

### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"url": "git://github.com/avbentem/raspi-uart-monitor.git"
},
"dependencies": {
"moment": "2.22.2",
"raspi": "5.0.2",
"raspi-serial": "5.0.0",
"slack-winston": "0.0.9",
Expand Down
4 changes: 3 additions & 1 deletion reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

'use strict';

const moment = require('moment');

class Reporter {

constructor(reports, schedule, logger) {
Expand Down Expand Up @@ -77,7 +79,7 @@ class Reporter {
* @private
*/
_report() {
const msg = this.schedule.name + ' since ' + (new Date(this.lastRun)).toISOString()
const msg = this.schedule.name + ' since ' + moment(this.lastRun).format('YYYY-MM-DD HH:mm')
+ ':\n'
+ this.reports.map(report => '\u2022 ' + report.name + ": " + (this.counts[report.name] || 0)).join('\n');

Expand Down
6 changes: 4 additions & 2 deletions watchdog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

'use strict';

const moment = require('moment');

class Watchdog {

constructor(config, logger) {
Expand Down Expand Up @@ -60,7 +62,7 @@ class Watchdog {
// Don't flood the logs with the same error
return;
}
this.logger.error('No ' + this.config.name + ' since ' + (new Date(this.lastHeartbeat)).toISOString());
this.logger.error('No ' + this.config.name + ' since ' + moment(this.lastHeartbeat).format('YYYY-MM-DD HH:mm'));
if (!this.firstWatchdogError) {
this.firstWatchdogError = this.lastHeartbeat;
}
Expand All @@ -70,7 +72,7 @@ class Watchdog {

// All fine (again)
if (this.firstWatchdogError) {
this.logger.warn('First ' + this.config.name + ' since ' + (new Date(this.firstWatchdogError)).toISOString());
this.logger.warn('First ' + this.config.name + ' since ' + moment(this.firstWatchdogError).format('YYYY-MM-DD HH:mm'));
this.firstWatchdogError = this.lastWatchdogError = null;
}
}
Expand Down

0 comments on commit c2eccc4

Please sign in to comment.