Compare commits

...

19 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
6d92a2e5a1
bump version patch 2024-08-02 21:53:11 +02:00
Sergiu Deitsch
6703865b78
Merge branch '0.7.x' 2024-08-02 21:47:32 +02:00
Shuai Zhang
175b54d4fa
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:57:43 +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
15 changed files with 109 additions and 57 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

@ -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)

View File

@ -5,3 +5,9 @@ module(
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

@ -91,12 +91,14 @@ def glog_library(with_gflags = 1, **kwargs):
# Enable declaration of _Unwind_Backtrace
"-D_GNU_SOURCE",
"-DHAVE_LINK_H",
"-DHAVE_SYMBOLIZE", # Supported by <link.h>
]
linux_only_copts = [
# For utilities.h.
"-DHAVE_EXECINFO_H",
"-DHAVE_LINK_H",
"-DHAVE_SYMBOLIZE", # Supported by <link.h>
]
darwin_only_copts = [

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 = "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

@ -1419,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

View File

@ -995,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;

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 ");

View File

@ -77,6 +77,10 @@
# error "symbolize.h" was not included correctly.
#endif
// We prefer to let the build system detect the availability of certain features
// such as symbolization support. HAVE_SYMBOLIZE should therefore be defined by
// the build system in general unless there is a good reason to perform the
// detection using the preprocessor.
#ifndef GLOG_NO_SYMBOLIZE_DETECTION
# ifndef HAVE_SYMBOLIZE
// defined by gcc