- Joined
- Dec 6, 2009
- Messages
- 79
JASS:
//@ Debug Log library by DoctorGester, 2011, v 1.0.0.1
// This little system allows you to use preload exploit for saving debug on the hard drive.
// Installation:
// Create a new trigger, convert it into code, delete existing code and paste Debug Log code into that
// or just copy Debug Log into the custom code section.
// API:
// LogAdd(string)
// - Add string into the log.
// LogClear()
// - Clears the log.
// LogUpdate()
// - Manually updates the log.
// Requirements:
// Jass New Gen Pack 5d
// cJass 1.4.2.27 : [url]http://code.google.com/p/cjass/downloads/list[/url]
library DebugLog{
//Settings:
#define{
private SavePath = \\Dir\\Debug
private AutoSaveLog = true
private LogSavePeriod = 1.0
}
//Code:
#include "cj_types_priv.j"
private string DebugLog[8192]
private int CurrentString = 0
private int Seconds = 0
private int Minutes = 0
private constant int StringLimit = 200
void LogAdd(string s){
string sec = I2S(Seconds)
if (Seconds < 10){
sec = "0" + sec
}
DebugLog[CurrentString] = DebugLog[CurrentString] + ("[" + I2S(Minutes) + ":" + sec + "] " + s + "\n")
if (StringLength(DebugLog[CurrentString]) >= StringLimit){
CurrentString++
}
}
optional void LogClear(){
for(int i = 0; i <= CurrentString; i++){
DebugLog[i] = ""
}
CurrentString = 0
}
void LogUpdate(){
PreloadGenClear()
PreloadGenStart()
for(int i = 0; i <= CurrentString; i++){
Preload("\")\n" + DebugLog[i] + "\n(\"")
}
PreloadGenEnd(`SavePath` + ".txt")
}
private void DebugLogOnTimer(){
Seconds++
if (Seconds > 59){
Seconds = 0
Minutes++
}
}
callback onInit(){
#if AutoSaveLog
TimerStart(CreateTimer(), LogSavePeriod, true, function LogUpdate)
#endif
TimerStart(CreateTimer(), 1., true, function DebugLogOnTimer)
LogAdd("By DoctorGester. Last compilation: " + `DATE` + " " + `TIME`)
}
}
JASS:
library DebugLog
globals
private constant string SAVE_PATH = "C:\\Users\\"
private constant boolean AUTO_SAVE = false
private constant real SAVE_INTERVAL = 1.0
private string array log
private integer index = 0
private integer seconds = 0
private integer minutes = 0
endglobals
function LogAdd takes string s returns nothing
local string sec=I2S(seconds)
if seconds<10 then
set sec="0"+sec
endif
set log[index]="[" + I2S(minutes) + ":" + sec + "] " + s + "\n"
set index=index+1
endfunction
function LogClear takes nothing returns nothing
local integer i = 0
loop
exitwhen i>index
set log[i]=""
set i=i+1
endloop
set index = 0
endfunction
function LogUpdate takes nothing returns nothing
local integer i=0
call PreloadGenClear()
call PreloadGenStart()
loop
exitwhen i>index
call Preload("\")\n" + log[i] + "\n(\"")
set i=i+1
endloop
call PreloadGenEnd(SAVE_PATH+"DebugLog.txt")
endfunction
private function TimeBuffer takes nothing returns nothing
set seconds=seconds+1
if seconds>59 then
set seconds=0
set minutes=minutes+1
endif
endfunction
private module Init
private static method onInit takes nothing returns nothing
static if AUTO_SAVE then
call TimerStart(CreateTimer(),SAVE_INTERVAL,true,function LogUpdate)
endif
call TimerStart(CreateTimer(),1.,true,function TimeBuffer)
endmethod
endmodule
private struct Inits extends array
implement Init
endstruct
endlibrary
Last edited: