danieleteti/loggerpro

Configuration via INI file

fastbike opened this issue · 3 comments

Some of the other logging frameworks I've previously used allow configuration at run time via INI configuration file settings. E.g. something like Log4D based on the Log4J / Log4Net code bases.

It is really useful when you hit a production issue and wish to increase the verbosity of logging from just Error through to Debug level.

Can this be done easily in LoggerPro ?

Yes, it isn't difficult to do. Can you describe what would be good in your case?

Now that dmvcframework got dotEnv support this could be done very easily.
Any news about your needs?

I've come back to this ticket as we are looking to dynamically be able to change the log level while a program is operating.
The use case is - "LogLevel is normally Warning (so web app logs out errors and warnings), but if we have a report of a production issue we want to set it to Debug while the issue is investigated".

It is possible to iterate through the appenders and set the log level on each of these. However that has no effect because the TCustomLogWriter class has a private property "FLogLevel which is compared each time the application wants to log.

procedure TCustomLogWriter.Log(const aType: TLogType; const aMessage, aTag: string);
var
  lLogItem: TLogItem;
begin
  if aType >= FLogLevel then
  begin
// you won't get to this line if the initial setting was warning and now you want debug

I can think of a number of ways to fix this:

  • add a GetLogLevel and SetLogLevel pair of methods to the ICustomLogWriter interface
  • add a GetLogLevel and SetLogLevel pair of methods to the ILogWriter interface
  • add a GetLogLevel and SetLogLevel pair of methods to a new interface and include this into the TCustomLogWriter descendant. This would required the underlying field to be protected rather than strict private.

The BuildLogWriter may also want another overloaded version that optionally takes the class type (TCustomLogWriterClass) so a custom log writer can be instantiated, otherwise the application could re implement a copy of this helper method.

@danieleteti Do you have a preference or should I do a proof of concept and create a PR ?