danieleteti / loggerpro

An modern and pluggable logging framework for Delphi
Apache License 2.0
353 stars 91 forks source link

Configuration via INI file #47

Open fastbike opened 3 years ago

fastbike commented 3 years ago

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 ?

danieleteti commented 3 years ago

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

danieleteti commented 1 year ago

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

fastbike commented 2 months ago

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:

The BuildLogWritermay 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 ?