Add docstr to class and methods, adjust names of settings to be more clearly modifying channel logs.
This commit is contained in:
parent
6e2c10b008
commit
4605b3128e
2 changed files with 31 additions and 4 deletions
|
|
@ -126,9 +126,9 @@ LOCKWARNING_LOG_FILE = os.path.join(LOG_DIR, 'lockwarnings.log')
|
||||||
# loose log info.
|
# loose log info.
|
||||||
CYCLE_LOGFILES = True
|
CYCLE_LOGFILES = True
|
||||||
# Number of lines to append to rotating channel logs when they rotate
|
# Number of lines to append to rotating channel logs when they rotate
|
||||||
NUM_LOG_TAIL_LINES = 20
|
CHANNEL_LOG_NUM_TAIL_LINES = 20
|
||||||
# Max size of channel log files before they rotate
|
# Max size of channel log files before they rotate
|
||||||
LOG_ROTATE_SIZE = 1000000
|
CHANNEL_LOG_ROTATE_SIZE = 1000000
|
||||||
# Local time zone for this installation. All choices can be found here:
|
# Local time zone for this installation. All choices can be found here:
|
||||||
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
|
||||||
|
|
@ -155,9 +155,19 @@ log_depmsg = log_dep
|
||||||
# Arbitrary file logger
|
# Arbitrary file logger
|
||||||
|
|
||||||
class EvenniaLogFile(logfile.LogFile):
|
class EvenniaLogFile(logfile.LogFile):
|
||||||
num_lines_to_append = settings.NUM_LOG_TAIL_LINES
|
"""
|
||||||
|
A rotating logfile based off Twisted's LogFile. It overrides
|
||||||
|
the LogFile's rotate method in order to append some of the last
|
||||||
|
lines of the previous log to the start of the new log, in order
|
||||||
|
to preserve a continuous chat history for channel log files.
|
||||||
|
"""
|
||||||
|
num_lines_to_append = settings.CHANNEL_LOG_NUM_TAIL_LINES
|
||||||
|
|
||||||
def rotate(self):
|
def rotate(self):
|
||||||
|
"""
|
||||||
|
Rotates our log file and appends some number of lines from
|
||||||
|
the previous log to the start of the new one.
|
||||||
|
"""
|
||||||
append_tail = self.num_lines_to_append > 0
|
append_tail = self.num_lines_to_append > 0
|
||||||
if not append_tail:
|
if not append_tail:
|
||||||
logfile.LogFile.rotate(self)
|
logfile.LogFile.rotate(self)
|
||||||
|
|
@ -168,9 +178,26 @@ class EvenniaLogFile(logfile.LogFile):
|
||||||
self.write(line)
|
self.write(line)
|
||||||
|
|
||||||
def seek(self, *args, **kwargs):
|
def seek(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Convenience method for accessing our _file attribute's seek method,
|
||||||
|
which is used in tail_log_function.
|
||||||
|
Args:
|
||||||
|
*args: Same args as file.seek
|
||||||
|
**kwargs: Same kwargs as file.seek
|
||||||
|
"""
|
||||||
return self._file.seek(*args, **kwargs)
|
return self._file.seek(*args, **kwargs)
|
||||||
|
|
||||||
def readlines(self, *args, **kwargs):
|
def readlines(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Convenience method for accessing our _file attribute's readlines method,
|
||||||
|
which is used in tail_log_function.
|
||||||
|
Args:
|
||||||
|
*args: same args as file.readlines
|
||||||
|
**kwargs: same kwargs as file.readlines
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
lines (list): lines from our _file attribute.
|
||||||
|
"""
|
||||||
return self._file.readlines(*args, **kwargs)
|
return self._file.readlines(*args, **kwargs)
|
||||||
|
|
||||||
_LOG_FILE_HANDLES = {} # holds open log handles
|
_LOG_FILE_HANDLES = {} # holds open log handles
|
||||||
|
|
@ -192,7 +219,7 @@ def _open_log_file(filename):
|
||||||
return _LOG_FILE_HANDLES[filename]
|
return _LOG_FILE_HANDLES[filename]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
filehandle = EvenniaLogFile.fromFullPath(filename, rotateLength=settings.LOG_ROTATE_SIZE)
|
filehandle = EvenniaLogFile.fromFullPath(filename, rotateLength=settings.CHANNEL_LOG_ROTATE_SIZE)
|
||||||
# filehandle = open(filename, "a+") # append mode + reading
|
# filehandle = open(filename, "a+") # append mode + reading
|
||||||
_LOG_FILE_HANDLES[filename] = filehandle
|
_LOG_FILE_HANDLES[filename] = filehandle
|
||||||
return filehandle
|
return filehandle
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue