Compare commits

...

32 Commits

Author SHA1 Message Date
Ahmed Hani
4f007d9621
fix: truncate single log file upon reopening (#1143) 2025-02-20 17:49:33 +01:00
stdpain
7fcf58afa6
feat(signalhandler): add LWP ID to dump info (#1146)
LWP can help identifying the corresponding thread in a debugger more easily.
2025-02-16 15:51:26 +01:00
Rodrigo Queiro
ca390c4718
Revert "Add deprecation notice (#1150)" (#1152)
This reverts commit 575fb19092.
2025-02-04 10:05:23 +01:00
Rodrigo Queiro
575fb19092
Add deprecation notice (#1150) 2025-02-04 12:59:45 +09:00
dependabot[bot]
6c5c692c8e
build(deps): bump codecov/codecov-action from 4 to 5 (#1140)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-18 18:01:35 +01:00
Takeshi Watanabe
1f0f3d6829
fix(cmake): enable symbolization on macOS (#1138) 2024-11-05 16:22:00 +01:00
Rodrigo Queiro
2075ae813b
Migrate to rules_cc (#1136)
See #1135. Not sure if this will work because the error only repros on
Windows with a specific Bazel version.
2024-10-16 10:08:53 +02:00
Sergiu Deitsch
de309c08c0
fix(clang-tidy): remove deprecated option (#1132) 2024-09-14 13:08:24 +02:00
Yun Peng
be06647ac2
fix(bazel): specify dependencies in MODULE.bazel (#1131)
With WORKSPACE disabled, all dependencies must be specified in MODULE.bazel.
2024-09-14 12:35:18 +02:00
kang jinci
b3b9eb987f
chore: add MODULE.bazel.lock to .gitignore (#1120) 2024-08-03 09:45:25 +02:00
Sergiu Deitsch
2714c2a258
Merge branch '0.7.x' 2024-08-02 21:54:14 +02:00
Sergiu Deitsch
6703865b78
Merge branch '0.7.x' 2024-08-02 21:47:32 +02:00
Shuai Zhang
65896fe00d
feat(bazel): enable symbolization (#1116)
Symbolization support on Linux and BSD requires link.h which is usually
provided by the GNU C Library (glibc). Assume the header to be present
at all times by unconditionally defining HAVE_SYMBOLIZE on the
corresponding platforms.
2024-08-02 20:38:49 +02:00
Vertexwahn
570c7e4e1d
docs: update to Bzlmod usage (#1099) 2024-07-07 13:54:19 +02:00
Sergiu Deitsch
45f99f5e1a
make operator<< overload constexpr (#1106) 2024-06-13 23:01:34 +02:00
Sergiu Deitsch
2bd06dbe36
ci(deps): update to gtest 1.14 (#1105) 2024-06-13 01:40:15 +02:00
Sergiu Deitsch
409e19881d
cmake: require gtest 1.11 (#1104) 2024-06-13 01:16:50 +02:00
Sergiu Deitsch
0c10a02229
Merge branch '0.7.x' 2024-06-13 00:01:17 +02:00
Sergiu Deitsch
44c2e9d9ad
Merge branch '0.7.x' 2024-06-12 01:20:27 +02:00
Sergiu Deitsch
1cd4d78817
Merge branch '0.7.x' 2024-06-11 20:13:53 +02:00
Sergiu Deitsch
30c9ed3687
docs: update version 2024-06-11 19:57:05 +02:00
Sergiu Deitsch
cfe648e9c5
docs: move to mkdocs-material (#1101) 2024-06-11 19:48:12 +02:00
Sergiu Deitsch
cc0de6c200
Merge branch '0.7.x' 2024-06-08 17:11:26 +02:00
Vertexwahn
d76999015c
feat(bazel): port to bzlmod (#1097) 2024-06-08 16:02:59 +02:00
xppt
cd4ef77d58
fix(symbolize): format unknown stack frames (#1092) 2024-04-22 21:08:44 +02:00
dependabot[bot]
c0813f90bb
build(deps): bump codecov/codecov-action from 3 to 4 (#1071)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-22 13:40:27 +02:00
Sergiu Deitsch
2b36dfe444
fix: rework android detection (#1094) 2024-04-22 00:47:36 +02:00
Victor Zheng PhD
31429d85b8
fix(bazel): add missing emscripten defines (#1082) 2024-03-11 11:20:22 +01:00
Sergiu Deitsch
ea0748d8df
feat: remove deprecations (#1078) 2024-02-21 18:56:43 +01:00
Sergiu Deitsch
5a7856ab96
fix: error message typo 2024-02-19 20:08:00 +01:00
Ram Subhash D
8a1c086d39
fix(readme): correct LOG_IF_EVERY_N typo (#1077) 2024-02-19 20:07:33 +01:00
Sergiu Deitsch
a189fc3d7d
fix(readme): wording 2024-02-18 13:24:53 +01:00
22 changed files with 123 additions and 281 deletions

View File

@ -2,7 +2,6 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*,modernize-*,-modernize-use-trailing-return-type,readability-*,portability-*,performance-*,bugprone-*,android-*,darwin-*,clang-analyzer-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
- key: cert-dcl16-c.NewSuffixes

View File

@ -31,42 +31,20 @@ jobs:
- name: Setup Dependencies
run: |
sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
build-essential \
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-suggests --no-install-recommends \
g++ \
cmake \
gcovr \
libgflags-dev \
libgmock-dev \
libgtest-dev \
libunwind-dev \
ninja-build
- name: Cache GTest
id: cache-gtest
uses: actions/cache@v4
with:
path: gtest/
key: ${{runner.os}}-gtest-1.11
- name: Download GTest
if: steps.cache-gtest.outputs.cache-hit != 'true'
run: |
wget https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz
tar xvf release-1.11.0.tar.gz
- name: Build GTest
if: steps.cache-gtest.outputs.cache-hit != 'true'
run: |
cmake -S googletest-release-1.11.0 -B build-googletest \
-DBUILD_SHARED_LIBS=${{matrix.shared}} \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/gtest \
-G Ninja
cmake --build build-googletest --target install
- name: Setup Environment
if: matrix.build_type == 'Debug'
run: |
echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV
echo 'GTest_ROOT=${{github.workspace}}/gtest' >> $GITHUB_ENV
- name: Configure
env:
@ -131,7 +109,7 @@ jobs:
- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build_${{matrix.build_type}}/coverage.xml

View File

@ -68,7 +68,7 @@ jobs:
- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build_${{matrix.build_type}}/coverage.xml

View File

@ -45,18 +45,18 @@ jobs:
uses: actions/cache@v4
with:
path: gtest/
key: ${{runner.os}}-gtest-1.11-${{matrix.lib}}-${{matrix.arch}}-${{matrix.build_type}}
key: ${{runner.os}}-gtest-1.14-${{matrix.lib}}-${{matrix.arch}}-${{matrix.build_type}}
- name: Download GTest
if: steps.cache-gtest.outputs.cache-hit != 'true'
run: |
(New-Object System.Net.WebClient).DownloadFile("https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip", "release-1.11.0.zip")
Expand-Archive release-1.11.0.zip .
(New-Object System.Net.WebClient).DownloadFile("https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip", "v1.14.0.zip")
Expand-Archive v1.14.0.zip .
- name: Build GTest
if: steps.cache-gtest.outputs.cache-hit != 'true'
run: |
cmake -S googletest-release-1.11.0 -B build-googletest `
cmake -S googletest-1.14.0 -B build-googletest `
-A ${{matrix.arch}} `
-DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} `
-Dgtest_force_shared_crt=ON `
@ -234,7 +234,7 @@ jobs:
- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build_${{matrix.build_type}}/coverage.xml

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
/build*/
/site/
bazel-*
# Bzlmod lockfile
/MODULE.bazel.lock

View File

@ -17,6 +17,6 @@ platform(
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
"@rules_cc//cc/private/toolchain:clang-cl",
],
)

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.22)
project (glog
VERSION 0.7.2
VERSION 0.8.0
DESCRIPTION "C++ implementation of the Google logging module"
HOMEPAGE_URL https://github.com/google/glog
LANGUAGES CXX
@ -64,7 +64,7 @@ set (CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set (CMAKE_DEBUG_POSTFIX d)
find_package (GTest NO_MODULE)
find_package (GTest 1.11 COMPONENTS GTest OPTIONAL_COMPONENTS GMock NO_MODULE)
if (GTest_FOUND)
set (HAVE_LIB_GTEST 1)
@ -278,12 +278,12 @@ if (WITH_SYMBOLIZE)
if (HAVE_SYMBOLIZE)
set (HAVE_STACKTRACE 1)
endif (HAVE_SYMBOLIZE)
elseif (APPLE AND HAVE_DLADDR)
set (HAVE_SYMBOLIZE 1)
elseif (UNIX)
if (HAVE_ELF_H OR HAVE_SYS_EXEC_ELF_H)
set (HAVE_SYMBOLIZE 1)
endif (HAVE_ELF_H OR HAVE_SYS_EXEC_ELF_H)
elseif (APPLE AND HAVE_DLADDR)
set (HAVE_SYMBOLIZE 1)
endif (WIN32 OR CYGWIN)
endif (WITH_SYMBOLIZE)
@ -467,7 +467,7 @@ if (ANDROID)
endif (ANDROID)
set_target_properties (glog PROPERTIES VERSION ${glog_VERSION})
set_target_properties (glog PROPERTIES SOVERSION 2)
set_target_properties (glog PROPERTIES SOVERSION 3)
if (CYGWIN OR WIN32)
target_compile_definitions (glog PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES)

View File

@ -3,4 +3,11 @@ module(
compatibility_level = 1,
)
bazel_dep(name = "gflags", version = "2.2.2", repo_name = "com_github_gflags_gflags")
bazel_dep(name = "gflags", version = "2.2.2")
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.0.12")
# Required for Windows clang-cl build: --extra_toolchains=@local_config_cc//:cc-toolchain-arm64_windows
cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc")

View File

@ -1,18 +0,0 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = [
"https://mirror.bazel.build/github.com/gflags/gflags/archive/v2.2.2.tar.gz",
"https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
],
)
http_archive(
name = "com_github_google_googletest",
sha256 = "258f33ab1a8ee17adf48ec65e821d0ea9eafcbedeff6110f9eaed78472e73dde",
strip_prefix = "googletest-15460959cbbfa20e66ef0b5ab497367e47fc0a04",
urls = ["https://github.com/google/googletest/archive/15460959cbbfa20e66ef0b5ab497367e47fc0a04.tar.gz"],
)

1
WORKSPACE.bazel Normal file
View File

@ -0,0 +1 @@
# WORKSPACE marker file needed by Bazel

View File

@ -4,6 +4,6 @@ cc_test(
srcs = ["main.cc"],
deps = [
"//:glog",
"@com_github_gflags_gflags//:gflags",
"@gflags//:gflags",
],
)

View File

@ -128,7 +128,7 @@ def glog_library(with_gflags = 1, **kwargs):
"src/windows/port.h",
]
gflags_deps = ["@com_github_gflags_gflags//:gflags"] if with_gflags else []
gflags_deps = ["@gflags//:gflags"] if with_gflags else []
final_lib_defines = select({
# GLOG_EXPORT is normally set by export.h, but that's not
@ -261,7 +261,7 @@ def glog_library(with_gflags = 1, **kwargs):
copts = final_lib_copts + test_only_copts,
deps = gflags_deps + [
":glog",
"@com_github_google_googletest//:gtest",
"@googletest//:gtest",
],
**kwargs
)

View File

@ -3,27 +3,20 @@
## Bazel
To use glog within a project which uses the [Bazel](https://bazel.build/) build
tool, add the following lines to your `WORKSPACE` file:
tool, add the following lines to your `MODULE.bazel` file:
``` bazel title="WORKSPACE"
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
``` bazel title="MODULE.bazel"
bazel_dep(name = "glog")
http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = ["https://github.com/gflags/gflags/archive/v2.2.2.tar.gz"],
)
http_archive(
name = "com_github_google_glog",
sha256 = "c17d85c03ad9630006ef32c7be7c65656aba2e7e2fbfc82226b7e680c771fc88",
strip_prefix = "glog-0.7.1",
urls = ["https://github.com/google/glog/archive/v0.7.1.zip"],
archive_override(
module_name = "glog",
urls = "https://github.com/google/glog/archive/cc0de6c200375b33d907ee7632eee2f173b33a09.tar.gz",
strip_prefix = "glog-cc0de6c200375b33d907ee7632eee2f173b33a09", # Latest commit as of 2024-06-08.
integrity = "sha256-rUrv4EBkdc+4Wbhfxp+KoRstlj2Iw842/OpLfDq0ivg=",
)
```
You can then add `@com_github_google_glog//:glog` to
You can then add `@glog//:glog` to
the deps section of a `cc_binary` or
`cc_library` rule, and `#!cpp #include <glog/logging.h>` to
include it in your source code.
@ -33,7 +26,7 @@ include it in your source code.
cc_binary(
name = "main",
srcs = ["main.cc"],
deps = ["@com_github_google_glog//:glog"],
deps = ["@glog//:glog"],
)
```

View File

@ -24,8 +24,8 @@ don't need to do it again.
Once your CLA is submitted (or if you already submitted one for another Google
project), make a commit adding yourself to the
[AUTHORS](https://github.com/google/glog/blob/0.7.x/AUTHORS) and
[CONTRIBUTORS](https://github.com/google/glog/blob/0.7.x/CONTRIBUTORS) files.
[AUTHORS](https://github.com/google/glog/blob/master/AUTHORS) and
[CONTRIBUTORS](https://github.com/google/glog/blob/master/CONTRIBUTORS) files.
This commit can be part of your first [pull
request](https://help.github.com/articles/creating-a-pull-request).

View File

@ -69,7 +69,7 @@ The following flags are most commonly used:
logging](logging.md#verbose-logging) for more details.
Additional flags are defined in
[flags.cc](https://github.com/google/glog/blob/0.7.x/src/flags.cc). Please see
[flags.cc](https://github.com/google/glog/blob/master/src/flags.cc). Please see
the source for their complete list.
## Modifying Flags Programmatically

View File

@ -397,7 +397,7 @@ The header file `<glog/raw_logging.h>` can be used for thread-safe logging,
which does not allocate any memory or acquire any locks. Therefore, the macros
defined in this header file can be used by low-level memory allocation and
synchronization code. Please check
[src/glog/raw_logging.h](https://github.com/google/glog/blob/0.7.x/src/glog/raw_logging.h)
[src/glog/raw_logging.h](https://github.com/google/glog/blob/master/src/glog/raw_logging.h)
for detail.
## Google Style `perror()`

View File

@ -8,7 +8,7 @@ find_package` to build against glog in your CMake project as follows:
cmake_minimum_required (VERSION 3.16)
project (myproj VERSION 1.0)
find_package (glog 0.7.2 REQUIRED)
find_package (glog 0.8.0 REQUIRED)
add_executable (myapp main.cpp)
target_link_libraries (myapp glog::glog)

View File

@ -3,7 +3,7 @@ site_name: Google Logging Library
site_url: https://google.github.io/glog/
repo_url: https://github.com/google/glog
repo_name: google/glog
edit_uri: edit/0.7.x/docs/
edit_uri: edit/master/docs/
copyright: Copyright &copy; 2024 Google Inc. &amp; contributors - <a href="#__consent">Change cookie settings</a>
markdown_extensions:
- admonition
@ -81,7 +81,7 @@ plugins:
enable_creation_date: true
- git-committers:
repository: google/glog
branch: 0.7.x
branch: master
- privacy
- search
- tags

View File

@ -83,10 +83,6 @@ struct GLOG_EXPORT LogMessageTime {
LogMessageTime();
explicit LogMessageTime(std::chrono::system_clock::time_point now);
[[deprecated("Use LogMessageTime::when() instead.")]] std::time_t timestamp()
const noexcept {
return std::chrono::system_clock::to_time_t(when());
}
const std::chrono::system_clock::time_point& when() const noexcept {
return timestamp_;
}
@ -100,10 +96,6 @@ struct GLOG_EXPORT LogMessageTime {
int dayOfWeek() const noexcept { return tm_.tm_wday; }
int dayInYear() const noexcept { return tm_.tm_yday; }
int dst() const noexcept { return tm_.tm_isdst; }
[[deprecated("Use LogMessageTime::gmtoffset() instead.")]] long gmtoff()
const noexcept {
return gmtoffset_.count();
}
std::chrono::seconds gmtoffset() const noexcept { return gmtoffset_; }
const std::tm& tm() const noexcept { return tm_; }
@ -115,24 +107,6 @@ struct GLOG_EXPORT LogMessageTime {
std::chrono::seconds gmtoffset_;
};
struct [[deprecated("Use LogMessage instead.")]] LogMessageInfo {
explicit LogMessageInfo(const char* const severity_,
const char* const filename_, const int& line_number_,
std::thread::id thread_id_,
const LogMessageTime& time_)
: severity(severity_),
filename(filename_),
line_number(line_number_),
thread_id(thread_id_),
time(time_) {}
const char* const severity;
const char* const filename;
const int& line_number;
std::thread::id thread_id;
const LogMessageTime& time;
};
} // namespace google
// The global value of GOOGLE_STRIP_LOG. All the messages logged to
@ -482,27 +456,6 @@ namespace google {
// specified by argv0 in log outputs.
GLOG_EXPORT void InitGoogleLogging(const char* argv0);
class LogMessage;
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
using CustomPrefixCallback
[[deprecated("Use PrefixFormatterCallback instead.")]] =
void (*)(std::ostream&, const LogMessageInfo&, void*);
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
[[deprecated("Use InstallPrefixFormatter instead.")]] GLOG_EXPORT void
InitGoogleLogging(const char* argv0, CustomPrefixCallback prefix_callback,
void* prefix_callback_data = nullptr);
// Check if google's logging library has been initialized.
GLOG_EXPORT bool IsGoogleLoggingInitialized();
@ -515,6 +468,8 @@ typedef void (*logging_fail_func_t)() __attribute__((noreturn));
typedef void (*logging_fail_func_t)();
#endif
class LogMessage;
using PrefixFormatterCallback = void (*)(std::ostream&, const LogMessage&,
void*);
@ -526,10 +481,6 @@ GLOG_EXPORT void InstallPrefixFormatter(PrefixFormatterCallback callback,
GLOG_EXPORT logging_fail_func_t
InstallFailureFunction(logging_fail_func_t fail_func);
[[deprecated(
"Use the type-safe std::chrono::minutes EnableLogCleaner overload "
"instead.")]] GLOG_EXPORT void
EnableLogCleaner(unsigned int overdue_days);
// Enable/Disable old log cleaner.
GLOG_EXPORT void EnableLogCleaner(const std::chrono::minutes& overdue);
GLOG_EXPORT void DisableLogCleaner();
@ -1361,11 +1312,6 @@ class GLOG_EXPORT LogMessage {
// Must be called without the log_mutex held. (L < log_mutex)
static int64 num_messages(int severity);
[[deprecated("Use LogMessage::time() instead.")]] const LogMessageTime&
getLogMessageTime() const {
return time();
}
LogSeverity severity() const noexcept;
int line() const noexcept;
const std::thread::id& thread_id() const noexcept;
@ -1473,7 +1419,7 @@ T CheckNotNull(const char* file, int line, const char* names, T&& t) {
struct LogMessageVoidify {
// This has to be an operator with a precedence lower than << but
// higher than ?:
void operator&(std::ostream&) noexcept {}
constexpr void operator&(std::ostream&) const noexcept {}
};
} // namespace internal
@ -1520,12 +1466,7 @@ class GLOG_EXPORT LogSink {
virtual void send(LogSeverity severity, const char* full_filename,
const char* base_filename, int line,
const LogMessageTime& time, const char* message,
size_t message_len);
// Provide an overload for compatibility purposes
GLOG_DEPRECATED
virtual void send(LogSeverity severity, const char* full_filename,
const char* base_filename, int line, const std::tm* t,
const char* message, size_t message_len);
size_t message_len) = 0;
// Redefine this to implement waiting for
// the sink's logging logic to complete.
@ -1637,15 +1578,9 @@ class GLOG_EXPORT Logger {
// appropriate by the higher level logging facility. For example,
// textual log messages already contain timestamps, and the
// file:linenumber header.
[[deprecated(
"Logger::Write accepting a std::time_t timestamp is provided for "
"compatibility purposes only. New code should implement the "
"std::chrono::system_clock::time_point overload.")]] virtual void
Write(bool force_flush, time_t timestamp, const char* message,
size_t message_len);
virtual void Write(bool force_flush,
const std::chrono::system_clock::time_point& timestamp,
const char* message, size_t message_len);
const char* message, size_t message_len) = 0;
// Flush any buffered messages
virtual void Flush() = 0;

View File

@ -342,28 +342,6 @@ static bool SendEmailInternal(const char* dest, const char* subject,
base::Logger::~Logger() = default;
void base::Logger::Write(bool /*force_flush*/, time_t /*timestamp*/,
const char* /*message*/, size_t /*message_len*/) {}
void base::Logger::Write(bool force_flush,
const std::chrono::system_clock::time_point& timestamp,
const char* message, size_t message_len) {
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
return Write(force_flush, std::chrono::system_clock::to_time_t(timestamp),
message, message_len);
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
}
namespace {
constexpr std::intmax_t kSecondsInDay = 60 * 60 * 24;
@ -372,44 +350,11 @@ constexpr std::intmax_t kSecondsInWeek = kSecondsInDay * 7;
// Optional user-configured callback to print custom prefixes.
class PrefixFormatter {
public:
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
PrefixFormatter(CustomPrefixCallback callback, void* data) noexcept
: version{V1}, callback_v1{callback}, data{data} {}
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
PrefixFormatter(PrefixFormatterCallback callback, void* data) noexcept
: version{V2}, callback_v2{callback}, data{data} {}
void operator()(std::ostream& s, const LogMessage& message) const {
switch (version) {
case V1:
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
callback_v1(s,
LogMessageInfo(LogSeverityNames[message.severity()],
message.basename(), message.line(),
message.thread_id(), message.time()),
data);
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
break;
case V2:
callback_v2(s, message, data);
break;
@ -420,21 +365,8 @@ class PrefixFormatter {
PrefixFormatter& operator=(const PrefixFormatter& other) = delete;
private:
enum Version { V1, V2 } version;
enum Version { V2 } version;
union {
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
CustomPrefixCallback callback_v1;
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
PrefixFormatterCallback callback_v2;
};
// User-provided data to pass to the callback:
@ -1063,7 +995,22 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) {
if (FLAGS_timestamp_in_logfile_name) {
// demand that the file is unique for our timestamp (fail if it exists).
flags = flags | O_EXCL;
} else {
// logs are written to a single file, where: a log file is created for the
// the first time or a file is being recreated due to exceeding max size
struct stat statbuf;
if (stat(filename, &statbuf) == 0) {
// truncate the file if it exceeds the max size
if ((static_cast<uint32>(statbuf.st_size) >> 20U) >= MaxLogSize()) {
flags |= O_TRUNC;
}
// update file length to sync file size
file_length_ = static_cast<uint32>(statbuf.st_size);
}
}
FileDescriptor fd{
open(filename, flags, static_cast<mode_t>(FLAGS_logfile_mode))};
if (!fd) return false;
@ -2081,38 +2028,6 @@ void SetLogSymlink(LogSeverity severity, const char* symlink_basename) {
LogSink::~LogSink() = default;
void LogSink::send(LogSeverity severity, const char* full_filename,
const char* base_filename, int line,
const LogMessageTime& time, const char* message,
size_t message_len) {
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
send(severity, full_filename, base_filename, line, &time.tm(), message,
message_len);
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
}
void LogSink::send(LogSeverity severity, const char* full_filename,
const char* base_filename, int line, const std::tm* t,
const char* message, size_t message_len) {
(void)severity;
(void)full_filename;
(void)base_filename;
(void)line;
(void)t;
(void)message;
(void)message_len;
}
void LogSink::WaitTillSent() {
// noop default
}
@ -2702,29 +2617,6 @@ void MakeCheckOpValueString(std::ostream* os, const std::nullptr_t& /*v*/) {
void InitGoogleLogging(const char* argv0) { InitGoogleLoggingUtilities(argv0); }
#if defined(__GNUG__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
#endif // __GNUG__
void InitGoogleLogging(const char* argv0, CustomPrefixCallback prefix_callback,
void* prefix_callback_data) {
if (prefix_callback != nullptr) {
g_prefix_formatter = std::make_unique<PrefixFormatter>(
prefix_callback, prefix_callback_data);
} else {
g_prefix_formatter = nullptr;
}
InitGoogleLogging(argv0);
}
#if defined(__GNUG__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif // __GNUG__
void InstallPrefixFormatter(PrefixFormatterCallback callback, void* data) {
if (callback != nullptr) {
g_prefix_formatter = std::make_unique<PrefixFormatter>(callback, data);

View File

@ -110,6 +110,7 @@ static void TestLogSinkWaitTillSent();
static void TestCHECK();
static void TestDCHECK();
static void TestSTREQ();
static void TestMaxLogSizeWhenNoTimestamp();
static void TestBasename();
static void TestBasenameAppendWhenNoTimestamp();
static void TestTwoProcessesWrite();
@ -288,6 +289,7 @@ int main(int argc, char** argv) {
MungeAndDiffTestStdout(FLAGS_test_srcdir + "/src/logging_unittest.out"));
FLAGS_logtostdout = false;
TestMaxLogSizeWhenNoTimestamp();
TestBasename();
TestBasenameAppendWhenNoTimestamp();
TestTwoProcessesWrite();
@ -806,6 +808,47 @@ static void CheckFile(const string& name, const string& expected_string,
<< expected_string << " in " << files[0];
}
static void TestMaxLogSizeWhenNoTimestamp() {
fprintf(stderr, "==== Test setting max log size without timestamp\n");
const string dest = FLAGS_test_tmpdir + "/logging_test_max_log_size";
DeleteFiles(dest + "*");
auto original_max_log_size = FLAGS_max_log_size;
auto original_timestamp_in_logfile_name = FLAGS_timestamp_in_logfile_name;
FLAGS_max_log_size = 1; // Set max log size to 1MB
FLAGS_timestamp_in_logfile_name = false;
// Set log destination
SetLogDestination(GLOG_INFO, dest.c_str());
// 1e4 info logs -> is about 772 KB in size
// 2e4 info logs -> is around 1500 KB in size -> 1.5MB
// If our max_log_size constraint is respected, it will truncate earlier logs
// and the file size will be lesser than 1MB (around 0.5MB)
const int num_logs = 2e4;
for (int i = 0; i < num_logs; i++) {
LOG(INFO) << "Hello world";
}
FlushLogFiles(GLOG_INFO);
// Check log file size
struct stat statbuf;
stat(dest.c_str(), &statbuf);
// Verify file size is less than the max log size limit
CHECK_LT(static_cast<unsigned int>(statbuf.st_size),
FLAGS_max_log_size << 20U);
// Reset flag values to their original values
FLAGS_max_log_size = original_max_log_size;
FLAGS_timestamp_in_logfile_name = original_timestamp_in_logfile_name;
// Release file handle for the destination file to unlock the file in Windows.
LogToStderr();
DeleteFiles(dest + "*");
}
static void TestBasename() {
fprintf(stderr, "==== Test setting log file basename\n");
const string dest = FLAGS_test_tmpdir + "/logging_test_basename";

View File

@ -55,6 +55,10 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_SYS_TYPES_H)
# include <sys/syscall.h>
# include <sys/types.h>
#endif
namespace google {
@ -216,8 +220,14 @@ void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
std::ostringstream oss;
oss << std::showbase << std::hex << std::this_thread::get_id();
formatter.AppendString(oss.str().c_str());
# if defined(GLOG_OS_LINUX) && defined(HAVE_SYS_SYSCALL_H) && \
defined(HAVE_SYS_TYPES_H)
pid_t tid = syscall(SYS_gettid);
formatter.AppendString(" LWP ");
formatter.AppendUint64(static_cast<uint64>(tid), 10);
# endif
formatter.AppendString(") ");
// Only linux has the PID of the signal sender in si_pid.
# ifdef GLOG_OS_LINUX
formatter.AppendString("from PID ");