From 63f445af6501766ed7321cfebdaade632ad37696 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Thu, 4 Jan 2024 16:57:52 +0100 Subject: [PATCH] feat: make headers self-contained --- .github/workflows/linux.yml | 1 - .github/workflows/macos.yml | 2 +- .github/workflows/windows.yml | 1 - CMakeLists.txt | 79 ++++++- bazel/glog.bzl | 6 + gcovr.cfg | 1 + src/flags.cc | 157 ++++++++++++++ src/glog/flags.h | 187 +++++++++++++++++ src/glog/log_severity.h | 8 + src/glog/logging.h | 194 +----------------- src/glog/platform.h | 2 +- src/glog/raw_logging.h | 17 +- src/glog/stl_logging.h | 6 +- src/glog/types.h | 81 ++++++++ src/glog/vlog_is_on.h | 26 ++- src/includes_unittest/CMakeLists.txt | 16 ++ .../glog_includes_logging.cc | 39 ++++ .../glog_includes_raw_logging.cc | 39 ++++ .../glog_includes_stl_logging.cc | 34 +++ .../glog_includes_vlog_is_on.cc | 34 +++ src/logging.cc | 105 ---------- src/logging_unittest.cc | 2 - src/utilities.cc | 3 - src/vlog_is_on.cc | 14 -- 24 files changed, 705 insertions(+), 349 deletions(-) create mode 100644 src/flags.cc create mode 100644 src/glog/flags.h create mode 100644 src/glog/types.h create mode 100644 src/includes_unittest/CMakeLists.txt create mode 100644 src/includes_unittest/glog_includes_logging.cc create mode 100644 src/includes_unittest/glog_includes_raw_logging.cc create mode 100644 src/includes_unittest/glog_includes_stl_logging.cc create mode 100644 src/includes_unittest/glog_includes_vlog_is_on.cc diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a2777feb8..ac2b49049 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -128,7 +128,6 @@ jobs: run: | cd build_${{matrix.build_type}} gcovr -r .. . -s --xml coverage.xml - cd .. - name: Upload Coverage to Codecov if: matrix.build_type == 'Debug' diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 01e6e9f77..7fc296678 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -63,8 +63,8 @@ jobs: if: matrix.build_type == 'Debug' run: | cd build_${{matrix.build_type}} + rm -r Tests/ gcovr -r .. . -s --cobertura coverage.xml - cd .. - name: Upload Coverage to Codecov if: matrix.build_type == 'Debug' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 01d3f2950..ab3ea940d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -231,7 +231,6 @@ jobs: run: | cd build_${{matrix.build_type}} gcovr -r .. . -s --cobertura coverage.xml - cd .. - name: Upload Coverage to Codecov if: matrix.build_type == 'Debug' diff --git a/CMakeLists.txt b/CMakeLists.txt index c7cbbf165..f7c157aef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,8 @@ set (GLOG_PUBLIC_H src/glog/platform.h src/glog/raw_logging.h src/glog/stl_logging.h + src/glog/types.h + src/glog/flags.h src/glog/vlog_is_on.h ) @@ -363,6 +365,7 @@ set (GLOG_SRCS src/base/googleinit.h src/demangle.cc src/demangle.h + src/flags.cc src/logging.cc src/raw_logging.cc src/signalhandler.cc @@ -787,10 +790,6 @@ if (BUILD_TESTING) PROPERTIES WILL_FAIL ON ) - set (_glog_TEST_ENVIRONMENT - glog_ROOT=${glog_BINARY_DIR} - ) - add_test (NAME log_severity_constants COMMAND ${CMAKE_CTEST_COMMAND} --build-config $ --build-and-test @@ -804,9 +803,9 @@ if (BUILD_TESTING) -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -Dglog_DIR=${glog_BINARY_DIR} ) set_tests_properties (log_severity_constants PROPERTIES - ENVIRONMENT "${_glog_TEST_ENVIRONMENT}" PASS_REGULAR_EXPRESSION "COMPACT_GOOGLE_LOG_[1-3]" ) @@ -823,9 +822,7 @@ if (BUILD_TESTING) -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} - ) - set_tests_properties (log_severity_conversion PROPERTIES - ENVIRONMENT "${_glog_TEST_ENVIRONMENT}" + -Dglog_DIR=${glog_BINARY_DIR} ) if (CMAKE_COMPILER_IS_GNUCXX) @@ -842,13 +839,75 @@ if (BUILD_TESTING) ) else (CMAKE_COMPILER_IS_GNUCXX) message (AUTHOR_WARNING - "Unsuuported C++ compiler ${CMAKE_CXX_COMPILER_ID}: " + "Unsupported C++ compiler ${CMAKE_CXX_COMPILER_ID}: " "log_severity_conversion test will be disabled" ) set_tests_properties (log_severity_conversion DISABLED ON) endif (CMAKE_COMPILER_IS_GNUCXX) - unset (_glog_TEST_ENVIRONMENT) + add_test (NAME includes_logging COMMAND ${CMAKE_CTEST_COMMAND} + --build-config $ + --build-and-test + "${glog_SOURCE_DIR}/src/includes_unittest" + "${glog_BINARY_DIR}/Tests/includes_logging" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target glog_includes_logging + --build-options + -DCMAKE_BUILD_TYPE=$ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -Dglog_DIR=${glog_BINARY_DIR} + ) + + add_test (NAME includes_vlog_is_on COMMAND ${CMAKE_CTEST_COMMAND} + --build-config $ + --build-and-test + "${glog_SOURCE_DIR}/src/includes_unittest" + "${glog_BINARY_DIR}/Tests/includes_vlog_is_on" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target glog_includes_vlog_is_on + --build-options + -DCMAKE_BUILD_TYPE=$ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -Dglog_DIR=${glog_BINARY_DIR} + ) + + add_test (NAME includes_raw_logging COMMAND ${CMAKE_CTEST_COMMAND} + --build-config $ + --build-and-test + "${glog_SOURCE_DIR}/src/includes_unittest" + "${glog_BINARY_DIR}/Tests/includes_raw_logging" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target glog_includes_raw_logging + --build-options + -DCMAKE_BUILD_TYPE=$ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -Dglog_DIR=${glog_BINARY_DIR} + ) + + add_test (NAME includes_stl_logging COMMAND ${CMAKE_CTEST_COMMAND} + --build-config $ + --build-and-test + "${glog_SOURCE_DIR}/src/includes_unittest" + "${glog_BINARY_DIR}/Tests/includes_stl_logging" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target glog_includes_stl_logging + --build-options + -DCMAKE_BUILD_TYPE=$ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -Dglog_DIR=${glog_BINARY_DIR} + ) endif (BUILD_TESTING) install (TARGETS glog diff --git a/bazel/glog.bzl b/bazel/glog.bzl index a38e508f5..2f248d0b7 100644 --- a/bazel/glog.bzl +++ b/bazel/glog.bzl @@ -166,6 +166,7 @@ def glog_library(with_gflags = 1, **kwargs): "src/base/googleinit.h", "src/demangle.cc", "src/demangle.h", + "src/flags.cc", "src/logging.cc", "src/raw_logging.cc", "src/signalhandler.cc", @@ -184,11 +185,13 @@ def glog_library(with_gflags = 1, **kwargs): "//conditions:default": [], }), hdrs = [ + "src/glog/flags.h", "src/glog/log_severity.h", "src/glog/logging.h", "src/glog/platform.h", "src/glog/raw_logging.h", "src/glog/stl_logging.h", + "src/glog/types.h", "src/glog/vlog_is_on.h", ], # https://github.com/google/glog/issues/837: Replacing @@ -251,10 +254,13 @@ def glog_library(with_gflags = 1, **kwargs): native.cc_library( name = "strip_include_prefix_hack", hdrs = [ + "src/glog/flags.h", "src/glog/log_severity.h", "src/glog/logging.h", + "src/glog/platform.h", "src/glog/raw_logging.h", "src/glog/stl_logging.h", + "src/glog/types.h", "src/glog/vlog_is_on.h", ], ) diff --git a/gcovr.cfg b/gcovr.cfg index 77c7324fa..89a860e5a 100644 --- a/gcovr.cfg +++ b/gcovr.cfg @@ -1,6 +1,7 @@ exclude = src/.*_unittest\.cc exclude = src/googletest\.h exclude = src/mock-log\.h +exclude-directories = Tests/ exclude-throw-branches = yes exclude-unreachable-branches = yes filter = .*/glog/.*\.h diff --git a/src/flags.cc b/src/flags.cc new file mode 100644 index 000000000..1fa17bd89 --- /dev/null +++ b/src/flags.cc @@ -0,0 +1,157 @@ +// 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. +// + +#include "glog/flags.h" + +#include +#include + +#include "base/commandlineflags.h" +#include "glog/log_severity.h" + +namespace { + +// Compute the default value for --log_dir +static const char* DefaultLogDir() { + constexpr const char* const names[]{"GOOGLE_LOG_DIR", "TEST_TMPDIR"}; + for (const char* const name : names) { + const char* const env = std::getenv(name); + if (env != nullptr && env[0] != '\0') { + return env; + } + } + return ""; +} + +bool BoolFromEnv(const char* varname, bool defval) { + const char* const valstr = getenv(varname); + if (!valstr) { + return defval; + } + return std::memchr("tTyY1\0", valstr[0], 6) != nullptr; +} + +} // namespace + +GLOG_DEFINE_bool(timestamp_in_logfile_name, + BoolFromEnv("GOOGLE_TIMESTAMP_IN_LOGFILE_NAME", true), + "put a timestamp at the end of the log file name"); +GLOG_DEFINE_bool(logtostderr, BoolFromEnv("GOOGLE_LOGTOSTDERR", false), + "log messages go to stderr instead of logfiles"); +GLOG_DEFINE_bool(alsologtostderr, BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false), + "log messages go to stderr in addition to logfiles"); +GLOG_DEFINE_bool(colorlogtostderr, false, + "color messages logged to stderr (if supported by terminal)"); +GLOG_DEFINE_bool(colorlogtostdout, false, + "color messages logged to stdout (if supported by terminal)"); +GLOG_DEFINE_bool(logtostdout, BoolFromEnv("GOOGLE_LOGTOSTDOUT", false), + "log messages go to stdout instead of logfiles"); +#ifdef GLOG_OS_LINUX +GLOG_DEFINE_bool( + drop_log_memory, true, + "Drop in-memory buffers of log contents. " + "Logs can grow very quickly and they are rarely read before they " + "need to be evicted from memory. Instead, drop them from memory " + "as soon as they are flushed to disk."); +#endif + +// By default, errors (including fatal errors) get logged to stderr as +// well as the file. +// +// The default is ERROR instead of FATAL so that users can see problems +// when they run a program without having to look in another file. +DEFINE_int32(stderrthreshold, google::GLOG_ERROR, + "log messages at or above this level are copied to stderr in " + "addition to logfiles. This flag obsoletes --alsologtostderr."); + +GLOG_DEFINE_string(alsologtoemail, "", + "log messages go to these email addresses " + "in addition to logfiles"); +GLOG_DEFINE_bool(log_file_header, true, + "Write the file header at the start of each log file"); +GLOG_DEFINE_bool(log_prefix, true, + "Prepend the log prefix to the start of each log line"); +GLOG_DEFINE_bool(log_year_in_prefix, true, + "Include the year in the log prefix"); +GLOG_DEFINE_int32(minloglevel, 0, + "Messages logged at a lower level than this don't " + "actually get logged anywhere"); +GLOG_DEFINE_int32(logbuflevel, 0, + "Buffer log messages logged at this level or lower" + " (-1 means don't buffer; 0 means buffer INFO only;" + " ...)"); +GLOG_DEFINE_int32(logbufsecs, 30, + "Buffer log messages for at most this many seconds"); + +GLOG_DEFINE_int32(logcleansecs, 60 * 5, // every 5 minutes + "Clean overdue logs every this many seconds"); + +GLOG_DEFINE_int32(logemaillevel, 999, + "Email log messages logged at this level or higher" + " (0 means email all; 3 means email FATAL only;" + " ...)"); +GLOG_DEFINE_string(logmailer, "", "Mailer used to send logging email"); + +GLOG_DEFINE_int32(logfile_mode, 0664, "Log file mode/permissions."); + +GLOG_DEFINE_string( + log_dir, DefaultLogDir(), + "If specified, logfiles are written into this directory instead " + "of the default logging directory."); +GLOG_DEFINE_string(log_link, "", + "Put additional links to the log " + "files in this directory"); + +GLOG_DEFINE_uint32(max_log_size, 1800, + "approx. maximum log file size (in MB). A value of 0 will " + "be silently overridden to 1."); + +GLOG_DEFINE_bool(stop_logging_if_full_disk, false, + "Stop attempting to log to disk if the disk is full."); + +GLOG_DEFINE_string(log_backtrace_at, "", + "Emit a backtrace when logging at file:linenum."); + +GLOG_DEFINE_bool(log_utc_time, false, "Use UTC time for logging."); + +GLOG_DEFINE_int32(v, 0, + "Show all VLOG(m) messages for m <= this." + " Overridable by --vmodule."); + +GLOG_DEFINE_string( + vmodule, "", + "per-module verbose level." + " Argument is a comma-separated list of =." + " is a glob pattern, matched against the filename base" + " (that is, name ignoring .cc/.h./-inl.h)." + " overrides any value given by --v."); + +GLOG_DEFINE_bool(symbolize_stacktrace, true, + "Symbolize the stack trace in the tombstone"); diff --git a/src/glog/flags.h b/src/glog/flags.h new file mode 100644 index 000000000..b53a381e1 --- /dev/null +++ b/src/glog/flags.h @@ -0,0 +1,187 @@ +// 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. +// + +#ifndef GLOG_FLAGS_H +#define GLOG_FLAGS_H + +#include + +#if defined(GLOG_USE_GFLAGS) +# include +#endif + +#if defined(GLOG_USE_GLOG_EXPORT) +# include "glog/export.h" +#endif + +#include "glog/platform.h" +#include "glog/types.h" + +#pragma push_macro("DECLARE_VARIABLE") +#pragma push_macro("DECLARE_bool") +#pragma push_macro("DECLARE_string") +#pragma push_macro("DECLARE_int32") +#pragma push_macro("DECLARE_uint32") + +#ifdef DECLARE_VARIABLE +# undef DECLARE_VARIABLE +#endif + +#ifdef DECLARE_bool +# undef DECLARE_bool +#endif + +#ifdef DECLARE_string +# undef DECLARE_string +#endif + +#ifdef DECLARE_int32 +# undef DECLARE_int32 +#endif + +#ifdef DECLARE_uint32 +# undef DECLARE_uint32 +#endif + +#ifndef DECLARE_VARIABLE +# define DECLARE_VARIABLE(type, shorttype, name, tn) \ + namespace fL##shorttype { \ + extern GLOG_EXPORT type FLAGS_##name; \ + } \ + using fL##shorttype::FLAGS_##name + +// bool specialization +# define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name, bool) + +// int32 specialization +# define DECLARE_int32(name) DECLARE_VARIABLE(google::int32, I, name, int32) + +# if !defined(DECLARE_uint32) +// uint32 specialization +# define DECLARE_uint32(name) \ + DECLARE_VARIABLE(google::uint32, U, name, uint32) +# endif // !defined(DECLARE_uint32) && !defined(GLOG_USE_GFLAGS) + +// Special case for string, because we have to specify the namespace +// std::string, which doesn't play nicely with our FLAG__namespace hackery. +# define DECLARE_string(name) \ + namespace fLS { \ + extern GLOG_EXPORT std::string& FLAGS_##name; \ + } \ + using fLS::FLAGS_##name +#endif + +DECLARE_int32(logemaillevel); +DECLARE_int32(logcleansecs); + +#ifdef GLOG_OS_LINUX +DECLARE_bool(drop_log_memory); +#endif +DECLARE_string(alsologtoemail); +DECLARE_string(log_backtrace_at); + +// Set whether appending a timestamp to the log file name +DECLARE_bool(timestamp_in_logfile_name); + +// Set whether log messages go to stdout instead of logfiles +DECLARE_bool(logtostdout); + +// Set color messages logged to stdout (if supported by terminal). +DECLARE_bool(colorlogtostdout); + +// Set whether log messages go to stderr instead of logfiles +DECLARE_bool(logtostderr); + +// Set whether log messages go to stderr in addition to logfiles. +DECLARE_bool(alsologtostderr); + +// Set color messages logged to stderr (if supported by terminal). +DECLARE_bool(colorlogtostderr); + +// Log messages at a level >= this flag are automatically sent to +// stderr in addition to log files. +DECLARE_int32(stderrthreshold); + +// Set whether the log file header should be written upon creating a file. +DECLARE_bool(log_file_header); + +// Set whether the log prefix should be prepended to each line of output. +DECLARE_bool(log_prefix); + +// Set whether the year should be included in the log prefix. +DECLARE_bool(log_year_in_prefix); + +// Log messages at a level <= this flag are buffered. +// Log messages at a higher level are flushed immediately. +DECLARE_int32(logbuflevel); + +// Sets the maximum number of seconds which logs may be buffered for. +DECLARE_int32(logbufsecs); + +// Log suppression level: messages logged at a lower level than this +// are suppressed. +DECLARE_int32(minloglevel); + +// If specified, logfiles are written into this directory instead of the +// default logging directory. +DECLARE_string(log_dir); + +// Set the log file mode. +DECLARE_int32(logfile_mode); + +// Sets the path of the directory into which to put additional links +// to the log files. +DECLARE_string(log_link); + +DECLARE_int32(v); // in vlog_is_on.cc + +DECLARE_string(vmodule); // also in vlog_is_on.cc + +// Sets the maximum log file size (in MB). +DECLARE_uint32(max_log_size); + +// Sets whether to avoid logging to the disk if the disk is full. +DECLARE_bool(stop_logging_if_full_disk); + +// Use UTC time for logging +DECLARE_bool(log_utc_time); + +// Mailer used to send logging email +DECLARE_string(logmailer); + +DECLARE_bool(symbolize_stacktrace); + +#pragma pop_macro("DECLARE_VARIABLE") +#pragma pop_macro("DECLARE_bool") +#pragma pop_macro("DECLARE_string") +#pragma pop_macro("DECLARE_int32") +#pragma pop_macro("DECLARE_uint32") + +#endif // GLOG_FLAGS_H diff --git a/src/glog/log_severity.h b/src/glog/log_severity.h index 5a1497ef1..a0296f2ec 100644 --- a/src/glog/log_severity.h +++ b/src/glog/log_severity.h @@ -30,6 +30,12 @@ #ifndef BASE_LOG_SEVERITY_H__ #define BASE_LOG_SEVERITY_H__ +#if defined(GLOG_USE_GLOG_EXPORT) +# include "glog/export.h" +#endif + +namespace google { + // The recommended semantics of the log levels are as follows: // // INFO: @@ -113,4 +119,6 @@ enum { DEBUG_MODE = 1 }; # define IF_DEBUG_MODE(x) x #endif +} // namespace google + #endif // BASE_LOG_SEVERITY_H__ diff --git a/src/glog/logging.h b/src/glog/logging.h index 925ce6d48..169488b50 100644 --- a/src/glog/logging.h +++ b/src/glog/logging.h @@ -36,6 +36,7 @@ #ifndef GLOG_LOGGING_H #define GLOG_LOGGING_H +#include #include #include #include @@ -51,16 +52,13 @@ #include #include -#if defined(_MSC_VER) -# define GLOG_MSVC_PUSH_DISABLE_WARNING(n) \ - __pragma(warning(push)) __pragma(warning(disable : n)) -# define GLOG_MSVC_POP_WARNING() __pragma(warning(pop)) -#else -# define GLOG_MSVC_PUSH_DISABLE_WARNING(n) -# define GLOG_MSVC_POP_WARNING() +#if defined(GLOG_USE_GLOG_EXPORT) +# include "glog/export.h" #endif +#include "glog/flags.h" #include "glog/platform.h" +#include "glog/types.h" #if defined(__has_attribute) # if __has_attribute(used) @@ -72,31 +70,11 @@ # define GLOG_USED #endif // !defined(GLOG_USED) -#if defined(GLOG_USE_GLOG_EXPORT) -# include "glog/export.h" -#endif - -// We care a lot about number of bits things take up. Unfortunately, -// systems define their bit-specific ints in a lot of different ways. -// We use our own way, and have a typedef to get there. -// Note: these commands below may look like "#if 1" or "#if 0", but -// that's because they were constructed that way at ./configure time. -// Look at logging.h.in to see how they're calculated (based on your config). -#include // the normal place uint16_t is defined - -#if defined(GLOG_USE_GFLAGS) -# include -#endif - -#include +#include "glog/log_severity.h" +#include "glog/vlog_is_on.h" namespace google { -typedef std::int32_t int32; -typedef std::uint32_t uint32; -typedef std::int64_t int64; -typedef std::uint64_t uint64; - struct GLOG_EXPORT LogMessageTime { LogMessageTime(); explicit LogMessageTime(std::chrono::system_clock::time_point now); @@ -364,129 +342,6 @@ typedef void (*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, // synchronized. Hence, use caution when comparing the low bits of // timestamps from different machines. -#pragma push_macro("DECLARE_VARIABLE") -#pragma push_macro("DECLARE_bool") -#pragma push_macro("DECLARE_string") -#pragma push_macro("DECLARE_int32") -#pragma push_macro("DECLARE_uint32") - -#ifdef DECLARE_VARIABLE -# undef DECLARE_VARIABLE -#endif - -#ifdef DECLARE_bool -# undef DECLARE_bool -#endif - -#ifdef DECLARE_string -# undef DECLARE_string -#endif - -#ifdef DECLARE_int32 -# undef DECLARE_int32 -#endif - -#ifdef DECLARE_uint32 -# undef DECLARE_uint32 -#endif - -#ifndef DECLARE_VARIABLE -# define DECLARE_VARIABLE(type, shorttype, name, tn) \ - namespace fL##shorttype { \ - extern GLOG_EXPORT type FLAGS_##name; \ - } \ - using fL##shorttype::FLAGS_##name - -// bool specialization -# define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name, bool) - -// int32 specialization -# define DECLARE_int32(name) DECLARE_VARIABLE(google::int32, I, name, int32) - -# if !defined(DECLARE_uint32) -// uint32 specialization -# define DECLARE_uint32(name) \ - DECLARE_VARIABLE(google::uint32, U, name, uint32) -# endif // !defined(DECLARE_uint32) && !defined(GLOG_USE_GFLAGS) - -// Special case for string, because we have to specify the namespace -// std::string, which doesn't play nicely with our FLAG__namespace hackery. -# define DECLARE_string(name) \ - namespace fLS { \ - extern GLOG_EXPORT std::string& FLAGS_##name; \ - } \ - using fLS::FLAGS_##name -#endif - -// Set whether appending a timestamp to the log file name -DECLARE_bool(timestamp_in_logfile_name); - -// Set whether log messages go to stdout instead of logfiles -DECLARE_bool(logtostdout); - -// Set color messages logged to stdout (if supported by terminal). -DECLARE_bool(colorlogtostdout); - -// Set whether log messages go to stderr instead of logfiles -DECLARE_bool(logtostderr); - -// Set whether log messages go to stderr in addition to logfiles. -DECLARE_bool(alsologtostderr); - -// Set color messages logged to stderr (if supported by terminal). -DECLARE_bool(colorlogtostderr); - -// Log messages at a level >= this flag are automatically sent to -// stderr in addition to log files. -DECLARE_int32(stderrthreshold); - -// Set whether the log file header should be written upon creating a file. -DECLARE_bool(log_file_header); - -// Set whether the log prefix should be prepended to each line of output. -DECLARE_bool(log_prefix); - -// Set whether the year should be included in the log prefix. -DECLARE_bool(log_year_in_prefix); - -// Log messages at a level <= this flag are buffered. -// Log messages at a higher level are flushed immediately. -DECLARE_int32(logbuflevel); - -// Sets the maximum number of seconds which logs may be buffered for. -DECLARE_int32(logbufsecs); - -// Log suppression level: messages logged at a lower level than this -// are suppressed. -DECLARE_int32(minloglevel); - -// If specified, logfiles are written into this directory instead of the -// default logging directory. -DECLARE_string(log_dir); - -// Set the log file mode. -DECLARE_int32(logfile_mode); - -// Sets the path of the directory into which to put additional links -// to the log files. -DECLARE_string(log_link); - -DECLARE_int32(v); // in vlog_is_on.cc - -DECLARE_string(vmodule); // also in vlog_is_on.cc - -// Sets the maximum log file size (in MB). -DECLARE_uint32(max_log_size); - -// Sets whether to avoid logging to the disk if the disk is full. -DECLARE_bool(stop_logging_if_full_disk); - -// Use UTC time for logging -DECLARE_bool(log_utc_time); - -// Mailer used to send logging email -DECLARE_string(logmailer); - // Log messages below the GOOGLE_STRIP_LOG level will be compiled away for // security reasons. See LOG(severtiy) below. @@ -615,10 +470,6 @@ DECLARE_string(logmailer); namespace google { -// They need the definitions of integer types. -#include "glog/log_severity.h" -#include "glog/vlog_is_on.h" - // Initialize google's logging library. You will see the program name // specified by argv0 in log outputs. GLOG_EXPORT void InitGoogleLogging(const char* argv0); @@ -1030,34 +881,9 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) #define LOG_CURRENT_TIME LOG_EVERY_N_VARNAME(currentTime_, __LINE__) #define LOG_PREVIOUS_TIME LOG_EVERY_N_VARNAME(previousTime_, __LINE__) -#if defined(__has_feature) -# if __has_feature(thread_sanitizer) -# define GLOG_SANITIZE_THREAD 1 -# endif -#endif - -#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && \ - __SANITIZE_THREAD__ -# define GLOG_SANITIZE_THREAD 1 -#endif - -#if defined(GLOG_SANITIZE_THREAD) -# define GLOG_IFDEF_THREAD_SANITIZER(X) X -#else -# define GLOG_IFDEF_THREAD_SANITIZER(X) -#endif - -#if defined(GLOG_SANITIZE_THREAD) } // namespace google -// We need to identify the static variables as "benign" races -// to avoid noisy reports from TSAN. -extern "C" void AnnotateBenignRaceSized(const char* file, int line, - const volatile void* mem, size_t size, - const char* description); - namespace google { -#endif #define SOME_KIND_OF_LOG_EVERY_T(severity, seconds) \ constexpr std::chrono::nanoseconds LOG_TIME_PERIOD = \ @@ -1835,10 +1661,4 @@ GLOG_EXPORT void InstallFailureWriter(void (*writer)(const char* data, } // namespace google -#pragma pop_macro("DECLARE_VARIABLE") -#pragma pop_macro("DECLARE_bool") -#pragma pop_macro("DECLARE_string") -#pragma pop_macro("DECLARE_int32") -#pragma pop_macro("DECLARE_uint32") - #endif // GLOG_LOGGING_H diff --git a/src/glog/platform.h b/src/glog/platform.h index f9478e48a..3951f27c6 100644 --- a/src/glog/platform.h +++ b/src/glog/platform.h @@ -1,4 +1,4 @@ -// Copyright (c) 2008, Google Inc. +// Copyright (c) 2024, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/src/glog/raw_logging.h b/src/glog/raw_logging.h index b30e54019..f96545258 100644 --- a/src/glog/raw_logging.h +++ b/src/glog/raw_logging.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Google Inc. +// Copyright (c) 2024, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -36,18 +36,15 @@ #ifndef GLOG_RAW_LOGGING_H #define GLOG_RAW_LOGGING_H -#include - -namespace google { #include "glog/log_severity.h" -#include "glog/logging.h" #include "glog/vlog_is_on.h" -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wvariadic-macros" +#if defined(GLOG_USE_GLOG_EXPORT) +# include "glog/export.h" #endif +namespace google { + // This is similar to LOG(severity) << format... and VLOG(level) << format.., // but // * it is to be used ONLY by low-level modules that can't use normal LOG() @@ -154,10 +151,6 @@ namespace google { #endif // NDEBUG -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif - // Stub log function used to work around for unused variable warnings when // building with STRIP_LOG > 0. static inline void RawLogStub__(int /* ignored */, ...) {} diff --git a/src/glog/stl_logging.h b/src/glog/stl_logging.h index 3689df276..8dd7707e0 100644 --- a/src/glog/stl_logging.h +++ b/src/glog/stl_logging.h @@ -36,8 +36,8 @@ // CHECK_EQ(v1, v2); // -#ifndef UTIL_GTL_STL_LOGGING_INL_H_ -#define UTIL_GTL_STL_LOGGING_INL_H_ +#ifndef GLOG_STL_LOGGING_H +#define GLOG_STL_LOGGING_H #include #include @@ -165,4 +165,4 @@ namespace std { using ::operator<<; } -#endif // UTIL_GTL_STL_LOGGING_INL_H_ +#endif // GLOG_STL_LOGGING_H diff --git a/src/glog/types.h b/src/glog/types.h new file mode 100644 index 000000000..dca2f06f8 --- /dev/null +++ b/src/glog/types.h @@ -0,0 +1,81 @@ + +// 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. +// + +#ifndef GLOG_TYPES_H +#define GLOG_TYPES_H + +#include +#include + +namespace google { + +using int32 = std::int32_t; +using uint32 = std::uint32_t; +using int64 = std::int64_t; +using uint64 = std::uint64_t; + +} // namespace google + +#if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define GLOG_SANITIZE_THREAD 1 +# endif +#endif + +#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && \ + __SANITIZE_THREAD__ +# define GLOG_SANITIZE_THREAD 1 +#endif + +#if defined(GLOG_SANITIZE_THREAD) +# define GLOG_IFDEF_THREAD_SANITIZER(X) X +#else +# define GLOG_IFDEF_THREAD_SANITIZER(X) +#endif + +#if defined(_MSC_VER) +# define GLOG_MSVC_PUSH_DISABLE_WARNING(n) \ + __pragma(warning(push)) __pragma(warning(disable : n)) +# define GLOG_MSVC_POP_WARNING() __pragma(warning(pop)) +#else +# define GLOG_MSVC_PUSH_DISABLE_WARNING(n) +# define GLOG_MSVC_POP_WARNING() +#endif + +#if defined(GLOG_SANITIZE_THREAD) +// We need to identify the static variables as "benign" races +// to avoid noisy reports from TSAN. +extern "C" void AnnotateBenignRaceSized(const char* file, int line, + const volatile void* mem, size_t size, + const char* description); +#endif // defined(GLOG_SANITIZE_THREAD) + +#endif // GLOG_TYPES_H diff --git a/src/glog/vlog_is_on.h b/src/glog/vlog_is_on.h index 914a57d13..c183c55d4 100644 --- a/src/glog/vlog_is_on.h +++ b/src/glog/vlog_is_on.h @@ -1,4 +1,4 @@ -// Copyright (c) 2023, Google Inc. +// Copyright (c) 2024, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -58,12 +58,17 @@ // CAVEAT: --vmodule functionality is not available in non gcc compilers. // -#ifndef BASE_VLOG_IS_ON_H_ -#define BASE_VLOG_IS_ON_H_ +#ifndef GLOG_VLOG_IS_ON_H +#define GLOG_VLOG_IS_ON_H #include -#include "glog/log_severity.h" +#if defined(GLOG_USE_GLOG_EXPORT) +# include "glog/export.h" +#endif + +#include "glog/flags.h" +#include "glog/types.h" #if defined(__GNUC__) // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site. @@ -89,6 +94,8 @@ # define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel)) #endif +namespace google { + // Set VLOG(_IS_ON) level for module_pattern to log_level. // This lets us dynamically control what is normally set by the --vmodule flag. // Returns the level that previously applied to module_pattern. @@ -102,7 +109,7 @@ extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level); // Various declarations needed for VLOG_IS_ON above: ========================= struct SiteFlag { - google::int32* level; + int32* level; const char* base_name; std::size_t base_len; SiteFlag* next; @@ -116,9 +123,10 @@ struct SiteFlag { // verbose_level is the argument to VLOG_IS_ON // We will return the return value for VLOG_IS_ON // and if possible set *site_flag appropriately. -extern GLOG_EXPORT bool InitVLOG3__(google::SiteFlag* site_flag, - google::int32* site_default, +extern GLOG_EXPORT bool InitVLOG3__(SiteFlag* site_flag, + int32* site_default, const char* fname, - google::int32 verbose_level); + int32 verbose_level); +} // namespace google -#endif // BASE_VLOG_IS_ON_H_ +#endif // GLOG_VLOG_IS_ON_H diff --git a/src/includes_unittest/CMakeLists.txt b/src/includes_unittest/CMakeLists.txt new file mode 100644 index 000000000..8f70fe916 --- /dev/null +++ b/src/includes_unittest/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required (VERSION 3.16) +project (glog_includes LANGUAGES CXX) + +find_package (glog REQUIRED NO_MODULE) + +add_executable (glog_includes_logging glog_includes_logging.cc) +target_link_libraries (glog_includes_logging PRIVATE glog::glog) + +add_executable (glog_includes_vlog_is_on glog_includes_vlog_is_on.cc) +target_link_libraries (glog_includes_vlog_is_on PRIVATE glog::glog) + +add_executable (glog_includes_raw_logging glog_includes_raw_logging.cc) +target_link_libraries (glog_includes_raw_logging PRIVATE glog::glog) + +add_executable (glog_includes_stl_logging glog_includes_stl_logging.cc) +target_link_libraries (glog_includes_stl_logging PRIVATE glog::glog) diff --git a/src/includes_unittest/glog_includes_logging.cc b/src/includes_unittest/glog_includes_logging.cc new file mode 100644 index 000000000..bde0834f9 --- /dev/null +++ b/src/includes_unittest/glog_includes_logging.cc @@ -0,0 +1,39 @@ +// 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: Sergiu Deitsch + +#include + +int main() { + LOG(INFO) << "info"; + LOG(WARNING) << "warning"; + LOG(ERROR) << "error"; + LOG(FATAL) << "fatal"; +} diff --git a/src/includes_unittest/glog_includes_raw_logging.cc b/src/includes_unittest/glog_includes_raw_logging.cc new file mode 100644 index 000000000..c9d08c1b4 --- /dev/null +++ b/src/includes_unittest/glog_includes_raw_logging.cc @@ -0,0 +1,39 @@ +// 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: Sergiu Deitsch + +#include + +int main() { + RAW_LOG(INFO, "info"); + RAW_LOG(WARNING, "warning"); + RAW_LOG(ERROR, "error"); + RAW_LOG(FATAL, "fatal"); +} diff --git a/src/includes_unittest/glog_includes_stl_logging.cc b/src/includes_unittest/glog_includes_stl_logging.cc new file mode 100644 index 000000000..1d366bb26 --- /dev/null +++ b/src/includes_unittest/glog_includes_stl_logging.cc @@ -0,0 +1,34 @@ +// 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: Sergiu Deitsch + +#include + +int main() {} diff --git a/src/includes_unittest/glog_includes_vlog_is_on.cc b/src/includes_unittest/glog_includes_vlog_is_on.cc new file mode 100644 index 000000000..164b0e234 --- /dev/null +++ b/src/includes_unittest/glog_includes_vlog_is_on.cc @@ -0,0 +1,34 @@ +// 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: Sergiu Deitsch + +#include + +int main() { VLOG_IS_ON(0); } diff --git a/src/logging.cc b/src/logging.cc index 7498fd0b0..0bc961d4d 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -44,8 +44,6 @@ #include #include -#include "base/commandlineflags.h" // to get the program name -#include "base/googleinit.h" #include "config.h" #include "glog/raw_logging.h" #include "utilities.h" @@ -131,109 +129,6 @@ using std::fdopen; // There is no thread annotation support. #define EXCLUSIVE_LOCKS_REQUIRED(mu) -static bool BoolFromEnv(const char* varname, bool defval) { - const char* const valstr = getenv(varname); - if (!valstr) { - return defval; - } - return memchr("tTyY1\0", valstr[0], 6) != nullptr; -} - -GLOG_DEFINE_bool(timestamp_in_logfile_name, - BoolFromEnv("GOOGLE_TIMESTAMP_IN_LOGFILE_NAME", true), - "put a timestamp at the end of the log file name"); -GLOG_DEFINE_bool(logtostderr, BoolFromEnv("GOOGLE_LOGTOSTDERR", false), - "log messages go to stderr instead of logfiles"); -GLOG_DEFINE_bool(alsologtostderr, BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false), - "log messages go to stderr in addition to logfiles"); -GLOG_DEFINE_bool(colorlogtostderr, false, - "color messages logged to stderr (if supported by terminal)"); -GLOG_DEFINE_bool(colorlogtostdout, false, - "color messages logged to stdout (if supported by terminal)"); -GLOG_DEFINE_bool(logtostdout, BoolFromEnv("GOOGLE_LOGTOSTDOUT", false), - "log messages go to stdout instead of logfiles"); -#ifdef GLOG_OS_LINUX -GLOG_DEFINE_bool( - drop_log_memory, true, - "Drop in-memory buffers of log contents. " - "Logs can grow very quickly and they are rarely read before they " - "need to be evicted from memory. Instead, drop them from memory " - "as soon as they are flushed to disk."); -#endif - -// By default, errors (including fatal errors) get logged to stderr as -// well as the file. -// -// The default is ERROR instead of FATAL so that users can see problems -// when they run a program without having to look in another file. -DEFINE_int32(stderrthreshold, google::GLOG_ERROR, - "log messages at or above this level are copied to stderr in " - "addition to logfiles. This flag obsoletes --alsologtostderr."); - -GLOG_DEFINE_string(alsologtoemail, "", - "log messages go to these email addresses " - "in addition to logfiles"); -GLOG_DEFINE_bool(log_file_header, true, - "Write the file header at the start of each log file"); -GLOG_DEFINE_bool(log_prefix, true, - "Prepend the log prefix to the start of each log line"); -GLOG_DEFINE_bool(log_year_in_prefix, true, - "Include the year in the log prefix"); -GLOG_DEFINE_int32(minloglevel, 0, - "Messages logged at a lower level than this don't " - "actually get logged anywhere"); -GLOG_DEFINE_int32(logbuflevel, 0, - "Buffer log messages logged at this level or lower" - " (-1 means don't buffer; 0 means buffer INFO only;" - " ...)"); -GLOG_DEFINE_int32(logbufsecs, 30, - "Buffer log messages for at most this many seconds"); - -GLOG_DEFINE_int32(logcleansecs, 60 * 5, // every 5 minutes - "Clean overdue logs every this many seconds"); - -GLOG_DEFINE_int32(logemaillevel, 999, - "Email log messages logged at this level or higher" - " (0 means email all; 3 means email FATAL only;" - " ...)"); -GLOG_DEFINE_string(logmailer, "", "Mailer used to send logging email"); - -// Compute the default value for --log_dir -static const char* DefaultLogDir() { - const char* env; - env = getenv("GOOGLE_LOG_DIR"); - if (env != nullptr && env[0] != '\0') { - return env; - } - env = getenv("TEST_TMPDIR"); - if (env != nullptr && env[0] != '\0') { - return env; - } - return ""; -} - -GLOG_DEFINE_int32(logfile_mode, 0664, "Log file mode/permissions."); - -GLOG_DEFINE_string( - log_dir, DefaultLogDir(), - "If specified, logfiles are written into this directory instead " - "of the default logging directory."); -GLOG_DEFINE_string(log_link, "", - "Put additional links to the log " - "files in this directory"); - -GLOG_DEFINE_uint32(max_log_size, 1800, - "approx. maximum log file size (in MB). A value of 0 will " - "be silently overridden to 1."); - -GLOG_DEFINE_bool(stop_logging_if_full_disk, false, - "Stop attempting to log to disk if the disk is full."); - -GLOG_DEFINE_string(log_backtrace_at, "", - "Emit a backtrace when logging at file:linenum."); - -GLOG_DEFINE_bool(log_utc_time, false, "Use UTC time for logging."); - // TODO(hamaji): consider windows enum { PATH_SEPARATOR = '/' }; diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index c1d117225..868716cf3 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -63,8 +63,6 @@ #include "glog/raw_logging.h" #include "googletest.h" -DECLARE_string(log_backtrace_at); // logging.cc - #ifdef GLOG_USE_GFLAGS # include using namespace GFLAGS_NAMESPACE; diff --git a/src/utilities.cc b/src/utilities.cc index b736d5285..4b1f5e0ba 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -80,9 +80,6 @@ bool IsGoogleLoggingInitialized() { # include "stacktrace.h" # include "symbolize.h" -GLOG_DEFINE_bool(symbolize_stacktrace, true, - "Symbolize the stack trace in the tombstone"); - namespace google { using DebugWriter = void(const char*, void*); diff --git a/src/vlog_is_on.cc b/src/vlog_is_on.cc index 4c4974a05..24044259d 100644 --- a/src/vlog_is_on.cc +++ b/src/vlog_is_on.cc @@ -39,8 +39,6 @@ #include #include -#include "base/commandlineflags.h" -#include "base/googleinit.h" #include "glog/logging.h" #include "glog/raw_logging.h" #include "utilities.h" @@ -50,18 +48,6 @@ using std::string; -GLOG_DEFINE_int32(v, 0, - "Show all VLOG(m) messages for m <= this." - " Overridable by --vmodule."); - -GLOG_DEFINE_string( - vmodule, "", - "per-module verbose level." - " Argument is a comma-separated list of =." - " is a glob pattern, matched against the filename base" - " (that is, name ignoring .cc/.h./-inl.h)." - " overrides any value given by --v."); - namespace google { namespace glog_internal_namespace_ {