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):
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_site_webroot = EEVariables.ee_webroot + ee_domain
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
logwatch(self, ee_site_webroot + '/logs/')
logfiles = glob.glob(ee_site_webroot + '/logs/*.log')
logwatch(self, logfiles)
else:
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']))
else:
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']))
if data['wpfc']:
@ -477,7 +477,7 @@ def display_cache_settings(self, data):
Log.info(self, "Browser Cache:\t\tDisable")
def logwatch(self, logdir):
def logwatch(self, logfiles):
import zlib
import base64
import time
@ -497,5 +497,5 @@ def logwatch(self, logdir):
'caught exception rendering a new log line in %s'
% filename)
l = logwatch.LogWatcher(logdir, callback)
l = logwatch.LogWatcher(logfiles, callback)
l.loop()

37
ee/core/logwatch.py

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

Loading…
Cancel
Save