Skip to content

Commit

Permalink
log: add two options(log_file_count and log_file_maxbytes) in the mai…
Browse files Browse the repository at this point in the history
…n config file

Currently the logrotation is not configurable. On system with large
amount of cpus a tuned start creates a lot of entries and older log
entries are lost.
  • Loading branch information
Lidong Zhong committed Sep 11, 2018
1 parent efcb477 commit 4791290
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions tuned-main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ default_instance_priority = 0

# Udev buffer size
udev_buffer_size = 1MB

# Log file count
log_file_count = 2

# Log file max size
log_file_max_size = 100KB
6 changes: 4 additions & 2 deletions tuned.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ def error(message):
log.setLevel("DEBUG")

try:
maxBytes = config.get_size("log_file_max_size", consts.LOG_FILE_MAXBYTES)
backupCount = config.get("log_file_count", consts.LOG_FILE_COUNT)
if args.daemon:
if args.log is None:
args.log = consts.LOG_FILE
log.switch_to_file(args.log)
log.switch_to_file(args.log, maxBytes, backupCount)
else:
if args.log is not None:
log.switch_to_file(args.log)
log.switch_to_file(args.log, maxBytes, backupCount)

app = tuned.daemon.Application(args.profile, config)

Expand Down
10 changes: 6 additions & 4 deletions tuned/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def switch_to_console(self):
self.remove_all_handlers()
self.addHandler(self._console_handler)

def switch_to_file(self, filename = consts.LOG_FILE):
self._setup_file_handler(filename)
def switch_to_file(self, filename = consts.LOG_FILE,
maxBytes = consts.LOG_FILE_MAXBYTES,
backupCount = consts.LOG_FILE_COUNT):
self._setup_file_handler(filename, maxBytes, backupCount)
self.remove_all_handlers()
self.addHandler(self._file_handler)

Expand All @@ -123,7 +125,7 @@ def _setup_console_handler(cls):
cls._console_handler.setFormatter(cls._formatter)

@classmethod
def _setup_file_handler(cls, filename):
def _setup_file_handler(cls, filename, maxBytes, backupCount):
if cls._file_handler is not None:
return

Expand All @@ -134,7 +136,7 @@ def _setup_file_handler(cls, filename):
os.makedirs(log_directory)

cls._file_handler = logging.handlers.RotatingFileHandler(
filename, maxBytes = consts.LOG_FILE_MAXBYTES, backupCount = consts.LOG_FILE_COUNT)
filename, maxBytes = maxBytes, backupCount = backupCount)
cls._file_handler.setFormatter(cls._formatter)

logging.addLevelName(consts.LOG_LEVEL_CONSOLE, consts.LOG_LEVEL_CONSOLE_NAME)
Expand Down

0 comments on commit 4791290

Please sign in to comment.