I did wrote a Log class some time ago. It was something like this (simplified):
TYPE
TLogClass = CLASS
PRIVATE
{ The higher the most "log" will write }
fLogLevel: INTEGER;
PUBLIC
CONSTRUCTOR Create (aLogLevel: INTEGER = -1);
PROCEDURE Out (Text: STRING; Level: INTEGER);
PROPERTY Level: INTEGER READ fLogLevel WRITE fLogLevel;
END;
CONSTRUCTOR TLogClass.Create (aLogLevel: INTEGER);
BEGIN
fLogLevel := aLogLevel;
END;
PROCEDURE TLogClass.Out (Text: STRING; Level: INTEGER);
BEGIN
IF Level <= fLogLevel THEN
BEGIN
WriteInLogFile (Text);
END;
END;
The use was as this (also simplified):
VAR
LogFile: TLogClass;
LogLevel: INTEGER;
BEGIN
IF (ParamCount > 1) AND (ParamStr (1) = '-DEBUG') THEN
LogLevel := 1
ELSE
LogLevel := 0;
LogFile := TLogClass.Create (LogLevel);
{ At some point of the program... }
LogFile.Out ('We will do something', 1); { This will write the log if "LogLevel" is 1 or bigger }
LogFile.Out ('This message will not be written', 3); { This will write the log if "LogLevel" is 3 or bigger }
{ An finally }
LogFile.Free;
END.
The actual class defined some constants to name the log level (NONE, INFO, ERROR, ALL, etc) and manages the file, creating it if it doesn't exists, flushing the output, closing it, etc.