Created
February 21, 2021 05:44
-
-
Save DavidMetcalfe/c176a7245ce3dd7e64abd2868bb0b4e6 to your computer and use it in GitHub Desktop.
AutoHotkey Logging function for debug and other uses since there's nothing native that seems to work well for this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DebugLogger(logText, debugLevel:="DEBUG") { | |
; Debug logging functionality for AutoHotkey (AHK). | |
; Creates one log file per day, and appends date/time to each log line. | |
; Uses debug levels: DEBUG, INFO, WARNING, ERROR, CRITICAL. | |
FormatTime, CurrentDate,, yyyy-MM-dd | |
FormatTime, CurrentDateTime,, yyyy-MM-dd hh:mm:ss | |
IfNotExist, .\log\ | |
FileCreateDir, .\log\ | |
stdout := FileOpen(".\log\" CurrentDate ".log", "a") | |
if (logText == "") { | |
stdout.WriteLine(CurrentDateTime " - No log text provided - WARNING") | |
} else if (InStr("DEBUG,INFO,WARNING,ERROR,CRITICAL", debugLevel) == 0) { | |
stdout.WriteLine(CurrentDateTime " - Invalid debug level provided - CRITICAL") | |
} else { | |
stdout.WriteLine(CurrentDateTime " - " logText " - " debugLevel) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment