Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1592)

Unified Diff: client/cros/cros_logging.py

Issue 6690056: Revert "Support rotated logs." (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/cros/cros_ui_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cros/cros_logging.py
diff --git a/client/cros/cros_logging.py b/client/cros/cros_logging.py
index ecdc1e43f7adae53cb2b032d6a4ae3d0755e2454..cc1f636071f845d2772c130a6db49bcb30c4813b 100644
--- a/client/cros/cros_logging.py
+++ b/client/cros/cros_logging.py
@@ -13,36 +13,14 @@ class LogReader(object):
A class to read system log files.
"""
- def __init__(self, filename='/var/log/messages', include_rotated_logs=True):
+ def __init__(self, filename='/var/log/messages'):
self._start_line = 1
self._filename = filename
- self._include_rotated_logs = include_rotated_logs
if not os.path.exists(CLEANUP_LOGS_PAUSED_FILE):
raise error.TestError('LogReader created without ' +
CLEANUP_LOGS_PAUSED_FILE)
- def read_all_logs(self, start=1):
- """Read all content from log files.
-
- Generator function.
- Return an iterator on the content of files.
- """
- log_files = []
- line_number = 1
- if self._include_rotated_logs:
- log_files.extend(utils.system_output(
- 'ls -tr1 %s.*' % self._filename,
- ignore_status=True).splitlines())
- log_files.append(self._filename)
- for log_file in log_files:
- f = open(log_file)
- for line in f:
- if line_number >= start:
- yield line
- line_number += 1
-
-
def set_start_by_regexp(self, index, regexp):
"""Set the start of logs based on a regular expression.
@@ -50,16 +28,17 @@ class LogReader(object):
Negative numbers indicate matches since end of log.
"""
regexp_compiled = re.compile(regexp)
+ file_handle = open(self._filename, 'r')
starts = []
line_number = 1
- for line in self.read_all_logs():
+ for line in file_handle:
if regexp_compiled.match(line):
starts.append(line_number)
line_number += 1
if index < -len(starts):
self._start_line = 1
elif index >= len(starts):
- self._start_line = line_number
+ self.set_start_by_current()
else:
self._start_line = starts[index]
@@ -74,16 +53,14 @@ class LogReader(object):
r'.*000\] Linux version \d')
- def set_start_by_current(self, relative=0):
+ def set_start_by_current(self, relative=1):
""" Set start of logs based on current last line.
@param relative: line relative to current to start at. 1 means
to start the log after this line.
"""
- count = self._start_line + relative
- for line in self.read_all_logs(start=self._start_line):
- count += 1
- self._start_line = count
+ lines = utils.system_output('wc -l %s' % self._filename)
+ self._start_line = int(lines.split(' ')[0]) + relative
def get_logs(self):
@@ -94,18 +71,15 @@ class LogReader(object):
@return string of contents of file since start line.
"""
- logs = []
- for line in self.read_all_logs(start=self._start_line):
- logs.append(line)
- return '\n'.join(logs)
-
+ return utils.system_output('tail -n +%d %s' %
+ (self._start_line, self._filename))
def can_find(self, string):
""" Try to find string in the logs.
@return boolean indicating if we found the string.
"""
- return string in self.read_all_logs(start=self._start_line)
+ return string in self.get_logs()
class LogRotationPauser(object):
« no previous file with comments | « no previous file | client/cros/cros_ui_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698