From 54bd97cb6e37407f1cc6e0e87044e725f5b96208 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Wed, 28 Jan 2015 15:58:15 +0530 Subject: [PATCH] updated logwatch --- ee/cli/plugins/site.py | 4 +++- ee/cli/plugins/site_functions.py | 6 +++--- ee/core/logwatch.py | 37 +++++++++++++++++--------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index 03bd14c8..0173021a 100644 --- a/ee/cli/plugins/site.py +++ b/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)) diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index b0a47ac9..0886f6a2 100644 --- a/ee/cli/plugins/site_functions.py +++ b/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() diff --git a/ee/core/logwatch.py b/ee/core/logwatch.py index 649d418f..8392a0cc 100644 --- a/ee/core/logwatch.py +++ b/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: