[BB, B+, B3D] inc_ErrorLog.bb
Übersicht

Weazle25Betreff: [BB, B+, B3D] inc_ErrorLog.bb |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Inc_ErrorLog.bb dient dazu Fehlermeldungen in eine Text-Datei zu schreiben.
InitErrorLog( AppName$, AppVersion$ ) ermittelt einen geeigneten Dateinamen für die Log-Datei. Die Log-Datei wird allerdings erst beim ersten Aufruf von AddError() erstellt wobei vorhandene Log-Dateien nicht überschrieben werden. Der Dateiname wird nach dem Schema "AppName_DebugLog_X.txt erstellt. AddError( MSG$, Critical = 0 ) fügt der Log-Datei eine Message hinzu. Ist Critical = 1 (kritischer Fehler) dann wird das Programm mit RuntimeError beendet. Die Log-Datei wird dann nach diesem Schema erstellt: Code: [AUSKLAPPEN] AppName 1.0 DebugLog - vom 22 May 2007 - 08:04:07 ====================================================================== 0001) 00:00:00:022 Hier ist ein Fehler. 0002) 00:10:00:570 Kritischer Fehler: Hier ist ein kritischer Fehler Von links nach rechts: laufende Nummer - Zeit seid Programmstart (hh:mm:ss:ms) - Message Code: [AUSKLAPPEN] Global EL_LogName$ = "" Global EL_ErrorCount = 0 Global EL_AppName$ = "" Global EL_AppVersion$ = "" Global EL_Init = 0 Global EL_Millisecs = 0 Global EL_Debug = 0 ;==================================================================================================== Function InitErrorLog( AppName$, AppVersion$ ) If EL_Init = 0 Then EL_Millisecs = MilliSecs() EL_AppName$ = AppName$ EL_AppVersion$ = AppVersion$ EL_LogName$ = ".\" + Replace( Replace( AppName$, " ", "_" ), "-", "_" ) + "_Debuglog_" i = 1 While FileType( EL_LogName$ + i + ".txt" ) = 1 i = i + 1 Wend EL_LogName$ = EL_LogName$ + i + ".txt" EL_Init = 1 EndIf End Function ;==================================================================================================== Function AddError( MSG$, Critical = 0 ) If EL_Init <> 1 Then RuntimeError "ErrorLog wurde nicht initialisiert! " + MSG$ If FileType( EL_LogName$ ) = 0 Then File = WriteFile( EL_LogName$ ) If File = 0 Then RuntimeError "Datei " + Chr( 34 ) + EL_LogName$ + Chr( 34 ) + " konnte nicht erstellt werden!" EL_Title$ = " " + EL_AppName$ + " " + EL_AppVersion$ + " DebugLog - vom " + CurrentDate$() + " - " + CurrentTime$() WriteLine( File, EL_Title$ ) mLine$ = Replace$( RSet$( "", Len( EL_Title$ ) + 10 ), " ", "=" ) WriteLine( File, mLine ) WriteLine( File, "" ) WriteLine( File, "" ) CloseFile( File ) EndIf If FileType( EL_LogName$ ) = 1 Then Size = FileSize( EL_LogName$ ) File = OpenFile( EL_LogName$ ) SeekFile( File, Size ) ErrorTime = MilliSecs() - EL_Millisecs EL_ErrorCount = EL_ErrorCount + 1 EL_ErrorCount2$ = Replace( RSet( EL_ErrorCount, 4 ), " ", "0" ) If Critical = 0 Then WriteLine( File, EL_ErrorCount2$ + ") " + GetTimeString( ErrorTime ) + " " + MSG$ ) CloseFile( File ) Else WriteLine( File, EL_ErrorCount2$ + ") " + GetTimeString( ErrorTime ) + " Kritischer Fehler: " + MSG$ ) CloseFile( File ) RuntimeError EL_ErrorCount2$ + ") " + GetTimeString( ErrorTime ) + " Kritischer Fehler: " + MSG$ EndIf EndIf End Function ;==================================================================================================== Function GetTimeString$( time ) hours = Floor(time/3600000) min = Floor(time/60000)-hours*60 sec = Floor(time/1000)-min*60-hours*3600 msec = time - ( (hours * 3600000) + (min * 60000) + (sec * 1000) ) Return Replace$( RSet( hours, 2 ) + ":" + RSet( min, 2 ) + ":" + RSet( sec, 2 ) + ":" + RSet( msec, 3 ), " ", "0" ) End Function Gruss Weazle |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group