DebugLog.txt

Blitz3D Forums/Blitz3D Programming/DebugLog.txt

Yue(Posted 2013) [#1]
Hello, I'm trying to make a debug log.txt, when loading an entity and showing a state O, or skirt and for that use.

SeekFile FileDebug%, FileSize("debug.txt")


[ 21:44:07 19 Aug 2013 ]
Loading... Puntero.png [Ok!]
[ 21:44:07 19 Aug 2013 ]
Loading... Iniciar.png [Ok!]
[ 21:44:07 19 Aug 2013 ]
Loading... Opciones.png [Ok!]
[ 21:44:07 19 Aug 2013 ]
Loading... Salir.png [Ok!]
[ 21:44:07 19 Aug 2013 ]
Loading... Nave.b3d [Faild!]


This works well, but wanted to do something more elegant, I would put a title and recoletar the time, date, and operating system and memory (User32). Any suggestions.

Greetings.


_PJ_(Posted 2013) [#2]
Maybe using LSet() and RSet May be useful.





LoadResource("Puntero.png")
LoadResource("Inciar.png")
LoadResource("Opciones.png")
LoadResource("Salir.png")
LoadResource("Nave.b3d")

Function LoadResource%(Path$)
	Local Resource%
	Debug("Loading "+Path+"...")
	Local Message$=Path+" [Loaded "
	If (Len(Path)>4)
		Select (Lower(Right(Path,3)))
			Case "b3d":
				Resource = LoadMesh(Path$)
			Default:
				;Image
				Resource = LoadImage(Path$)
		End Select
	EndIf
	
	If ( Resource )
		Message=Message+" OK!]"
	Else
		Message=Message+" Failed!]"
	End If
	Debug(Message)
	Return Resource
End Function

				
			

Const DEBUG_TRIGGER$="+dev"
Const DEBUG_FILE$="Debuglog.txt"

Global DEBUG_PATH$
Global DEBUG_STREAM%
Global DEBUG_ON

Function InitialiseDebug()
	DEBUG_ON=(Instr(Lower(CommandLine()),DEBUG_TRIGGER$)<>False)
	DEBUG_PATH=CurrentDir()+DEBUG_FILE
	DeleteFile DEBUG_PATH
End Function

Function Debug(Message$,Critical=False)
	If (Not(DEBUG_ON))
		Return
	End If
	
	If (Not(DEBUG_STREAM))
		If (FileType(DEBUG_PATH)=1)
			DEBUG_STREAM=OpenFile(DEBUG_PATH)
		Else
			DEBUG_STREAM=WriteFile(DEBUG_PATH)
		End If
		
		If (Not (DEBUG_STREAM))
			DEBUG_ON=False
			Return 
		End If
		
		SeekFile DEBUG_STREAM,(FileSize(DEBUG_PATH))
		
	End If
	
	DebugLog Message
	
	Local FormatMessage$=LSet(CurrentTime(),9)+"| "+LSet(CurrentDate(),12)+"| "+Message
	
	WriteLine DEBUG_STREAM,FormatMessage
	
	If (Critical)
		RuntimeError Message
	End If	
	
End Function 




Imperium(Posted 2013) [#3]
I've been looking for a better way to debug this is very useful. Thanks!