threadsafelog OnCustomPrefix event
Return to Introduction  Previous page  Next page
Applies to
acThreadSafeLog component.  

Declaration
type  
  TacThreadSafeLogCustomPrefixEvent = procedure(Sender: TObject; var Prefix: Stringof object;  
 
property OnCustomPrefix: TacThreadSafeLogCustomPrefixEvent;  

Description
The OnCustomPrefix event occurs when the component is about to append new line to the log file. It allows to specify custom prefix before each line of logged text. For example, you can specify current time, or identifier or calling thread or something else, which can not be specified in Options property and can not be put as prefix automatically.  

Example
procedure TForm1.acThreadSafeLog1CustomPrefix(Sender: TObject;  
  var Prefix: string);  
var  
  TickDiff: DWord;  
begin  
  // basically to specify the prefix, just put required text to Prefix parameter  
  Prefix := 'My custom prefix';  
 
  // here is more complicated example  
  TickDiff := GetTickCount - FStartTime;  
  Prefix := Format('[%d.%3.3d %s %d] %s', [TickDiff div 1000, TickDiff mod 1000,  
                   FormatDateTime(FDateTimeFormat, Now), GetCurrentThreadID, Text]);  
end;  

See also
Options and DateTimeFormat properties.