diff --git a/evennia/settings_default.py b/evennia/settings_default.py index c472268a7d..f94bf5d3ef 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -126,9 +126,9 @@ LOCKWARNING_LOG_FILE = os.path.join(LOG_DIR, 'lockwarnings.log') # loose log info. CYCLE_LOGFILES = True # 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 -LOG_ROTATE_SIZE = 1000000 +CHANNEL_LOG_ROTATE_SIZE = 1000000 # 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 TIME_ZONE = 'UTC' diff --git a/evennia/utils/logger.py b/evennia/utils/logger.py index 70bf223fe8..bde0649922 100644 --- a/evennia/utils/logger.py +++ b/evennia/utils/logger.py @@ -155,9 +155,19 @@ log_depmsg = log_dep # Arbitrary file logger 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): + """ + 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 if not append_tail: logfile.LogFile.rotate(self) @@ -168,9 +178,26 @@ class EvenniaLogFile(logfile.LogFile): self.write(line) 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) 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) _LOG_FILE_HANDLES = {} # holds open log handles @@ -192,7 +219,7 @@ def _open_log_file(filename): return _LOG_FILE_HANDLES[filename] else: 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 _LOG_FILE_HANDLES[filename] = filehandle return filehandle