// Copyright (c) 2024, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: Ray Sidney
//
// This file contains #include information about logging-related stuff.
// Pretty much everybody needs to #include this file so that they can
// log various happenings.
//
#ifndef GLOG_LOGGING_H
#define GLOG_LOGGING_H
#include <atomic>
#include <cerrno>
#include <chrono>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iosfwd>
#include <memory>
#include <ostream>
#include <sstream>
#include <string>
#include <thread>
#include <utility>
#include <vector>
#if defined(GLOG_USE_GLOG_EXPORT)
# include "glog/export.h"
#endif
#if !defined(GLOG_EXPORT) || !defined(GLOG_NO_EXPORT)
# error <glog/logging.h> was not included correctly. See the documentation for how to consume the library.
#endif
#include "glog/flags.h"
#include "glog/platform.h"
#include "glog/types.h"
#if defined(__has_attribute)
# if __has_attribute(used)
# define GLOG_USED __attribute__((used))
# endif // __has_attribute(used)
#endif // defined(__has_attribute)
#if !defined(GLOG_USED)
# define GLOG_USED
#endif // !defined(GLOG_USED)
#include "glog/log_severity.h"
#include "glog/vlog_is_on.h"
namespace google {
struct GLOG_EXPORT LogMessageTime {
LogMessageTime();
explicit LogMessageTime(std::chrono::system_clock::time_point now);
const std::chrono::system_clock::time_point& when() const noexcept {
return timestamp_;
}
int sec() const noexcept { return tm_.tm_sec; }
long usec() const noexcept { return usecs_.count(); }
int(min)() const noexcept { return tm_.tm_min; }
int hour() const noexcept { return tm_.tm_hour; }
int day() const noexcept { return tm_.tm_mday; }
int month() const noexcept { return tm_.tm_mon; }
int year() const noexcept { return tm_.tm_year; }
int dayOfWeek() const noexcept { return tm_.tm_wday; }
int dayInYear() const noexcept { return tm_.tm_yday; }
int dst() const noexcept { return tm_.tm_isdst; }
std::chrono::seconds gmtoffset() const noexcept { return gmtoffset_; }
const std::tm& tm() const noexcept { return tm_; }
private:
std::tm tm_{}; // Time of creation of LogMessage
std::chrono::system_clock::time_point
timestamp_; // Time of creation of LogMessage in seconds
std::chrono::microseconds usecs_;
std::chrono::seconds gmtoffset_;
};
} // namespace google
// The global value of GOOGLE_STRIP_LOG. All the messages logged to
// LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.
// If it can be determined at compile time that the message will not be
// printed, the statement will be compiled out.
//
// Example: to strip out all INFO and WARNING messages, use the value
// of 2 below. To make an exception for WARNING messages from a single
// file, add "#define GOOGLE_STRIP_LOG 1" to that file _before_ including
// base/logging.h
#ifndef GOOGLE_STRIP_LOG
# define GOOGLE_STRIP_LOG 0
#endif
// GCC can be told that a certain branch is not likely to be taken (for
// instance, a CHECK failure), and use that information in static analysis.
// Giving it this information can help it optimize for the common case in
// the absence of better information (ie. -fprofile-arcs).
//
#if defined(__has_builtin)
# if __has_builtin(__builtin_expect)
# define GLOG_BUILTIN_EXPECT_PRESENT
# endif
#endif
#if !defined(GLOG_BUILTIN_EXPECT_PRESENT) && defined(__GNUG__)
// __has_builtin is not available prior to GCC 10
# define GLOG_BUILTIN_EXPECT_PRESENT
#endif
#if defined(GLOG_BUILTIN_EXPECT_PRESENT)
# ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
# define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) (__builtin_expect(x, 0))
# endif
# ifndef GOOGLE_PREDICT_FALSE
# define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0))
# endif
# ifndef GOOGLE_PREDICT_TRUE
# define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
# endif
#else
# ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
# define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) x
# endif
# ifndef GOOGLE_PREDICT_TRUE
# define GOOGLE_PREDICT_FALSE(x) x
# endif
# ifndef GOOGLE_PREDICT_TRUE
# define GOOGLE_PREDICT_TRUE(x) x
# endif
#endif
#undef GLOG_BUILTIN_EXPECT_PRESENT
// Make a bunch of macros for logging. The way to log things is to stream
// things to LOG(<a particular severity level>). E.g.,
//
// LOG(INFO) << "Found " << num_cookies << " cookies";
//
// You can capture log messages in a string, rather than reporting them
// immediately:
//
// vector<string> errors;
// LOG_STRING(ERROR, &errors) << "Couldn't parse cookie #" << cookie_num;
//
// This pushes back the new error onto 'errors'; if given a nullptr pointer,
// it reports the error via LOG(ERROR).
//
// You can also do conditional logging:
//
// LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
//
// You can also do occasional logging (log every n'th occurrence of an
// event):
//
// LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
//
// The above will cause log messages to be output on the 1st, 11th, 21st, ...
// times it is executed. Note that the special google::COUNTER value is used
// to identify which repetition is happening.
//
// You can also do occasional conditional logging (log every n'th
// occurrence of an event, when condition is satisfied):
//
// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
// << "th big cookie";
//
// You can log messages the first N times your code executes a line. E.g.
//
// LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
//
// Outputs log messages for the first 20 times it is executed.
//
// Analogous SYSLOG, SYSLOG_IF, and SYSLOG_EVERY_N macros are available.
// These log to syslog as well as to the normal logs. If you use these at
// all, you need to be aware that syslog can drastically reduce performance,
// especially if it is configured for remote logging! Don't use these
// unless you fully understand this and have a concrete need to use them.
// Even then, try to minimize your use of them.
//
// There are also "debug mode" logging macros like the ones above:
//
// DLOG(INFO) << "Found cookies";
//
// DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
//
// DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
//
// All "debug mode" logging is compiled away to nothing for non-debug mode
// compiles.
//
// We also have
//
// LOG_ASSERT(assertion);
// DLOG_ASSERT(asse
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
glog.zip (6个子文件)
glog
debug
glogd.dll 686KB
logging.h 69KB
glogd.lib 68KB
release
glog.dll 203KB
glog.lib 68KB
logging.h 69KB
共 6 条
- 1
资源评论
三月微暖寻春笋
- 粉丝: 904
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功