summaryrefslogtreecommitdiffstats
path: root/deluge/log.py
diff options
context:
space:
mode:
authorbendikro <bro.devel+deluge@gmail.com>2016-01-15 22:08:44 +0100
committerbendikro <bro.devel+deluge@gmail.com>2016-04-18 09:36:13 +0200
commit6300f9154acf04bf9bb7c3db44603fd1954efe37 (patch)
tree7b4309bf419b92767d58cdc65a258f08f6405494 /deluge/log.py
parentc90af1ce6c01e8948f0ffd388c49292efe75a211 (diff)
downloaddeluge-6300f9154acf04bf9bb7c3db44603fd1954efe37.tar.gz
deluge-6300f9154acf04bf9bb7c3db44603fd1954efe37.tar.bz2
deluge-6300f9154acf04bf9bb7c3db44603fd1954efe37.zip
[#1949] [UI] Allow setting max size for rotating log file
Diffstat (limited to 'deluge/log.py')
-rw-r--r--deluge/log.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/deluge/log.py b/deluge/log.py
index 9d3b77469..5c34dc81f 100644
--- a/deluge/log.py
+++ b/deluge/log.py
@@ -107,15 +107,19 @@ levels = {
}
-def setup_logger(level="error", filename=None, filemode="w"):
+def setup_logger(level="error", filename=None, filemode="w", logrotate=None):
"""
Sets up the basic logger and if `:param:filename` is set, then it will log
to that file instead of stdout.
- :param level: str, the level to log
- :param filename: str, the file to log to
+ Args:
+ level (str): The log level to use (Default: "error")
+ filename (str, optional): The log filename. Default is None meaning log
+ to terminal
+ filemode (str): The filemode to use when opening the log file
+ logrotate (int, optional): The size of the logfile in bytes when enabling
+ log rotation (Default is None meaning disabled)
"""
-
if logging.getLoggerClass() is not Logging:
logging.setLoggerClass(Logging)
logging.addLevelName(5, "TRACE")
@@ -125,19 +129,16 @@ def setup_logger(level="error", filename=None, filemode="w"):
root_logger = logging.getLogger()
- if filename and filemode == "a":
+ if filename and logrotate:
handler = logging.handlers.RotatingFileHandler(
- filename, filemode,
- maxBytes=50 * 1024 * 1024, # 50 Mb
- backupCount=3,
- encoding="utf-8",
- delay=0
+ filename, maxBytes=logrotate,
+ backupCount=5, encoding="utf-8"
)
elif filename and filemode == "w":
handler = getattr(
logging.handlers, "WatchedFileHandler", logging.FileHandler)(
- filename, filemode, "utf-8", delay=0
- )
+ filename, mode=filemode, encoding="utf-8"
+ )
else:
handler = logging.StreamHandler(stream=sys.stdout)