logging function

Post your working scripts, libraries and tools
User avatar
SL5
Posts: 493
Joined: 12 May 2015, 02:10
GitHub: sl5net
Contact:

logging function

24 Feb 2018, 03:19

using:

Code: Select all

 lll( A_LineNumber, A_ScriptName, " STARTING something ")
it saves into log\MyScript.txt

Code: Select all

08:58:10   MyScript.ahk>25
STARTING something
config ingnore lists:

Code: Select all

;<<<<<<<< g_ignReg <<<< 180224082501 <<<< 24.02.2018 08:25:01 <<<<
global g_ignReg := { saveLogFiles: {ln:"", scriptName:"", text:"HotKeys"} } ;;;; regEx ignoreConfigList ;;;;
; please use it like this:     if( 1<RegExMatch(0 . ln, g_ignReg["saveLogFiles"]["ln"])	|| ......
; OR: the regEx .^ never match anything. if you use .^ i recomand using: if( RegExMatch(ln, g_ignReg["saveLogFiles"]["ln"])	|| ......
;>>>>>>>> g_ignReg >>>> 180224082506 >>>> 24.02.2018 08:25:06 >>>>
BTW i dont feel preety with this:
1<RegExMatch(0 .
i tried to use false and empty for values but with no success. empty is matching in every RegExMatch. false is converted to 0 and this is often matching. :think:
==> the regEx .^ never match anything. if you use .^ i recomand using: if( RegExMatch(ln, g_ignReg["saveLogFiles"]["ln"]) || ......

and if you may automatically set a lll in front of each function definitions, this is may helpful for you to find your functioin defs:
https://github.com/sl5net/global-Intell ... bal.txt#L4

Code: Select all

^[ ]*?\w[\w\d_]{5,}\s*\([^()+<>]+\)[\s\S]{0,5}?\{

Code: Select all


;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 lll(ln, scriptName, text="") {

    if( 1<RegExMatch(0 . ln, g_ignReg["saveLogFiles"]["ln"])		|| 1<RegExMatch(0 . scriptName, g_ignReg["saveLogFiles"]["scriptName"])		|| 1<RegExMatch(0 . text, g_ignReg["saveLogFiles"]["text"]) )
		return

	ln .= "`n"
	text .= "`n"

	scriptName := trim(scriptName)
	GLOBAL_lllog_only_this_scriptName := trim(GLOBAL_lllog_only_this_scriptName)
	if(StrLen(GLOBAL_lllog_only_this_scriptName)>0) {
		do_createLog_notAppendLog:=true
		if(scriptName != GLOBAL_lllog_only_this_scriptName)
			return false
	}


;~ logFileName=log\%A_ScriptName%.log.txt
	logFileName=log\%scriptName%.log.txt

	;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	; proof randomly if ye should delte the log file 16.07.2017 12:05
	Random, rand, 1, 100
	if(rand == 1){
		FileGetSize, logFileKbytes, ,%logFileName%, K  ; Retrieve the size in Kbytes.
		if(logFileKbytes > 10){
			FileDelete,%logFileName%
			FileAppend, %A_LineNumber%: logFileDeleted %timestampHHmmss%, %logFileName%
		}else{
			; M = Modification time (this is the default if the parameter is omitted)
			FileGetTime, cFileMTime, %logFileName%, M

			diff_cFileMTime_Now_hour:=A_Now
			EnvSub, diff_cFileMTime_Now_hour, %cFileMTime%, hours

			diff_cFileMTime_Now_min:= Round(diff_cFileMTime_Now_hour / 60)

			diff_cFileMTime_Now_day:=A_Now
			EnvSub, diff_cFileMTime_Now_day, %cFileMTime%, days

			diff_cFileMTime_Now_year:= Round(diff_cFileMTime_Now_day / 365)
			;~ EnvSub, diff_cFileMTime_Now_year, %cFileMTime%, year

			if(diff_cFileMTime_Now_hour > 1){
				FileDelete,%logFileName%
				FileAppend, %A_LineNumber%: logFileDeleted %timestampHHmmss%, %logFileName%
			}
		}
		; proof randomly if ye should delte the log file 16.07.2017 12:05
		;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		;~ if(diff_cFileMTime_Now_day > 7)
			;~ FileDelete,%logFileName%
	}



	if(StrLen(scriptName) < 5 ) ; || "functions_global.inc.ahk" != A_ScriptName ... for that we need a PreCompiler !!!
	{
		lll(A_LineNumber, "functions_global.inc.ahk")

		;~ t := ""
		;~ t .= "#Include *i init_global.init.inc.ahk" . "`n"
		;~ t .= "#Include *i %A_ScriptDir%\inc_ahk\functions_global.inc.ahk" . "`n"
		;~ Clipboard := t

		Clipboard="%A_ScriptName%"
		MsgBox, functions_global.inc.ahk `n ln=%ln% `n  scriptName = %scriptName% `n parameter FILE must not be empty `n `n you find this now inside your clipboard : %Clipboard% `n `n move to line %ln% and fix the bug. `n `n or let run the SL5_AHK_preparser.ahk
		return -1
	}
	;~ tipp: use notepadd++ , diverses> ohne r?ckfraen aktuallisieren
	;~ tipp: use notepadd++ , diverses> nach aktuallisierung zum ende springen
	msg:=""
	;~ msg.= ";<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<`n"

	;~ if(strlen(text)>0)
;~ 		msgtext := """" . text . """"
;~ 	else
		;~ msgtext := text
    msgtext := text


	msg.= scriptName . ">" . ln  . msgtext  . "`n"
	;~ msg.= ";>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`n`n"

	global lll
	if(StrLen(lll)>0)
		lll .= msg
	else
		lll := msg
	; Suspend,on ; Disables or enables all or selected hotkeys and hotstrings.
	if(!FileExist("log"))
	{
		FileCreateDir,log
		if(true != InStr(FileExist("log"), "D") )
		{
		;~ would be true only if the file exists and is a directory
		MsgBox,15-05-15_17-00 ops Who could we store logfiles ?
		}
	}

;~if(StrLen(GLOBAL_lllog_only_this_scriptName)>0
	if(do_createLog_notAppendLog)
	{
		FileDelete,%logFileName%
		while(FileExist(logFileName))
			Sleep,100
		gLOBAL_lllog = GLOBAL_lllog_only_this_scriptName
		strLen_GLOBAL_lllog := StrLen(gLOBAL_lllog)
		subStr_lll__strLen := SubStr(lll,1,strLen_GLOBAL_lllog)
		if(subStr_lll__strLen != gLOBAL_lllog)
		{
		;~ MsgBox,%subStr_lll__strLen% %GLOBAL_lllog_only_this_scriptName% := GLOBAL_lllog_only_this_scriptName `n
		lll := "GLOBAL_lllog_only_this_scriptName = " . GLOBAL_lllog_only_this_scriptName . "`n" . lll
		}
	}
    FormatTime, timestampHHmmss, %A_now%,HH:mm:ss
	FileAppend, % timestampHHmmss . "   " .  lll, % logFileName
	;~ ToolTip,%logFileName% := logFileName `n
	;~ MsgBox,%lll%
	;Suspend,off
	text := "" ; iam suspicious with autohotkey dis days ;) 16.07.2017 21:03 usally we dont need to do so
	lll := ""
	return
}
;>>>>>>>>>lll >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot] and 25 guests