drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.44k stars 1.1k forks source link

Log total size or time limit #1395

Closed timomrs closed 4 months ago

timomrs commented 2 years ago

The current log size limit creates a new file after a set size limit. However, no log files are removed, which means that apps which log regularly will eventually fill the disk, given enough time.

It would be useful to be able to set a total size or age limit to the logs, after which they are deleted. Imaginary example of config.json log section:

"log": {
            //log_path: Log file path,empty by default,in which case,logs are output to the stdout
            //"log_path": "./",
            //logfile_base_name: Log file base name,empty by default which means drogon names logfile as
            //drogon.log ...
            "logfile_base_name": "",
            //log_size_limit: 100000000 bytes by default,
            //When the log file size reaches "log_size_limit", the log file is switched.
            "log_size_limit": 100000000,
            //When the total size of all created log files in the directory exceed this size, older log files 
            //(by file timestamp? Time included in file name? Some other internal  marker, such as a 
            //header line in the log?) are deleted until the size is no longer exceeded.
            "log_total_size_limit": 1000000000, 
            //Log files older than "log_age_limit_days" days are deleted whether or not the total size is exceeded.
            "log_age_limit_days": 30,
            //log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
            //The TRACE level is only valid when built in DEBUG mode.
            "log_level": "DEBUG"
        },

Of course, similar behaviour can be created with a cronjob etc, but it would be useful to have this directly in the framework.

rbugajewski commented 2 years ago

Thanks for the feature request. I have some doubts though, as this would basically replicate syslog of which many, many implementations exist.

So what would be the benefit? Maybe you have a concrete use case for this feature request?

timomrs commented 2 years ago

First, let me confess my ignorance: I come from a windows background, though I'm working on a Linux system now, so syslog was not familiar to me before. After some googling, what I'm getting is that it's a framework for handling logs in *nix systems, including sharing / consolidating them over the network. The basic logging call in such systems is syslog(), so is your suggestion to switch to a completely different logging framework? How would that solve the problem of limiting total log sizes?

Or did you perhaps mean logrotate?

Anyway, the use case, from my point of view: our deployment team wants this feature, I believe they'd prefer to limit the number of independent apps / configurations to maintain. I'm sure they know of logrotate, but I'll ask them what's the case for not using it.

rbugajewski commented 2 years ago

I see, thanks for the elaborate explanation.

Yes, I mean syslog / logrotate, as there are multiple implementations out there, and some are packaged together.

This should not be a problem on Windows Server, too.

Why not just let Drogon log endlessly and let the system logger, which is already present on every modern system, do its job?

hwc0919 commented 4 months ago

We support "log_size_limit" and "max_files" now.