danieleteti / loggerpro

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

Feature Request: Ability to support multiple log directories #46

Closed fastbike closed 3 years ago

fastbike commented 3 years ago

We have a DMVC web server where we write log entries for each request into its own file. We do this by creating a GUID when each web request is received and passing this in as the Log Tag.

Is there any simple way to use the first two characters of the GUID to write the log file into a sub-directory that uses those characters as the directory name. E.g. with a GUID of F900E9A6-4830-48CF-840B-7EB1110CCB76, write the log file to the "logs\F9" directory. The reason for this is that the file system is struggling to keep up with the number of log files we create. We're looking to use ELK to post process (and then delete) the log files on the day after the request has been served. But we are still handling approx 160k requests each day => 160k files.

I've looked at overriding the TLoggerProFileAppenderManaged.WriteLog in a sub class but it makes calls to private methods that are no accessible to a subclass. I'd rather not have to re-implement this class.

danieleteti commented 3 years ago

Hi, why don't append you logs directly to your ELK stack? There is the LoggerPro.ElasticSearchAppender.pas which is designed on purpose. If this is not viable for you, we can surely promote some private methods to virtual, but that doesn't sole the problem because you need a method to "close" a file when the request is terminated (a.k.a. "at the last log line of that request"). That could be done in a middleware. Another approach could be to append your logs in a redis instance and then use Logstash, or other specific software, to do ingestion into elasticsearch. With you don't have any problem about the number of files. There are many different solutions, I don't know the system, but IMHO overriding a method in the FileAppender is not enough. Let me know what you think.

fastbike commented 3 years ago

Thanks Daniele. I'll look at the ElasticSearchAppender once we've got the ELK stack up and running.

On the interim I have subclassed the TLoggerProFileAppenderManaged so it can deal with a file per GUI and writes to a sub directory created from the first two characters of the GUID (16x16 possible sub directories)

This issue can be closed