Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/network/ifupdown2/ifupdown2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

# enable persistent ifupdown2 debug logs
# ifupdown2 will keep debug logs in /etc/network/ifupdown2/logs
# ifupdown2 will keep debug logs in /var/log/ifupdown2/logs/
# by default the last 42 configurations logs will be kept.
# yes - (default) enable persistent logging (42 configs)
# no - disable persistent logging
Expand Down
40 changes: 22 additions & 18 deletions ifupdown2/lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import sys
import shutil
import re
import traceback

import logging
Expand Down Expand Up @@ -126,31 +127,34 @@ def __init__(self):
self.__root_logger.debug("couldn't initialize persistent debug logging: %s" % str(e))

def __get_enable_persistent_debug_logging(self):
# ifupdownconfig.config is not yet initialized so we need to cat and grep ifupdown2.conf
# ifupdownconfig.config is not yet initialized so we need to evaluate ifupdown2.conf
# by default we limit logging to LOGGING_DIRECTORY_LIMIT number of files
# the user can specify a different amount in /etc/network/ifupdown2/ifupdown2.conf
# or just yes/no to enable/disable the feature.
try:
user_config_limit_str = (
utils.exec_user_command(
"cat /etc/network/ifupdown2/ifupdown2.conf | grep enable_persistent_debug_logging") or ""
).strip().split("=", 1)[1]

try:
# get the integer amount
return int(user_config_limit_str)
except ValueError:
# the user didn't specify an integer but a boolean
# if the input is not recognized we are disabling the feature
user_config_limit = {
True: self.LOGGING_DIRECTORY_LIMIT,
False: 0,
}.get(utils.get_boolean_from_string(user_config_limit_str))
# ensure a safe default return value
result = self.LOGGING_DIRECTORY_LIMIT

cfg_valid_values = r"^(yes|no|\d+)$"
try:
with open('/etc/network/ifupdown2/ifupdown2.conf', 'r') as conffile:
for line in conffile.readlines():
if line.startswith('enable_persistent_debug_logging='):
val = line.split("=")[-1].strip()
if re.match(cfg_valid_values, val):
try:
val = int(val)
result = max(0, val)
except ValueError:
result = {
True: self.LOGGING_DIRECTORY_LIMIT,
False: 0,
}.get(utils.get_boolean_from_string(user_config_limit_str))
except Exception:
user_config_limit = self.LOGGING_DIRECTORY_LIMIT
pass

return result

return user_config_limit

def __init_debug_logging(self):
# check if enable_persistent_debug_logging is enabled
Expand Down