Improved logging functionality. Different logs may not be specified and the log may be truncated upon initialization.

This commit is contained in:
Joshua Fuhs 2012-06-24 13:26:45 -04:00
parent 9c4e5dd34e
commit fb71e0d7dc
2 changed files with 22 additions and 6 deletions

View file

@ -1,6 +1,6 @@
/** /**
* bug.n - tiling window management * AHK Debug log implementation
* Copyright (c) 2010-2012 joten * Copyright (c) 2012 Joshua Fuhs
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,23 +18,36 @@
* @version 8.3.0 * @version 8.3.0
*/ */
Log_debug_level := 0
Log_init(name, truncate) {
Global
If truncate
IfExist, %name%
FileDelete, %name%
Log_name := name
}
Log_msg( message ) { Log_msg( message ) {
Local CurrentTime
If Not Log_name
Return
FormatTime, CurrentTime, , yyyyMMddHHmmss FormatTime, CurrentTime, , yyyyMMddHHmmss
FileAppend, %CurrentTime% %message%`r`n, bugn_log.txt FileAppend, %CurrentTime% %message%`r`n, %Log_name%
} }
Log_bare( message ) { Log_bare( message ) {
Local padded_message Local padded_message
If Not Log_name
Return
padded_message := " " . message . "`r`n" padded_message := " " . message . "`r`n"
FileAppend, %padded_message% , bugn_log.txt FileAppend, %padded_message% , %Log_name%
} }
Log_debug_level := 0
Log_incDebugLevel() { Log_incDebugLevel() {
Global Global
If Not Log_name
Return
If ( Log_debug_level < 9 ) If ( Log_debug_level < 9 )
{ {
Log_debug_level += 1 Log_debug_level += 1
@ -44,6 +57,8 @@ Log_incDebugLevel() {
Log_decDebugLevel() { Log_decDebugLevel() {
Global Global
If Not Log_name
Return
If ( Log_debug_level > 0 ) { If ( Log_debug_level > 0 ) {
Log_debug_level -= 1 Log_debug_level -= 1
If ( Log_debug_level = 0 ) If ( Log_debug_level = 0 )

View file

@ -32,6 +32,7 @@ SetWinDelay, 10
#WinActivateForce #WinActivateForce
; pseudo main function ; pseudo main function
Log_init("bugn_log.txt", False)
Log_msg("====== Initializing ======") Log_msg("====== Initializing ======")
If 0 = 1 If 0 = 1
Config_filePath = %1% Config_filePath = %1%