From 21616aeaaf6902c6bc40835012c73dc52858d457 Mon Sep 17 00:00:00 2001 From: Izwzyzx <184772711+Izwzyzx@users.noreply.github.com> Date: Sun, 26 Feb 2023 17:53:53 -0600 Subject: [PATCH] Added timestamps to console output --- Onequestionmark.hx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Onequestionmark.hx b/Onequestionmark.hx index 049e902..702bbb2 100644 --- a/Onequestionmark.hx +++ b/Onequestionmark.hx @@ -4,6 +4,7 @@ import hxdiscord.endpoints.Endpoints; import haxe.Json; import sys.io.File; import sys.FileSystem; +using StringTools; class Onequestionmark { static var Bot:DiscordClient; @@ -12,13 +13,13 @@ class Onequestionmark { static function main() { // Init - Sys.println("onequestionmark-chat startup\r\n"); + Sys.println('[${timestamp()}] Starting onequestionmark-chat'); if (FileSystem.exists("settings.json")) { - Sys.println("Found settings.json, loading.\r\n"); + Sys.println('[${timestamp()}] Found settings.json, loading'); settings = Json.parse(File.getContent("settings.json")); } else { - Sys.println("Did not find settings.json, exiting."); + Sys.println('[${timestamp()}] Did not find settings.json, exiting'); Sys.exit(0); } @@ -29,7 +30,7 @@ class Onequestionmark { } public static function onReady() { - Sys.println("onequestionmark is online."); + Sys.println('[${timestamp()}] Bot is online'); //Endpoints.sendMessage(settings.devchannel, {content:"onequestionmark-chat alpha test is now running"}, null, false); } @@ -57,7 +58,7 @@ class Onequestionmark { case "quit": if (m.author.id == settings.botowner) { m.reply({content:"Shutdown command received from botowner, exiting."}, false); - Sys.println("Shutdown command received from botowner, exiting."); + Sys.println('[${timestamp()}] Shutdown command received from botowner, exiting'); shutdown(); } case "devmode": @@ -105,6 +106,10 @@ class Onequestionmark { } } + public static function timestamp() { + return '${StringTools.lpad(Std.string(Date.now().getHours()), "0", 2)}:${StringTools.lpad(Std.string(Date.now().getMinutes()), "0", 2)}'; + } + public static function saveSettings() { File.saveContent("settings.json", Json.stringify(settings, "\t")); }