unit Emulator_Logger; interface USES Classes; const cTimePrefix=' at '; cTimeStart=Succ(Length(cTimePrefix)); type tEmulatorLoggerMode=( elmOpenNew, elmAppendToExisting ); tEmulatorLoggerError=( eleOK, eleStoppedBecauseTooLong, eleErrorWrite, eleLast ); tEmulatorLoggerFlag=( elfLogEnable, elfLogDisable, elfAddTime ); tEmulatorLoggerFlags=set of tEmulatorLoggerFlag; tEmulatorLogger=class(TObject) private prDestinationName:string; prMode:tEmulatorLoggerMode; prLastError:tEmulatorLoggerError; prStream:tFileStream; prLevel:cardinal; prLevelStr:string; prSizeLimit:cardinal; prFlags:tEmulatorLoggerFlags; prTimeBuffer:string; prTimeBufferLength:cardinal; function GetEnable:boolean; procedure SetEnable(state:boolean); function GetAddTime:boolean; procedure SetAddTime(state:boolean); procedure SetDestinationName(ADestinationName:string); procedure prLogTime; function prLog(const AStr:string):boolean; protected procedure SetLevel(ALevel:cardinal); procedure Reinit; public constructor Create(ADestinationName:string; AMode:tEmulatorLoggerMode; ASizeLimit:cardinal); overload; constructor Create(ADestinationName:string); overload; destructor Destroy; override; function Log(const AStr:string):boolean; overload; function IncLevel:cardinal; function DecLevel:cardinal; property DestinationName:string read prDestinationName write SetDestinationName; property Mode:tEmulatorLoggerMode read prMode write prMode; property SizeLimit:cardinal read prSizeLimit write prSizeLimit; property LastError:tEmulatorLoggerError read prLastError write prLastError; property Enable:boolean read GetEnable write SetEnable; property Flags:tEmulatorLoggerFlags read prFlags; property AddTime:boolean read GetAddTime write SetAddTime; end; implementation USES MMSystem, Windows, SysUtils; function tEmulatorLogger.IncLevel:cardinal; begin Inc(prLevel); Result:=prLevel; SetLength(prLevelStr,Result); prLevelStr[Result]:=' '; end; function tEmulatorLogger.DecLevel:cardinal; begin Dec(prLevel); Result:=prLevel; SetLength(prLevelStr,Result); end; procedure tEmulatorLogger.SetLevel(ALevel:cardinal); begin SetLength(prLevelStr,ALevel); if prLevel