[ACCEPTED]-Good, free Delphi logging framework-logging
Which logging library is better? mentions the following of which only the 1 last two are free.
I know it's not free - but well worth it's 9 money: CodeSite by Raize Software. Quality has its 8 price! :-)
I always enjoyed working with 7 CodeSite, especially the ability to add 6 just about any type of objects to the log 5 without huge conversions to a string format 4 was often very helpful.
Again: not free, but 3 worth its price in gold, if you really are 2 serious about production-quality logging 1 and viewing of those logs.
Marc
I have been granted access to update the 6 dormant Log4Delphi project and I have rolled 5 up 4 years of bugfixes and patches into 4 the latest 0.8 release available on Source-forge. I 3 use this library in production and have 2 found it to very stable and reliable and 1 easy to use.
A logger library shouldn't dump the contents 9 synchronously. That will slow down the application. Instead, it 8 needs to buffer the contents and dump them 7 when it is flushed.
It should also be thread-safe 6 and able to dump the contents from different 5 threads. (And preferably be able to log 4 the thread ID as well)
It should also be 3 flexible and able to log multiple output 2 formats.
Here's a library which does all 1 this: loggerpro
I'm a big fan of CodeSite, too, but if you're 2 looking for free, how about OutputDebugString 1 with either the Delphi IDE or DebugView from SysInternals.
Another alternative to Codesite is Overseer which 3 is open sourced and part of the nexus project, but stands 2 alone so does not require you to use their 1 framework.
There is another new logging framework for Delphi, which comes in a single file (nxlogging.pas). nxlogging 6 is a nice lightweight and powerful set of 5 classes like log4d (appenders, formaters), but 4 much easier tu use. It includes file appenders 3 (rolling files, all in a single one, etc...) and 2 a tcp appender too, so you can forward your 1 logs to a central logserver.
There is Log4D, another port of the Java Log4J logging framework for 10 Delphi at Sourceforge.
Log4D project page at sourceforge
A description of its 9 architecture can be found on CodeCentral and here.
Help 8 files are available online at http://cc.embarcadero.com/item/16446.
It is currently 7 based on log4j 1.2.12 and quite active, and 6 very easy to use. It includes TLogODSAppender, TLogStreamAppender, TLogFileAppender, TLogRollingFileAppender.
The 5 following example project creates a ODS 4 appender. If you run it in the IDE, the 3 log messages will appear in the ‘Event log’ window.
program Log4Dexample;
{$APPTYPE CONSOLE}
uses
Log4D,
SysUtils;
var
Logger: TLogLogger;
begin
try
// basic configuration - creates a TLogODSAppender (ODS = OutputDebugString)
TLogBasicConfigurator.Configure;
// set the log level
TLogLogger.GetRootLogger.Level := Trace;
// create a named logger
Logger := TLogLogger.GetLogger('exampleLogger');
// write log messages
Logger.Fatal('fatal output');
Logger.Error('error output');
Logger.Warn('warn output');
Logger.Info('info output');
Logger.Debug('debug output');
Logger.Trace('trace output');
ReadLn;
except
on E:Exception do
begin
Writeln(E.Classname, ': ', E.Message);
ReadLn;
end;
end;
end.
Writing 2 appenders is straightforward, here is an 1 example of a simple console appender:
unit LogConsoleAppender;
interface
uses
Log4D;
type
{ Send log messages to console output. }
TLogConsoleAppender = class(TLogCustomAppender)
protected
procedure DoAppend(const Message: string); override;
end;
implementation
{ TLogConsoleAppender }
procedure TLogConsoleAppender.DoAppend(const Message: string);
begin
if IsConsole then
Write(Message);
end;
initialization
RegisterAppender(TLogConsoleAppender);
end.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.