Add cache optimization to variable imports in logger.
This commit is contained in:
parent
8acfb36391
commit
6370c377d5
1 changed files with 15 additions and 5 deletions
|
|
@ -24,7 +24,9 @@ from twisted.internet.threads import deferToThread
|
||||||
|
|
||||||
|
|
||||||
_LOGDIR = None
|
_LOGDIR = None
|
||||||
|
_LOG_ROTATE_SIZE = None
|
||||||
_TIMEZONE = None
|
_TIMEZONE = None
|
||||||
|
_CHANNEL_LOG_NUM_TAIL_LINES = None
|
||||||
|
|
||||||
|
|
||||||
def timeformat(when=None):
|
def timeformat(when=None):
|
||||||
|
|
@ -160,8 +162,13 @@ class EvenniaLogFile(logfile.LogFile):
|
||||||
lines of the previous log to the start of the new log, in order
|
lines of the previous log to the start of the new log, in order
|
||||||
to preserve a continuous chat history for channel log files.
|
to preserve a continuous chat history for channel log files.
|
||||||
"""
|
"""
|
||||||
from django.conf import settings
|
# we delay import of settings to keep logger module as free
|
||||||
num_lines_to_append = settings.CHANNEL_LOG_NUM_TAIL_LINES
|
# from django as possible.
|
||||||
|
global _CHANNEL_LOG_NUM_TAIL_LINES
|
||||||
|
if _CHANNEL_LOG_NUM_TAIL_LINES is None:
|
||||||
|
from django.conf import settings
|
||||||
|
_CHANNEL_LOG_NUM_TAIL_LINES = settings.CHANNEL_LOG_NUM_TAIL_LINES
|
||||||
|
num_lines_to_append = _CHANNEL_LOG_NUM_TAIL_LINES
|
||||||
|
|
||||||
def rotate(self):
|
def rotate(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -209,10 +216,13 @@ def _open_log_file(filename):
|
||||||
handle. Will create a new file in the log dir if one didn't
|
handle. Will create a new file in the log dir if one didn't
|
||||||
exist.
|
exist.
|
||||||
"""
|
"""
|
||||||
from django.conf import settings
|
# we delay import of settings to keep logger module as free
|
||||||
global _LOG_FILE_HANDLES, _LOGDIR
|
# from django as possible.
|
||||||
|
global _LOG_FILE_HANDLES, _LOGDIR, _LOG_ROTATE_SIZE
|
||||||
if not _LOGDIR:
|
if not _LOGDIR:
|
||||||
|
from django.conf import settings
|
||||||
_LOGDIR = settings.LOG_DIR
|
_LOGDIR = settings.LOG_DIR
|
||||||
|
_LOG_ROTATE_SIZE = settings.CHANNEL_LOG_ROTATE_SIZE
|
||||||
|
|
||||||
filename = os.path.join(_LOGDIR, filename)
|
filename = os.path.join(_LOGDIR, filename)
|
||||||
if filename in _LOG_FILE_HANDLES:
|
if filename in _LOG_FILE_HANDLES:
|
||||||
|
|
@ -220,7 +230,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.CHANNEL_LOG_ROTATE_SIZE)
|
filehandle = EvenniaLogFile.fromFullPath(filename, rotateLength=_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