Skip to content

Commit bd7933b

Browse files
committed
Merge branch 'DaStoned-master'
2 parents 30024e5 + 69b5130 commit bd7933b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

simpledaemonlog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""__init__.py: Module init."""
22

3-
version = "0.2.1"
3+
version = "0.2.2"
44

55
__author__ = "Raido Pahtma"
66
__license__ = "MIT"

simpledaemonlog/daemonarguments.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ def add_daemon_arguments(parser):
1616
parser.add_argument("-d", dest="daemon", action="store_true", help="Daemon mode, no logging to console.")
1717
parser.add_argument("--logdir", default=None, help="Folder where logfiles should be stored.")
1818
parser.add_argument("--colorlog", default=False, type=arg_str2bool, help="Color logs for terminal output.")
19+
parser.add_argument("--rotate_count", default=0, type=int, help="Enable log rotation, keep so many old log files. If 0, log rotation is disabled.")
20+
parser.add_argument("--rotate_unit", default="W6", type=str, help="When log rotation is enabled, select this time unit ('S':secs, 'M':mins, 'H':hours, 'D':days, 'W0'-'W6':weekday, 'midnight')")
21+
parser.add_argument("--rotate_interval", default="1", type=int, help="When log rotation is enabled, allow this many time units to elapse before doing the rotation (not used when weekday rotation is selected)")
1922

2023

2124
def setup_daemon(args, name):
2225
if args.daemon is False:
2326
logsetup.setup_console(color=args.colorlog)
2427

2528
if args.logdir is not None:
26-
logsetup.setup_file(name, logdir=args.logdir)
29+
logsetup.setup_file(name, logdir=args.logdir, backups=args.rotate_count, backupInterval=args.rotate_interval, backupIntervalUnit=args.rotate_unit)
2730
elif args.daemon:
2831
print "WARNING Logging not configured!"
2932
print args

simpledaemonlog/logsetup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def setup_console(level=logging.NOTSET, fs=DEFAULT_FORMAT_STRING, settings=None,
8585
log.debug("logging config loaded from {:s}".format(loaded))
8686

8787

88-
def setup_file(application_name, logdir="log", level=logging.NOTSET, fs=DEFAULT_FORMAT_STRING, settings=None, backups=8):
88+
def setup_file(application_name, logdir="log", level=logging.NOTSET, fs=DEFAULT_FORMAT_STRING, settings=None, backups=8, backupInterval=1, backupIntervalUnit="W6"):
8989
"""
9090
Directs printf to file with INFO level.
9191
"""
@@ -102,9 +102,10 @@ def setup_file(application_name, logdir="log", level=logging.NOTSET, fs=DEFAULT_
102102
logfilepath = os.path.join(logdir, logfilename)
103103
loglinkpath = os.path.join(logdir, loglatest)
104104
if backups:
105-
logfile = logging.handlers.TimedRotatingFileHandler(logfilepath, when="W6", backupCount=backups)
105+
logfile = logging.handlers.TimedRotatingFileHandler(logfilepath, backupCount=backups, when=backupIntervalUnit, interval=backupInterval)
106106
else:
107-
logfile = logging.FileHandler(logfilepath)
107+
# Expect logrotate to pull the file out from underneath us
108+
logfile = logging.handlers.WatchedFileHandler(logfilepath)
108109

109110
if hasattr(os, "symlink"):
110111
if os.path.islink(loglinkpath):

0 commit comments

Comments
 (0)