blob: 16ff5d2736bc1a7a8b2d776d14bc6a27816d41e7 [file] [log] [blame]
Christopher Wileyb691efd2012-08-09 13:51:51 -07001// Copyright (c) 2012 The Chromium OS 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 SHILL_LOGGING_H_
6#define SHILL_LOGGING_H_
7
8#include <base/logging.h>
9
10#include "shill/memory_log.h"
11#include "shill/scope_logger.h"
12
13// How to use:
14//
15// The SLOG macro and its variants are similar to the VLOG macros
16// defined in base/logging.h, except that the SLOG macros take an additional
17// |scope| argument to enable logging only if |scope| is enabled. In addition,
18// messages sent to SLOG[_IF] are sent to the MemoryLog, whether or not
19// that scope is enabled.
20//
21// Like VLOG, SLOG macros internally map verbosity to LOG severity using
22// negative values, i.e. SLOG(scope, 1) corresponds to LOG(-1).
23//
24// Example usages:
25// SLOG(Service, 1) << "Printed when the 'service' scope is enabled and "
26// "the verbose level is greater than or equal to 1";
27//
28// SLOG_IF(Service, 1, (size > 1024))
29// << "Printed when the 'service' scope is enabled, the verbose level "
30// "is greater than or equal to 1, and size is more than 1024";
31//
32// Similarly, MLOG and MLOG_IF are equivalents to LOG and LOG_IF that send
33// their messages through the MemoryLog on the way to the normal logging system.
34//
35// Example usages:
36// MLOG(ERROR) << "Message logged at ERROR level";
37//
38// MLOG_IF(INFO, tacos < enough) << "Such a sad day";
39//
40//
41
42#define SLOG_IS_ON(scope, verbose_level) \
43 ::shill::ScopeLogger::GetInstance()->IsLogEnabled( \
44 ::shill::ScopeLogger::k##scope, verbose_level)
45
46#define MLOG_SCOPE_STREAM(scope, verbose_level) \
47 ::shill::MemoryLogMessage(__FILE__, __LINE__, \
48 -verbose_level, \
49 SLOG_IS_ON(scope, verbose_level)).stream()
50
51#define MLOG_SEVERITY_STREAM(severity) \
52 ::shill::MemoryLogMessage(__FILE__, __LINE__, \
53 logging::LOG_ ## severity, \
54 LOG_IS_ON(severity)).stream()
55
56#define SLOG(scope, verbose_level) MLOG_SCOPE_STREAM(scope, verbose_level)
57
58#define SLOG_IF(scope, verbose_level, condition) \
59 LAZY_STREAM(MLOG_SCOPE_STREAM(scope, verbose_level), condition)
60
61// TODO(wiley) Add SLOG macros (crosbug.com/33416)
62
63#define MLOG(severity) MLOG_SEVERITY_STREAM(severity)
64
65#define MLOG_IF(severity, condition) \
66 LAZY_STREAM(MLOG_SEVERITY_STREAM(severity), condition)
67
68// TODO(wiley) Add MPLOG macros (crosbug.com/33416)
69
70#endif // SHILL_LOGGING_H_