|
Packit |
18d29c |
// Copyright (c) 2006, Google Inc.
|
|
Packit |
18d29c |
// All rights reserved.
|
|
Packit |
18d29c |
//
|
|
Packit |
18d29c |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
18d29c |
// modification, are permitted provided that the following conditions are
|
|
Packit |
18d29c |
// met:
|
|
Packit |
18d29c |
//
|
|
Packit |
18d29c |
// * Redistributions of source code must retain the above copyright
|
|
Packit |
18d29c |
// notice, this list of conditions and the following disclaimer.
|
|
Packit |
18d29c |
// * Redistributions in binary form must reproduce the above
|
|
Packit |
18d29c |
// copyright notice, this list of conditions and the following disclaimer
|
|
Packit |
18d29c |
// in the documentation and/or other materials provided with the
|
|
Packit |
18d29c |
// distribution.
|
|
Packit |
18d29c |
// * Neither the name of Google Inc. nor the names of its
|
|
Packit |
18d29c |
// contributors may be used to endorse or promote products derived from
|
|
Packit |
18d29c |
// this software without specific prior written permission.
|
|
Packit |
18d29c |
//
|
|
Packit |
18d29c |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
18d29c |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
18d29c |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit |
18d29c |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit |
18d29c |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit |
18d29c |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
18d29c |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
18d29c |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
18d29c |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
18d29c |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
18d29c |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
18d29c |
//
|
|
Packit |
18d29c |
// Author: Maxim Lifantsev
|
|
Packit |
18d29c |
//
|
|
Packit |
18d29c |
// Thread-safe logging routines that do not allocate any memory or
|
|
Packit |
18d29c |
// acquire any locks, and can therefore be used by low-level memory
|
|
Packit |
18d29c |
// allocation and synchronization code.
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#ifndef BASE_RAW_LOGGING_H_
|
|
Packit |
18d29c |
#define BASE_RAW_LOGGING_H_
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#include <time.h>
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
@ac_google_start_namespace@
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#include "glog/log_severity.h"
|
|
Packit |
18d29c |
#include "glog/vlog_is_on.h"
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// Annoying stuff for windows -- makes sure clients can import these functions
|
|
Packit |
18d29c |
#ifndef GOOGLE_GLOG_DLL_DECL
|
|
Packit |
18d29c |
# if defined(_WIN32) && !defined(__CYGWIN__)
|
|
Packit |
18d29c |
# define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
|
|
Packit |
18d29c |
# else
|
|
Packit |
18d29c |
# define GOOGLE_GLOG_DLL_DECL
|
|
Packit |
18d29c |
# endif
|
|
Packit |
18d29c |
#endif
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// This is similar to LOG(severity) << format... and VLOG(level) << format..,
|
|
Packit |
18d29c |
// but
|
|
Packit |
18d29c |
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
|
Packit |
18d29c |
// * it is desiged to be a low-level logger that does not allocate any
|
|
Packit |
18d29c |
// memory and does not need any locks, hence:
|
|
Packit |
18d29c |
// * it logs straight and ONLY to STDERR w/o buffering
|
|
Packit |
18d29c |
// * it uses an explicit format and arguments list
|
|
Packit |
18d29c |
// * it will silently chop off really long message strings
|
|
Packit |
18d29c |
// Usage example:
|
|
Packit |
18d29c |
// RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
|
|
Packit |
18d29c |
// RAW_VLOG(3, "status is %i", status);
|
|
Packit |
18d29c |
// These will print an almost standard log lines like this to stderr only:
|
|
Packit |
18d29c |
// E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
|
Packit |
18d29c |
// I0821 211317 file.cc:142] RAW: status is 20
|
|
Packit |
18d29c |
#define RAW_LOG(severity, ...) \
|
|
Packit |
18d29c |
do { \
|
|
Packit |
18d29c |
switch (@ac_google_namespace@::GLOG_ ## severity) { \
|
|
Packit |
18d29c |
case 0: \
|
|
Packit |
18d29c |
RAW_LOG_INFO(__VA_ARGS__); \
|
|
Packit |
18d29c |
break; \
|
|
Packit |
18d29c |
case 1: \
|
|
Packit |
18d29c |
RAW_LOG_WARNING(__VA_ARGS__); \
|
|
Packit |
18d29c |
break; \
|
|
Packit |
18d29c |
case 2: \
|
|
Packit |
18d29c |
RAW_LOG_ERROR(__VA_ARGS__); \
|
|
Packit |
18d29c |
break; \
|
|
Packit |
18d29c |
case 3: \
|
|
Packit |
18d29c |
RAW_LOG_FATAL(__VA_ARGS__); \
|
|
Packit |
18d29c |
break; \
|
|
Packit |
18d29c |
default: \
|
|
Packit |
18d29c |
break; \
|
|
Packit |
18d29c |
} \
|
|
Packit |
18d29c |
} while (0)
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// The following STRIP_LOG testing is performed in the header file so that it's
|
|
Packit |
18d29c |
// possible to completely compile out the logging code and the log messages.
|
|
Packit |
18d29c |
#if STRIP_LOG == 0
|
|
Packit |
18d29c |
#define RAW_VLOG(verboselevel, ...) \
|
|
Packit |
18d29c |
do { \
|
|
Packit |
18d29c |
if (VLOG_IS_ON(verboselevel)) { \
|
|
Packit |
18d29c |
RAW_LOG_INFO(__VA_ARGS__); \
|
|
Packit |
18d29c |
} \
|
|
Packit |
18d29c |
} while (0)
|
|
Packit |
18d29c |
#else
|
|
Packit |
18d29c |
#define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
|
|
Packit |
18d29c |
#endif // STRIP_LOG == 0
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#if STRIP_LOG == 0
|
|
Packit |
18d29c |
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_INFO, \
|
|
Packit |
18d29c |
__FILE__, __LINE__, __VA_ARGS__)
|
|
Packit |
18d29c |
#else
|
|
Packit |
18d29c |
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
|
Packit |
18d29c |
#endif // STRIP_LOG == 0
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#if STRIP_LOG <= 1
|
|
Packit |
18d29c |
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_WARNING, \
|
|
Packit |
18d29c |
__FILE__, __LINE__, __VA_ARGS__)
|
|
Packit |
18d29c |
#else
|
|
Packit |
18d29c |
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
|
Packit |
18d29c |
#endif // STRIP_LOG <= 1
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#if STRIP_LOG <= 2
|
|
Packit |
18d29c |
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_ERROR, \
|
|
Packit |
18d29c |
__FILE__, __LINE__, __VA_ARGS__)
|
|
Packit |
18d29c |
#else
|
|
Packit |
18d29c |
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
|
Packit |
18d29c |
#endif // STRIP_LOG <= 2
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#if STRIP_LOG <= 3
|
|
Packit |
18d29c |
#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_FATAL, \
|
|
Packit |
18d29c |
__FILE__, __LINE__, __VA_ARGS__)
|
|
Packit |
18d29c |
#else
|
|
Packit |
18d29c |
#define RAW_LOG_FATAL(...) \
|
|
Packit |
18d29c |
do { \
|
|
Packit |
18d29c |
@ac_google_namespace@::RawLogStub__(0, __VA_ARGS__); \
|
|
Packit |
18d29c |
exit(1); \
|
|
Packit |
18d29c |
} while (0)
|
|
Packit |
18d29c |
#endif // STRIP_LOG <= 3
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// Similar to CHECK(condition) << message,
|
|
Packit |
18d29c |
// but for low-level modules: we use only RAW_LOG that does not allocate memory.
|
|
Packit |
18d29c |
// We do not want to provide args list here to encourage this usage:
|
|
Packit |
18d29c |
// if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
|
Packit |
18d29c |
// so that the args are not computed when not needed.
|
|
Packit |
18d29c |
#define RAW_CHECK(condition, message) \
|
|
Packit |
18d29c |
do { \
|
|
Packit |
18d29c |
if (!(condition)) { \
|
|
Packit |
18d29c |
RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
|
Packit |
18d29c |
} \
|
|
Packit |
18d29c |
} while (0)
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// Debug versions of RAW_LOG and RAW_CHECK
|
|
Packit |
18d29c |
#ifndef NDEBUG
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
|
|
Packit |
18d29c |
#define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#else // NDEBUG
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#define RAW_DLOG(severity, ...) \
|
|
Packit |
18d29c |
while (false) \
|
|
Packit |
18d29c |
RAW_LOG(severity, __VA_ARGS__)
|
|
Packit |
18d29c |
#define RAW_DCHECK(condition, message) \
|
|
Packit |
18d29c |
while (false) \
|
|
Packit |
18d29c |
RAW_CHECK(condition, message)
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#endif // NDEBUG
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// Stub log function used to work around for unused variable warnings when
|
|
Packit |
18d29c |
// building with STRIP_LOG > 0.
|
|
Packit |
18d29c |
static inline void RawLogStub__(int /* ignored */, ...) {
|
|
Packit |
18d29c |
}
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// Helper function to implement RAW_LOG and RAW_VLOG
|
|
Packit |
18d29c |
// Logs format... at "severity" level, reporting it
|
|
Packit |
18d29c |
// as called from file:line.
|
|
Packit |
18d29c |
// This does not allocate memory or acquire locks.
|
|
Packit |
18d29c |
GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
|
|
Packit |
18d29c |
const char* file,
|
|
Packit |
18d29c |
int line,
|
|
Packit |
18d29c |
const char* format, ...)
|
|
Packit |
18d29c |
@ac_cv___attribute___printf_4_5@;
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
// Hack to propagate time information into this module so that
|
|
Packit |
18d29c |
// this module does not have to directly call localtime_r(),
|
|
Packit |
18d29c |
// which could allocate memory.
|
|
Packit |
18d29c |
GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
@ac_google_end_namespace@
|
|
Packit |
18d29c |
|
|
Packit |
18d29c |
#endif // BASE_RAW_LOGGING_H_
|