Browse Source

updated logwatch

bugfixes
harshadyeola 10 years ago
parent
commit
54bd97cb6e
  1. 4
      ee/cli/plugins/site.py
  2. 6
      ee/cli/plugins/site_functions.py
  3. 37
      ee/core/logwatch.py

4
ee/cli/plugins/site.py

@ -107,9 +107,11 @@ class EESiteController(CementBaseController):
def log(self): def log(self):
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_site_webroot = EEVariables.ee_webroot + ee_domain ee_site_webroot = EEVariables.ee_webroot + ee_domain
if os.path.isfile('/etc/nginx/sites-available/{0}' if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)): .format(ee_domain)):
logwatch(self, ee_site_webroot + '/logs/') logfiles = glob.glob(ee_site_webroot + '/logs/*.log')
logwatch(self, logfiles)
else: else:
Log.error(self, " site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))

6
ee/cli/plugins/site_functions.py

@ -465,7 +465,7 @@ def display_cache_settings(self, data):
"page=w3tc_general".format(data['site_name'])) "page=w3tc_general".format(data['site_name']))
else: else:
Log.info(self, "Configure W3TC:" Log.info(self, "Configure W3TC:"
"\t\thttp://{0}wp-admin/admin.php?" "\t\thttp://{0}/wp-admin/admin.php?"
"page=w3tc_general".format(data['site_name'])) "page=w3tc_general".format(data['site_name']))
if data['wpfc']: if data['wpfc']:
@ -477,7 +477,7 @@ def display_cache_settings(self, data):
Log.info(self, "Browser Cache:\t\tDisable") Log.info(self, "Browser Cache:\t\tDisable")
def logwatch(self, logdir): def logwatch(self, logfiles):
import zlib import zlib
import base64 import base64
import time import time
@ -497,5 +497,5 @@ def logwatch(self, logdir):
'caught exception rendering a new log line in %s' 'caught exception rendering a new log line in %s'
% filename) % filename)
l = logwatch.LogWatcher(logdir, callback) l = logwatch.LogWatcher(logfiles, callback)
l.loop() l.loop()

37
ee/core/logwatch.py

@ -24,7 +24,7 @@ class LogWatcher(object):
>>> l.loop() >>> l.loop()
""" """
def __init__(self, folder, callback, extensions=["log"], tail_lines=0): def __init__(self, filelist, callback, extensions=["log"], tail_lines=0):
"""Arguments: """Arguments:
(str) @folder: (str) @folder:
@ -42,11 +42,14 @@ class LogWatcher(object):
read last N lines from files being watched before starting read last N lines from files being watched before starting
""" """
self.files_map = {} self.files_map = {}
self.filelist = filelist
self.callback = callback self.callback = callback
self.folder = os.path.realpath(folder) # self.folder = os.path.realpath(folder)
self.extensions = extensions self.extensions = extensions
assert (os.path.isdir(self.folder), "%s does not exists" # assert (os.path.isdir(self.folder), "%s does not exists"
% self.folder) # % self.folder)
for files in self.filelist:
assert (os.path.isfile(file), "%s does not exists" % file)
assert callable(callback) assert callable(callback)
self.update_files() self.update_files()
# The first time we run the script we move all file markers at EOF. # The first time we run the script we move all file markers at EOF.
@ -77,17 +80,17 @@ class LogWatcher(object):
"""Log when a file is un/watched""" """Log when a file is un/watched"""
print(line) print(line)
def listdir(self): # def listdir(self):
"""List directory and filter files by extension. # """List directory and filter files by extension.
You may want to override this to add extra logic or # You may want to override this to add extra logic or
globbling support. # globbling support.
""" # """
ls = os.listdir(self.folder) # ls = os.listdir(self.folder)
if self.extensions: # if self.extensions:
return ([x for x in ls if os.path.splitext(x)[1][1:] # return ([x for x in ls if os.path.splitext(x)[1][1:]
in self.extensions]) # in self.extensions])
else: # else:
return ls # return ls
@staticmethod @staticmethod
def tail(fname, window): def tail(fname, window):
@ -122,8 +125,8 @@ class LogWatcher(object):
def update_files(self): def update_files(self):
ls = [] ls = []
for name in self.listdir(): for name in self.filelist:
absname = os.path.realpath(os.path.join(self.folder, name)) absname = os.path.realpath(os.path.join(name))
try: try:
st = os.stat(absname) st = os.stat(absname)
except EnvironmentError as err: except EnvironmentError as err:

Loading…
Cancel
Save