Better logging

This commit is contained in:
Skylar Grant 2023-01-06 17:32:29 -05:00
parent 88206c8208
commit c505c858dc

View File

@ -115,11 +115,13 @@ const functions = {
startup () { startup () {
// Basic startup just enables the auger // Basic startup just enables the auger
config.status.auger = 1; config.status.auger = 1;
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger enabled.`);
return; return;
}, },
shutdown() { shutdown() {
// Basic shutdown only needs to disable the auger // Basic shutdown only needs to disable the auger
config.status.auger = 0; config.status.auger = 0;
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger disabled.`);
}, },
// Pauses the script for the time defined in env variables // Pauses the script for the time defined in env variables
pause() { pause() {
@ -160,6 +162,8 @@ const functions = {
config.intervals.augerOff = newSettings.augerOff; config.intervals.augerOff = newSettings.augerOff;
config.intervals.augerOn = newSettings.augerOn; config.intervals.augerOn = newSettings.augerOn;
config.intervals.pause = newSettings.pause; config.intervals.pause = newSettings.pause;
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Intervals updated: (${newSettings.augerOn}/${newSettings.augerOff}/${newSettings.pause})`);
} }
fs.writeFile('./config.json', JSON.stringify(config), (err) => { fs.writeFile('./config.json', JSON.stringify(config), (err) => {
if (err) reject(err); if (err) reject(err);
@ -230,7 +234,7 @@ const functions = {
// Setup for use with the Pi's GPIO pins // Setup for use with the Pi's GPIO pins
switch (process.env.ONPI) { switch (process.env.ONPI) {
case 'true': case 'true':
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] == Running on a Raspberry Pi.`); console.log(`== Running on a Raspberry Pi.`);
var gpio = require('rpi-gpio'); var gpio = require('rpi-gpio');
functions.init(gpio).then((res) => { functions.init(gpio).then((res) => {
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);
@ -241,7 +245,7 @@ switch (process.env.ONPI) {
}); });
break; break;
case 'false': case 'false':
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Not running on a Raspberry Pi.`); console.log(`I: Not running on a Raspberry Pi.`);
var gpio = 'gpio'; var gpio = 'gpio';
functions.init(gpio).then(res => { functions.init(gpio).then(res => {
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);