shill: log file name when dumping memorylog
Depending on whether or not someone is logged in, the memory log
will be dumped to different places. Rather than making the reader
of /var/log/messages guess which was the case, log the memory
log dump file name in /var/log/messages.
BUG=chromium-os:37002
TEST=unit tests
Change-Id: I7f833d4b22f43e042cb5f8016410515a934bdcf1
Reviewed-on: https://gerrit.chromium.org/gerrit/39335
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Ready: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/memory_log.cc b/memory_log.cc
index ce751d0..4bf9b8d 100644
--- a/memory_log.cc
+++ b/memory_log.cc
@@ -78,6 +78,7 @@
}
void MemoryLog::FlushToDiskImpl(const FilePath &file_path) {
+ LOG(INFO) << "Saving memory log to " << file_path.AsUTF8Unsafe();
do {
// If the file exists, lets make sure it is of reasonable size before
// writing to it, and roll it over if it's too big.
diff --git a/memory_log_unittest.cc b/memory_log_unittest.cc
index 3fc225a..52a3a42 100644
--- a/memory_log_unittest.cc
+++ b/memory_log_unittest.cc
@@ -144,11 +144,12 @@
TEST_F(MemoryLogTest, MemoryLogFlushToDiskCannotCreateFile) {
ScopedMockLog log;
+ FilePath tmp_path;
+ EXPECT_CALL(log, Log(_, _, ::testing::EndsWith(tmp_path.AsUTF8Unsafe())));
EXPECT_CALL(log, Log(_,
_,
"Failed to open file for dumping memory log to disk."));
EXPECT_CALL(log, Log(_, _, "Failed to flush memory log to disk"));
- FilePath tmp_path;
file_util::CreateTemporaryFile(&tmp_path);
// Flushing fails because a directory already exists with the same name as
// our log file.
@@ -184,11 +185,14 @@
}
TEST_F(MemoryLogTest, MemoryLogFlushToDiskWorks) {
+ ScopedMockLog log;
FilePath tmp_path;
file_util::CreateTemporaryFile(&tmp_path);
LOG(INFO) << kTestStr1;
LOG(INFO) << kTestStr2;
LOG(INFO) << kTestStr3;
+ EXPECT_CALL(log, Log(_, _, _));
+ EXPECT_CALL(log, Log(_, _, ::testing::EndsWith(tmp_path.AsUTF8Unsafe())));
MemoryLog::GetInstance()->FlushToDiskImpl(tmp_path);
// No rotation should have happened.
EXPECT_FALSE(file_util::PathExists(tmp_path.Append(".bak")));