log.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_TEST_CHROMEDRIVER_CHROME_LOG_H_
6#define CHROME_TEST_CHROMEDRIVER_CHROME_LOG_H_
7
8#include <string>
9
10#include "base/compiler_specific.h"
11#include "base/time.h"
12
13// Accepts log entries that have a level, timestamp, and a string message.
14class Log {
15 public:
16  enum Level {
17    kDebug,
18    kLog,
19    kWarning,
20    kError
21  };
22
23  virtual ~Log() {}
24
25  // Log a message with an explicit timestamp.
26  virtual void AddEntry(const base::Time& time,
27                        Level level,
28                        const std::string& message) = 0;
29
30  // Implicit timestamp, default to current time.
31  void AddEntry(Level level, const std::string& message);
32};
33
34// Writes log entries using printf.
35class Logger : public Log {
36 public:
37  // Creates a logger with a minimum level of |kDebug|.
38  Logger();
39  explicit Logger(Level min_log_level);
40  virtual ~Logger();
41
42  virtual void AddEntry(const base::Time& time,
43                        Level level,
44                        const std::string& message) OVERRIDE;
45
46 private:
47  Level min_log_level_;
48  base::Time start_;
49};
50
51#endif  // CHROME_TEST_CHROMEDRIVER_CHROME_LOG_H_
52