Commit e83710b0 authored by Simon Que's avatar Simon Que Committed by Commit Bot

Start reading Atrus logs from a particular timestamp

Previously, this was only done for /var/log/messages.

BUG=715263
R=afakhry@chromium.org

Change-Id: I1ece80c22d9a74f2ab28eab6c63fd3b6d5772ba7
Reviewed-on: https://chromium-review.googlesource.com/572582Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Simon Que <sque@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487207}
parent deed4ed0
......@@ -17,6 +17,8 @@ namespace system_logs {
namespace {
using SupportedSource = SingleLogFileLogSource::SupportedSource;
constexpr char kDefaultSystemLogDirPath[] = "/var/log";
constexpr int kMaxNumAllowedLogRotationsDuringFileRead = 3;
......@@ -36,11 +38,11 @@ const base::Time* g_chrome_start_time_for_test = nullptr;
base::FilePath GetLogFileSourceRelativeFilePath(
SingleLogFileLogSource::SupportedSource source) {
switch (source) {
case SingleLogFileLogSource::SupportedSource::kMessages:
case SupportedSource::kMessages:
return base::FilePath("messages");
case SingleLogFileLogSource::SupportedSource::kUiLatest:
case SupportedSource::kUiLatest:
return base::FilePath("ui/ui.LATEST");
case SingleLogFileLogSource::SupportedSource::kAtrusLog:
case SupportedSource::kAtrusLog:
return base::FilePath("atrus.log");
}
NOTREACHED();
......@@ -77,6 +79,20 @@ base::Time GetChromeStartTime() {
return base::CurrentProcessInfo::CreationTime();
}
// Returns true if |source_type| is a log source that should be read starting
// from a particular timestamp rather than from the beginning of the file.
bool ShouldReadFromTimestampBasedOffset(SupportedSource source_type) {
switch (source_type) {
case SupportedSource::kMessages:
case SupportedSource::kAtrusLog:
return true;
case SupportedSource::kUiLatest:
return false;
}
NOTREACHED();
return false;
}
// Returns the file offset into |path| of the first line that starts with a
// timestamp no earlier than |time|. Returns 0 if no such offset could be
// determined (e.g. can't open file, no timestamps present).
......@@ -178,7 +194,7 @@ void SingleLogFileLogSource::ReadFile(size_t num_rotations_allowed,
return;
// Determine actual offset from which to start reading.
if (source_type_ == SupportedSource::kMessages) {
if (ShouldReadFromTimestampBasedOffset(source_type_)) {
const base::Time earliest_log_time =
GetChromeStartTime() - kLogCutoffTimeBeforeChromeStart;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment