Compare commits
No commits in common. "master" and "v0.6.0-rc1" have entirely different histories.
master
...
v0.6.0-rc1
@ -1,8 +1,6 @@
|
|||||||
---
|
---
|
||||||
tasks:
|
platforms:
|
||||||
ubuntu1804:
|
ubuntu1804:
|
||||||
name: "Ubuntu 22.04"
|
|
||||||
platform: ubuntu2204
|
|
||||||
build_flags:
|
build_flags:
|
||||||
- "--features=layering_check"
|
- "--features=layering_check"
|
||||||
- "--copt=-Werror"
|
- "--copt=-Werror"
|
||||||
@ -14,8 +12,6 @@ tasks:
|
|||||||
test_targets:
|
test_targets:
|
||||||
- "//..."
|
- "//..."
|
||||||
macos:
|
macos:
|
||||||
name: "macOS: latest Xcode"
|
|
||||||
platform: macos
|
|
||||||
build_flags:
|
build_flags:
|
||||||
- "--features=layering_check"
|
- "--features=layering_check"
|
||||||
- "--copt=-Werror"
|
- "--copt=-Werror"
|
||||||
@ -26,9 +22,8 @@ tasks:
|
|||||||
- "--copt=-Werror"
|
- "--copt=-Werror"
|
||||||
test_targets:
|
test_targets:
|
||||||
- "//..."
|
- "//..."
|
||||||
windows-msvc:
|
windows:
|
||||||
name: "Windows: MSVC 2017"
|
# Optional: use VS 2017 instead of 2015.
|
||||||
platform: windows
|
|
||||||
environment:
|
environment:
|
||||||
BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC"
|
BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC"
|
||||||
build_flags:
|
build_flags:
|
||||||
@ -41,22 +36,3 @@ tasks:
|
|||||||
- "--copt=/WX"
|
- "--copt=/WX"
|
||||||
test_targets:
|
test_targets:
|
||||||
- "//..."
|
- "//..."
|
||||||
windows-clang-cl:
|
|
||||||
name: "Windows: Clang"
|
|
||||||
platform: windows
|
|
||||||
environment:
|
|
||||||
BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC"
|
|
||||||
build_flags:
|
|
||||||
- "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"
|
|
||||||
- "--extra_execution_platforms=//:x64_windows-clang-cl"
|
|
||||||
- "--compiler=clang-cl"
|
|
||||||
- "--features=layering_check"
|
|
||||||
build_targets:
|
|
||||||
- "//..."
|
|
||||||
test_flags:
|
|
||||||
- "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"
|
|
||||||
- "--extra_execution_platforms=//:x64_windows-clang-cl"
|
|
||||||
- "--compiler=clang-cl"
|
|
||||||
- "--features=layering_check"
|
|
||||||
test_targets:
|
|
||||||
- "//..."
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ ConstructorInitializerIndentWidth: 4
|
|||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
DeriveLineEnding: true
|
DeriveLineEnding: true
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: true
|
||||||
DisableFormat: false
|
DisableFormat: false
|
||||||
ExperimentalAutoDetectBinPacking: false
|
ExperimentalAutoDetectBinPacking: false
|
||||||
FixNamespaceComments: true
|
FixNamespaceComments: true
|
||||||
@ -84,7 +84,7 @@ IncludeIsMainRegex: '([-_](test|unittest))?$'
|
|||||||
IncludeIsMainSourceRegex: ''
|
IncludeIsMainSourceRegex: ''
|
||||||
IndentCaseLabels: true
|
IndentCaseLabels: true
|
||||||
IndentGotoLabels: true
|
IndentGotoLabels: true
|
||||||
IndentPPDirectives: AfterHash
|
IndentPPDirectives: None
|
||||||
IndentWidth: 2
|
IndentWidth: 2
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
JavaScriptQuotes: Leave
|
JavaScriptQuotes: Leave
|
||||||
@ -157,7 +157,7 @@ SpacesInCStyleCastParentheses: false
|
|||||||
SpacesInParentheses: false
|
SpacesInParentheses: false
|
||||||
SpacesInSquareBrackets: false
|
SpacesInSquareBrackets: false
|
||||||
SpaceBeforeSquareBrackets: false
|
SpaceBeforeSquareBrackets: false
|
||||||
Standard: c++14
|
Standard: Auto
|
||||||
StatementMacros:
|
StatementMacros:
|
||||||
- Q_UNUSED
|
- Q_UNUSED
|
||||||
- QT_REQUIRE_VERSION
|
- QT_REQUIRE_VERSION
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*,modernize-*,-modernize-use-trailing-return-type,readability-*,portability-*,performance-*,bugprone-*,android-*,darwin-*,clang-analyzer-*'
|
Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*'
|
||||||
WarningsAsErrors: ''
|
WarningsAsErrors: ''
|
||||||
HeaderFilterRegex: ''
|
HeaderFilterRegex: ''
|
||||||
|
AnalyzeTemporaryDtors: false
|
||||||
FormatStyle: file
|
FormatStyle: file
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: cert-dcl16-c.NewSuffixes
|
- key: cert-dcl16-c.NewSuffixes
|
||||||
|
|||||||
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@ -1,10 +0,0 @@
|
|||||||
# Set update schedule for GitHub Actions
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
# Check for updates to GitHub Actions every week
|
|
||||||
interval: "weekly"
|
|
||||||
44
.github/workflows/android.yml
vendored
44
.github/workflows/android.yml
vendored
@ -5,58 +5,43 @@ on: [push, pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
build-android:
|
build-android:
|
||||||
name: NDK-C++${{matrix.std}}-${{matrix.abi}}-${{matrix.build_type}}
|
name: NDK-C++${{matrix.std}}-${{matrix.abi}}-${{matrix.build_type}}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
NDK_VERSION: 26.0.10792818
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
std: [14, 17, 20]
|
std: [98, 11, 14, 17, 20]
|
||||||
abi: [arm64-v8a, armeabi-v7a, x86_64, x86]
|
abi: [arm64-v8a, armeabi-v7a, x86_64, x86]
|
||||||
build_type: [Debug, Release]
|
build_type: [Debug, Release]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Setup Ninja
|
||||||
uses: github/codeql-action/init@v3
|
uses: ashutoshvarma/setup-ninja@master
|
||||||
with:
|
with:
|
||||||
languages: cpp
|
version: 1.10.0
|
||||||
|
|
||||||
- name: Setup Dependencies
|
- name: Setup C++98 Environment
|
||||||
|
if: matrix.std == '98'
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV
|
||||||
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
|
|
||||||
cmake \
|
|
||||||
ninja-build
|
|
||||||
|
|
||||||
- name: Setup NDK
|
|
||||||
env:
|
|
||||||
ANDROID_SDK_ROOT: /usr/local/lib/android/sdk
|
|
||||||
run: |
|
|
||||||
echo 'y' | ${{env.ANDROID_SDK_ROOT}}/cmdline-tools/latest/bin/sdkmanager --install 'ndk;${{env.NDK_VERSION}}'
|
|
||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
env:
|
env:
|
||||||
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
|
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build_${{matrix.abi}} \
|
cmake -S . -B build_${{matrix.abi}} \
|
||||||
-DCMAKE_ANDROID_API=28 \
|
-DANDROID_ABI=${{matrix.abi}} \
|
||||||
-DCMAKE_ANDROID_ARCH_ABI=${{matrix.abi}} \
|
-DANDROID_NATIVE_API_LEVEL=28 \
|
||||||
-DCMAKE_ANDROID_NDK=/usr/local/lib/android/sdk/ndk/${{env.NDK_VERSION}} \
|
-DANDROID_STL=c++_shared \
|
||||||
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
|
|
||||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||||
-DCMAKE_CXX_EXTENSIONS=OFF \
|
-DCMAKE_CXX_EXTENSIONS=OFF \
|
||||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||||
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
||||||
-DCMAKE_SYSTEM_NAME=Android \
|
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
|
||||||
-G Ninja \
|
-G Ninja \
|
||||||
-Werror
|
-Werror
|
||||||
|
|
||||||
@ -64,6 +49,3 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cmake --build build_${{matrix.abi}} \
|
cmake --build build_${{matrix.abi}} \
|
||||||
--config ${{matrix.build_type}}
|
--config ${{matrix.build_type}}
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v3
|
|
||||||
|
|||||||
26
.github/workflows/cifuzz.yml
vendored
26
.github/workflows/cifuzz.yml
vendored
@ -1,26 +0,0 @@
|
|||||||
name: CIFuzz
|
|
||||||
on: [pull_request]
|
|
||||||
jobs:
|
|
||||||
Fuzzing:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Build Fuzzers
|
|
||||||
id: build
|
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
|
||||||
with:
|
|
||||||
oss-fuzz-project-name: 'glog'
|
|
||||||
dry-run: false
|
|
||||||
language: c++
|
|
||||||
- name: Run Fuzzers
|
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
|
||||||
with:
|
|
||||||
oss-fuzz-project-name: 'glog'
|
|
||||||
fuzz-seconds: 60
|
|
||||||
dry-run: false
|
|
||||||
language: c++
|
|
||||||
- name: Upload Crash
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
if: failure() && steps.build.outcome == 'success'
|
|
||||||
with:
|
|
||||||
name: artifacts
|
|
||||||
path: ./out/artifacts
|
|
||||||
57
.github/workflows/emscripten.yml
vendored
57
.github/workflows/emscripten.yml
vendored
@ -1,57 +0,0 @@
|
|||||||
name: Emscripten
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-linux:
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
name: Emscripten-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
container: emscripten/emsdk
|
|
||||||
strategy:
|
|
||||||
fail-fast: true
|
|
||||||
matrix:
|
|
||||||
build_type: [Release, Debug]
|
|
||||||
lib: [static]
|
|
||||||
std: [14, 17, 20, 23]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v3
|
|
||||||
with:
|
|
||||||
languages: cpp
|
|
||||||
|
|
||||||
- name: Setup Dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
|
|
||||||
cmake \
|
|
||||||
ninja-build
|
|
||||||
|
|
||||||
- name: Configure
|
|
||||||
env:
|
|
||||||
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror -Wno-error=wasm-exception-spec ${{env.CXXFLAGS}}
|
|
||||||
run: |
|
|
||||||
emcmake cmake -S . -B build_${{matrix.build_type}} \
|
|
||||||
-DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \
|
|
||||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
|
||||||
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
|
||||||
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \
|
|
||||||
-G Ninja \
|
|
||||||
-Werror
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cmake --build build_${{matrix.build_type}} \
|
|
||||||
--config ${{matrix.build_type}}
|
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v3
|
|
||||||
80
.github/workflows/linux.yml
vendored
80
.github/workflows/linux.yml
vendored
@ -7,44 +7,63 @@ jobs:
|
|||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
name: GCC-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}
|
name: GCC-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}-${{matrix.extra}}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
build_type: [Release, Debug]
|
build_type: [Release, Debug]
|
||||||
|
extra: [no-custom-prefix, custom-prefix]
|
||||||
lib: [shared, static]
|
lib: [shared, static]
|
||||||
std: [14, 17, 20, 23]
|
std: [98, 11, 14, 17, 20]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v3
|
|
||||||
with:
|
|
||||||
languages: cpp
|
|
||||||
|
|
||||||
- name: Setup Dependencies
|
- name: Setup Dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-suggests --no-install-recommends \
|
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
|
||||||
g++ \
|
build-essential \
|
||||||
cmake \
|
cmake \
|
||||||
gcovr \
|
lcov \
|
||||||
libgflags-dev \
|
libgflags-dev \
|
||||||
libgmock-dev \
|
|
||||||
libgtest-dev \
|
|
||||||
libunwind-dev \
|
libunwind-dev \
|
||||||
ninja-build
|
ninja-build
|
||||||
|
|
||||||
|
- name: Cache GTest
|
||||||
|
id: cache-gtest
|
||||||
|
uses: actions/cache@v2
|
||||||
|
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
|
- name: Setup Environment
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
run: |
|
run: |
|
||||||
echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV
|
echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV
|
||||||
|
echo 'GTest_ROOT=${{github.workspace}}/gtest' >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Setup C++98 Environment
|
||||||
|
if: matrix.std == '98'
|
||||||
|
run: |
|
||||||
|
echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
env:
|
env:
|
||||||
@ -55,6 +74,7 @@ jobs:
|
|||||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||||
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
||||||
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \
|
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \
|
||||||
|
-DWITH_CUSTOM_PREFIX=${{matrix.extra == 'custom-prefix'}} \
|
||||||
-G Ninja \
|
-G Ninja \
|
||||||
-Werror
|
-Werror
|
||||||
|
|
||||||
@ -104,17 +124,27 @@ jobs:
|
|||||||
- name: Generate Coverage
|
- name: Generate Coverage
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
run: |
|
run: |
|
||||||
cd build_${{matrix.build_type}}
|
lcov --directory . --capture --output-file coverage.info
|
||||||
gcovr -r .. . -s --xml coverage.xml
|
lcov --remove coverage.info \
|
||||||
|
'${{github.workspace}}/gtest/*' \
|
||||||
|
'*/src/*_unittest.cc' \
|
||||||
|
'*/src/googletest.h' \
|
||||||
|
'*/src/mock-log.h' \
|
||||||
|
'/usr/*' \
|
||||||
|
--output-file coverage.info
|
||||||
|
|
||||||
|
for file in src/glog/*.h.in; do
|
||||||
|
name=$(basename ${file})
|
||||||
|
name_we=${name%.h.in}
|
||||||
|
sed -i "s|build_${{matrix.build_type}}/glog/${name_we}.h\$|${file}|g" coverage.info
|
||||||
|
done
|
||||||
|
|
||||||
|
lcov --list coverage.info
|
||||||
|
|
||||||
- name: Upload Coverage to Codecov
|
- name: Upload Coverage to Codecov
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: build_${{matrix.build_type}}/coverage.xml
|
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
verbose: true
|
verbose: true
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v3
|
|
||||||
|
|||||||
51
.github/workflows/macos.yml
vendored
51
.github/workflows/macos.yml
vendored
@ -5,44 +5,41 @@ on: [push, pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
build-macos:
|
build-macos:
|
||||||
name: AppleClang-C++${{matrix.std}}-${{matrix.build_type}}
|
name: AppleClang-C++${{matrix.std}}-${{matrix.build_type}}
|
||||||
runs-on: macos-12
|
runs-on: macos-10.15
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
std: [14, 17, 20, 23]
|
std: [98, 11, 14, 17, 20]
|
||||||
include:
|
include:
|
||||||
- generator: Xcode
|
- generator: Ninja
|
||||||
- build_type: Debug
|
- build_type: Debug
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Ninja
|
||||||
|
uses: ashutoshvarma/setup-ninja@master
|
||||||
|
with:
|
||||||
|
version: 1.10.0
|
||||||
|
|
||||||
- name: Setup Dependencies
|
- name: Setup Dependencies
|
||||||
run: |
|
run: |
|
||||||
brew install ninja
|
brew install lcov
|
||||||
|
|
||||||
- name: Setup Coverage Dependencies
|
|
||||||
if: matrix.build_type == 'Debug'
|
|
||||||
run: |
|
|
||||||
brew install gcovr
|
|
||||||
|
|
||||||
- name: Setup Environment
|
- name: Setup Environment
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
run: |
|
run: |
|
||||||
echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV
|
echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV
|
||||||
echo 'LDFLAGS=--coverage' >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror -pedantic-errors ${{env.CXXFLAGS}}
|
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build_${{matrix.build_type}} \
|
cmake -S . -B build_${{matrix.build_type}} \
|
||||||
-DCMAKE_CXX_EXTENSIONS=OFF \
|
-DCMAKE_CXX_EXTENSIONS=OFF \
|
||||||
|
-DCMAKE_CXX_FLAGS_DEBUG=-pedantic-errors \
|
||||||
|
-DCMAKE_CXX_FLAGS_RELEASE=-pedantic-errors \
|
||||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||||
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
||||||
-G "${{matrix.generator}}" \
|
-G "${{matrix.generator}}" \
|
||||||
@ -56,21 +53,31 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
ctest --test-dir build_${{matrix.build_type}} \
|
ctest --test-dir build_${{matrix.build_type}} \
|
||||||
--build-config ${{matrix.build_type}} \
|
|
||||||
--output-on-failure
|
--output-on-failure
|
||||||
|
|
||||||
- name: Generate Coverage
|
- name: Generate Coverage
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
run: |
|
run: |
|
||||||
cd build_${{matrix.build_type}}
|
lcov --directory . --capture --output-file coverage.info
|
||||||
rm -r Tests/
|
lcov --remove coverage.info \
|
||||||
gcovr -r .. . -s --cobertura coverage.xml
|
'*/src/*_unittest.cc' \
|
||||||
|
'*/src/googletest.h' \
|
||||||
|
'*/src/mock-log.h' \
|
||||||
|
'*/usr/*' \
|
||||||
|
--output-file coverage.info
|
||||||
|
|
||||||
|
for file in src/glog/*.h.in; do
|
||||||
|
name=$(basename ${file})
|
||||||
|
name_we=${name%.h.in}
|
||||||
|
sed -i "" "s|${{github.workspace}}/glog/${name_we}.h\$|${file}|g" coverage.info
|
||||||
|
done
|
||||||
|
|
||||||
|
lcov --list coverage.info
|
||||||
|
|
||||||
- name: Upload Coverage to Codecov
|
- name: Upload Coverage to Codecov
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: build_${{matrix.build_type}}/coverage.xml
|
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
verbose: true
|
verbose: true
|
||||||
|
|||||||
91
.github/workflows/windows.yml
vendored
91
.github/workflows/windows.yml
vendored
@ -4,12 +4,8 @@ on: [push, pull_request]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-msvc:
|
build-msvc:
|
||||||
name: ${{matrix.msvc}}-${{matrix.arch}}-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}
|
name: ${{matrix.msvc}}-${{matrix.arch}}-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}-${{matrix.extra}}
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: powershell
|
shell: powershell
|
||||||
@ -21,9 +17,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
arch: [Win32, x64]
|
arch: [Win32, x64]
|
||||||
build_type: [Debug, Release]
|
build_type: [Debug, Release]
|
||||||
|
extra: [no-custom-prefix, custom-prefix]
|
||||||
lib: [shared, static]
|
lib: [shared, static]
|
||||||
msvc: [VS-16-2019, VS-17-2022]
|
msvc: [VS-16-2019, VS-17-2022]
|
||||||
std: [14, 17, 20, 23]
|
# Visual Studio 17 2022 does not support C++11 and older language standard
|
||||||
|
std: [14, 17, 20]
|
||||||
include:
|
include:
|
||||||
- msvc: VS-16-2019
|
- msvc: VS-16-2019
|
||||||
os: windows-2019
|
os: windows-2019
|
||||||
@ -33,30 +31,25 @@ jobs:
|
|||||||
generator: 'Visual Studio 17 2022'
|
generator: 'Visual Studio 17 2022'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v3
|
|
||||||
with:
|
|
||||||
languages: cpp
|
|
||||||
|
|
||||||
- name: Cache GTest
|
- name: Cache GTest
|
||||||
id: cache-gtest
|
id: cache-gtest
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: gtest/
|
path: gtest/
|
||||||
key: ${{runner.os}}-gtest-1.14-${{matrix.lib}}-${{matrix.arch}}-${{matrix.build_type}}
|
key: ${{runner.os}}-gtest-1.11-${{matrix.lib}}-${{matrix.arch}}-${{matrix.build_type}}
|
||||||
|
|
||||||
- name: Download GTest
|
- name: Download GTest
|
||||||
if: steps.cache-gtest.outputs.cache-hit != 'true'
|
if: steps.cache-gtest.outputs.cache-hit != 'true'
|
||||||
run: |
|
run: |
|
||||||
(New-Object System.Net.WebClient).DownloadFile("https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip", "v1.14.0.zip")
|
(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 v1.14.0.zip .
|
Expand-Archive release-1.11.0.zip .
|
||||||
|
|
||||||
- name: Build GTest
|
- name: Build GTest
|
||||||
if: steps.cache-gtest.outputs.cache-hit != 'true'
|
if: steps.cache-gtest.outputs.cache-hit != 'true'
|
||||||
run: |
|
run: |
|
||||||
cmake -S googletest-1.14.0 -B build-googletest `
|
cmake -S googletest-release-1.11.0 -B build-googletest `
|
||||||
-A ${{matrix.arch}} `
|
-A ${{matrix.arch}} `
|
||||||
-DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} `
|
-DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} `
|
||||||
-Dgtest_force_shared_crt=ON `
|
-Dgtest_force_shared_crt=ON `
|
||||||
@ -67,7 +60,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Cache gflags
|
- name: Cache gflags
|
||||||
id: cache-gflags
|
id: cache-gflags
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: gflags/
|
path: gflags/
|
||||||
key: ${{runner.os}}-gflags-2.2.2-${{matrix.lib}}-${{matrix.arch}}-${{matrix.build_type}}
|
key: ${{runner.os}}-gflags-2.2.2-${{matrix.lib}}-${{matrix.arch}}-${{matrix.build_type}}
|
||||||
@ -113,6 +106,7 @@ jobs:
|
|||||||
-DCMAKE_EXE_LINKER_FLAGS_RELEASE='/INCREMENTAL:NO /DEBUG' `
|
-DCMAKE_EXE_LINKER_FLAGS_RELEASE='/INCREMENTAL:NO /DEBUG' `
|
||||||
-DCMAKE_INSTALL_PREFIX:PATH=./install `
|
-DCMAKE_INSTALL_PREFIX:PATH=./install `
|
||||||
-DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$<CONFIG:Debug>:Debug>DLL' `
|
-DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$<CONFIG:Debug>:Debug>DLL' `
|
||||||
|
-DWITH_CUSTOM_PREFIX=${{matrix.extra == 'custom-prefix'}} `
|
||||||
-G "${{matrix.generator}}" `
|
-G "${{matrix.generator}}" `
|
||||||
-Werror
|
-Werror
|
||||||
|
|
||||||
@ -134,20 +128,11 @@ jobs:
|
|||||||
--config ${{matrix.build_type}} `
|
--config ${{matrix.build_type}} `
|
||||||
--target install
|
--target install
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v3
|
|
||||||
with:
|
|
||||||
category: language:cpp
|
|
||||||
|
|
||||||
build-mingw:
|
build-mingw:
|
||||||
name: ${{matrix.sys}}-${{matrix.env}}-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}
|
name: ${{matrix.sys}}-${{matrix.env}}-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}-${{matrix.extra}}
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
env:
|
env:
|
||||||
BUILDDIR: 'build_${{matrix.sys}}-${{matrix.env}}-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}'
|
BUILDDIR: 'build_${{matrix.sys}}-${{matrix.env}}-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}-${{matrix.extra}}'
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
@ -155,8 +140,9 @@ jobs:
|
|||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
build_type: [Debug]
|
build_type: [Debug]
|
||||||
|
extra: [no-custom-prefix, custom-prefix]
|
||||||
lib: [shared, static]
|
lib: [shared, static]
|
||||||
std: [14, 17, 20, 23]
|
std: [98, 11, 14, 17, 20]
|
||||||
sys: [mingw32, mingw64]
|
sys: [mingw32, mingw64]
|
||||||
include:
|
include:
|
||||||
- sys: mingw32
|
- sys: mingw32
|
||||||
@ -165,30 +151,21 @@ jobs:
|
|||||||
env: x86_64
|
env: x86_64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v3
|
|
||||||
with:
|
|
||||||
languages: cpp
|
|
||||||
|
|
||||||
- uses: msys2/setup-msys2@v2
|
- uses: msys2/setup-msys2@v2
|
||||||
with:
|
with:
|
||||||
msystem: ${{matrix.sys}}
|
msystem: ${{matrix.sys}}
|
||||||
install: >-
|
install: >-
|
||||||
|
lcov
|
||||||
mingw-w64-${{matrix.env}}-cmake
|
mingw-w64-${{matrix.env}}-cmake
|
||||||
mingw-w64-${{matrix.env}}-gcc
|
mingw-w64-${{matrix.env}}-gcc
|
||||||
mingw-w64-${{matrix.env}}-gflags
|
mingw-w64-${{matrix.env}}-gflags
|
||||||
mingw-w64-${{matrix.env}}-ninja
|
mingw-w64-${{matrix.env}}-ninja
|
||||||
mingw-w64-${{matrix.env}}-python-jinja
|
|
||||||
mingw-w64-${{matrix.env}}-python-lxml
|
|
||||||
mingw-w64-${{matrix.env}}-python-pip
|
|
||||||
mingw-w64-${{matrix.env}}-python-pygments
|
|
||||||
|
|
||||||
- name: Setup Coverage Dependencies
|
- name: Setup C++98 Environment
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.std == '98'
|
||||||
run: |
|
run: |
|
||||||
pip install 'gcovr==7.0'
|
echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Setup Environment
|
- name: Setup Environment
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
@ -206,6 +183,7 @@ jobs:
|
|||||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||||
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
|
||||||
-DCMAKE_INSTALL_PREFIX:PATH=./install \
|
-DCMAKE_INSTALL_PREFIX:PATH=./install \
|
||||||
|
-DWITH_CUSTOM_PREFIX=${{matrix.extra == 'custom-prefix'}} \
|
||||||
-G Ninja \
|
-G Ninja \
|
||||||
-Werror
|
-Werror
|
||||||
|
|
||||||
@ -229,17 +207,28 @@ jobs:
|
|||||||
- name: Generate Coverage
|
- name: Generate Coverage
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
run: |
|
run: |
|
||||||
cd build_${{matrix.build_type}}
|
lcov --directory . --capture --output-file coverage.info
|
||||||
gcovr -r .. . -s --cobertura coverage.xml
|
lcov --remove coverage.info \
|
||||||
|
'*/install/include/*' \
|
||||||
|
'*/msys64/mingw32/*' \
|
||||||
|
'*/msys64/mingw64/*' \
|
||||||
|
'*/src/*_unittest.cc' \
|
||||||
|
'*/src/googletest.h' \
|
||||||
|
'*/src/mock-log.h' \
|
||||||
|
--output-file coverage.info
|
||||||
|
|
||||||
|
for file in src/glog/*.h.in; do
|
||||||
|
name=$(basename ${file})
|
||||||
|
name_we=${name%.h.in}
|
||||||
|
sed -i "s|build_${{matrix.build_type}}/glog/${name_we}.h\$|${file}|g" coverage.info
|
||||||
|
done
|
||||||
|
|
||||||
|
lcov --list coverage.info
|
||||||
|
|
||||||
- name: Upload Coverage to Codecov
|
- name: Upload Coverage to Codecov
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: build_${{matrix.build_type}}/coverage.xml
|
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
verbose: true
|
verbose: true
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v3
|
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,3 @@
|
|||||||
*.orig
|
*.orig
|
||||||
/build*/
|
/build*/
|
||||||
/site/
|
|
||||||
bazel-*
|
bazel-*
|
||||||
# Bzlmod lockfile
|
|
||||||
/MODULE.bazel.lock
|
|
||||||
|
|||||||
1
AUTHORS
1
AUTHORS
@ -16,7 +16,6 @@ Brian Silverman <bsilver16384@gmail.com>
|
|||||||
Dmitriy Arbitman <d.arbitman@gmail.com>
|
Dmitriy Arbitman <d.arbitman@gmail.com>
|
||||||
Google Inc.
|
Google Inc.
|
||||||
Guillaume Dumont <dumont.guillaume@gmail.com>
|
Guillaume Dumont <dumont.guillaume@gmail.com>
|
||||||
LingBin <lingbinlb@gmail.com>
|
|
||||||
Marco Wang <m.aesophor@gmail.com>
|
Marco Wang <m.aesophor@gmail.com>
|
||||||
Michael Tanner <michael@tannertaxpro.com>
|
Michael Tanner <michael@tannertaxpro.com>
|
||||||
MiniLight <MiniLightAR@Gmail.com>
|
MiniLight <MiniLightAR@Gmail.com>
|
||||||
|
|||||||
19
BUILD.bazel
19
BUILD.bazel
@ -1,22 +1,7 @@
|
|||||||
licenses(["notice"])
|
licenses(['notice'])
|
||||||
|
|
||||||
exports_files(["COPYING"])
|
exports_files(["COPYING"])
|
||||||
|
|
||||||
load(":bazel/glog.bzl", "glog_library")
|
load(':bazel/glog.bzl', 'glog_library')
|
||||||
|
|
||||||
glog_library()
|
glog_library()
|
||||||
|
|
||||||
# platform() to build with clang-cl on Bazel CI. This is enabled with
|
|
||||||
# the flags in .bazelci/presubmit.yml:
|
|
||||||
#
|
|
||||||
# --incompatible_enable_cc_toolchain_resolution
|
|
||||||
# --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl
|
|
||||||
# --extra_execution_platforms=//:x64_windows-clang-cl
|
|
||||||
platform(
|
|
||||||
name = "x64_windows-clang-cl",
|
|
||||||
constraint_values = [
|
|
||||||
"@platforms//cpu:x86_64",
|
|
||||||
"@platforms//os:windows",
|
|
||||||
"@rules_cc//cc/private/toolchain:clang-cl",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|||||||
999
CMakeLists.txt
999
CMakeLists.txt
File diff suppressed because it is too large
Load Diff
@ -29,14 +29,12 @@ Andy Ying <andy@trailofbits.com>
|
|||||||
Bret McKee <bretmckee@google.com>
|
Bret McKee <bretmckee@google.com>
|
||||||
Brian Silverman <bsilver16384@gmail.com>
|
Brian Silverman <bsilver16384@gmail.com>
|
||||||
Dmitriy Arbitman <d.arbitman@gmail.com>
|
Dmitriy Arbitman <d.arbitman@gmail.com>
|
||||||
Eric Kilmer <eric.d.kilmer@gmail.com>
|
|
||||||
Fumitoshi Ukai <ukai@google.com>
|
Fumitoshi Ukai <ukai@google.com>
|
||||||
Guillaume Dumont <dumont.guillaume@gmail.com>
|
Guillaume Dumont <dumont.guillaume@gmail.com>
|
||||||
Håkan L. S. Younes <hyounes@google.com>
|
Håkan L. S. Younes <hyounes@google.com>
|
||||||
Ivan Penkov <ivanpe@google.com>
|
Ivan Penkov <ivanpe@google.com>
|
||||||
Jacob Trimble <modmaker@google.com>
|
Jacob Trimble <modmaker@google.com>
|
||||||
Jim Ray <jimray@google.com>
|
Jim Ray <jimray@google.com>
|
||||||
LingBin <lingbinlb@gmail.com>
|
|
||||||
Marco Wang <m.aesophor@gmail.com>
|
Marco Wang <m.aesophor@gmail.com>
|
||||||
Michael Darr <mdarr@matician.com>
|
Michael Darr <mdarr@matician.com>
|
||||||
Michael Tanner <michael@tannertaxpro.com>
|
Michael Tanner <michael@tannertaxpro.com>
|
||||||
|
|||||||
65
COPYING
Normal file
65
COPYING
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
Copyright (c) 2008, 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.
|
||||||
|
|
||||||
|
|
||||||
|
A function gettimeofday in utilities.cc is based on
|
||||||
|
|
||||||
|
http://www.google.com/codesearch/p?hl=en#dR3YEbitojA/COPYING&q=GetSystemTimeAsFileTime%20license:bsd
|
||||||
|
|
||||||
|
The license of this code is:
|
||||||
|
|
||||||
|
Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi> and contributors
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. 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.
|
||||||
|
|
||||||
|
3. Neither the name(s) of the above-listed copyright holder(s) 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.
|
||||||
15
ChangeLog
15
ChangeLog
@ -1,18 +1,3 @@
|
|||||||
2024-06-08 Google Inc. <opensource@google.com>
|
|
||||||
|
|
||||||
* google-glog: version 0.7.1.
|
|
||||||
* See git log for the details.
|
|
||||||
|
|
||||||
2024-02-17 Google Inc. <opensource@google.com>
|
|
||||||
|
|
||||||
* google-glog: version 0.7.0.
|
|
||||||
* See git log for the details.
|
|
||||||
|
|
||||||
2022-04-05 Google Inc. <opensource@google.com>
|
|
||||||
|
|
||||||
* google-glog: version 0.6.0.
|
|
||||||
* See git log for the details.
|
|
||||||
|
|
||||||
2021-05-08 Google Inc. <opensource@google.com>
|
2021-05-08 Google Inc. <opensource@google.com>
|
||||||
|
|
||||||
* google-glog: version 0.5.0.
|
* google-glog: version 0.5.0.
|
||||||
|
|||||||
27
LICENSE.md
27
LICENSE.md
@ -1,27 +0,0 @@
|
|||||||
Copyright © 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.
|
|
||||||
13
MODULE.bazel
13
MODULE.bazel
@ -1,13 +0,0 @@
|
|||||||
module(
|
|
||||||
name = "glog",
|
|
||||||
compatibility_level = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
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")
|
|
||||||
862
README.rst
862
README.rst
@ -1,16 +1,868 @@
|
|||||||
Google Logging Library
|
Google Logging Library
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|Linux Github actions| |Windows Github actions| |macOS Github actions| |Codecov|
|
|Linux Github actions| |Windows Github actions| |macOS Github actions| |Total alerts| |Language grade: C++| |Codecov|
|
||||||
|
|
||||||
Google Logging (glog) is a C++14 library that implements application-level
|
Google Logging (glog) is a C++98 library that implements application-level
|
||||||
logging. The library provides logging APIs based on C++-style streams and
|
logging. The library provides logging APIs based on C++-style streams and
|
||||||
various helper macros.
|
various helper macros.
|
||||||
|
|
||||||
|
.. role:: cmake(code)
|
||||||
|
:language: cmake
|
||||||
|
|
||||||
|
.. role:: cmd(code)
|
||||||
|
:language: bash
|
||||||
|
|
||||||
|
.. role:: cpp(code)
|
||||||
|
:language: cpp
|
||||||
|
|
||||||
|
.. role:: bazel(code)
|
||||||
|
:language: starlark
|
||||||
|
|
||||||
|
|
||||||
Getting Started
|
Getting Started
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Please refer to project's `documentation <https://google.github.io/glog/>`_.
|
You can log a message by simply streaming things to ``LOG``\ (<a
|
||||||
|
particular `severity level <#severity-levels>`__>), e.g.,
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
// Initialize Google’s logging library.
|
||||||
|
google::InitGoogleLogging(argv[0]);
|
||||||
|
|
||||||
|
// ...
|
||||||
|
LOG(INFO) << "Found " << num_cookies << " cookies";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
For a detailed overview of glog features and their usage, please refer
|
||||||
|
to the `user guide <#user-guide>`__.
|
||||||
|
|
||||||
|
.. contents:: Table of Contents
|
||||||
|
|
||||||
|
|
||||||
|
Building from Source
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
glog supports multiple build systems for compiling the project from
|
||||||
|
source: `Bazel <#bazel>`__, `CMake <#cmake>`__, and `vcpkg <#vcpkg>`__.
|
||||||
|
|
||||||
|
Bazel
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
To use glog within a project which uses the
|
||||||
|
`Bazel <https://bazel.build/>`__ build tool, add the following lines to
|
||||||
|
your ``WORKSPACE`` file:
|
||||||
|
|
||||||
|
.. code:: bazel
|
||||||
|
|
||||||
|
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://github.com/gflags/gflags/archive/v2.2.2.tar.gz"],
|
||||||
|
)
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "com_github_google_glog",
|
||||||
|
sha256 = "21bc744fb7f2fa701ee8db339ded7dce4f975d0d55837a97be7d46e8382dea5a",
|
||||||
|
strip_prefix = "glog-0.5.0",
|
||||||
|
urls = ["https://github.com/google/glog/archive/v0.5.0.zip"],
|
||||||
|
)
|
||||||
|
|
||||||
|
You can then add :bazel:`@com_github_google_glog//:glog` to the deps section
|
||||||
|
of a :bazel:`cc_binary` or :bazel:`cc_library` rule, and :code:`#include
|
||||||
|
<glog/logging.h>` to include it in your source code. Here’s a simple example:
|
||||||
|
|
||||||
|
.. code:: bazel
|
||||||
|
|
||||||
|
cc_binary(
|
||||||
|
name = "main",
|
||||||
|
srcs = ["main.cc"],
|
||||||
|
deps = ["@com_github_google_glog//:glog"],
|
||||||
|
)
|
||||||
|
|
||||||
|
CMake
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
glog also supports CMake that can be used to build the project on a wide
|
||||||
|
range of platforms. If you don’t have CMake installed already, you can
|
||||||
|
download it for from CMake’s `official
|
||||||
|
website <http://www.cmake.org>`__.
|
||||||
|
|
||||||
|
CMake works by generating native makefiles or build projects that can be
|
||||||
|
used in the compiler environment of your choice. You can either build
|
||||||
|
glog with CMake as a standalone project or it can be incorporated into
|
||||||
|
an existing CMake build for another project.
|
||||||
|
|
||||||
|
Building glog with CMake
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
When building glog as a standalone project, on Unix-like systems with
|
||||||
|
GNU Make as build tool, the typical workflow is:
|
||||||
|
|
||||||
|
1. Get the source code and change to it. e.g., cloning with git:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
git clone https://github.com/google/glog.git
|
||||||
|
cd glog
|
||||||
|
|
||||||
|
2. Run CMake to configure the build tree.
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
cmake -S . -B build -G "Unix Makefiles"
|
||||||
|
|
||||||
|
CMake provides different generators, and by default will pick the most
|
||||||
|
relevant one to your environment. If you need a specific version of Visual
|
||||||
|
Studio, use :cmd:`cmake . -G <generator-name>`, and see :cmd:`cmake --help`
|
||||||
|
for the available generators. Also see :cmd:`-T <toolset-name>`, which can
|
||||||
|
be used to request the native x64 toolchain with :cmd:`-T host=x64`.
|
||||||
|
|
||||||
|
3. Afterwards, generated files can be used to compile the project.
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
cmake --build build
|
||||||
|
|
||||||
|
4. Test the build software (optional).
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
cmake --build build --target test
|
||||||
|
|
||||||
|
5. Install the built files (optional).
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
cmake --build build --target install
|
||||||
|
|
||||||
|
Consuming glog in a CMake Project
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
If you have glog installed in your system, you can use the CMake command
|
||||||
|
:cmake:`find_package` to build against glog in your CMake Project as follows:
|
||||||
|
|
||||||
|
.. code:: cmake
|
||||||
|
|
||||||
|
cmake_minimum_required (VERSION 3.16)
|
||||||
|
project (myproj VERSION 1.0)
|
||||||
|
|
||||||
|
find_package (glog 0.6.0 REQUIRED)
|
||||||
|
|
||||||
|
add_executable (myapp main.cpp)
|
||||||
|
target_link_libraries (myapp glog::glog)
|
||||||
|
|
||||||
|
Compile definitions and options will be added automatically to your
|
||||||
|
target as needed.
|
||||||
|
|
||||||
|
Incorporating glog into a CMake Project
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
You can also use the CMake command :cmake:`add_subdirectory` to include glog
|
||||||
|
directly from a subdirectory of your project by replacing the
|
||||||
|
:cmake:`find_package` call from the previous example by
|
||||||
|
:cmake:`add_subdirectory`. The :cmake:`glog::glog` target is in this case an
|
||||||
|
:cmake:`ALIAS` library target for the ``glog`` library target.
|
||||||
|
|
||||||
|
Again, compile definitions and options will be added automatically to
|
||||||
|
your target as needed.
|
||||||
|
|
||||||
|
vcpkg
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
You can download and install glog using the `vcpkg
|
||||||
|
<https://github.com/Microsoft/vcpkg>`__ dependency manager:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
git clone https://github.com/Microsoft/vcpkg.git
|
||||||
|
cd vcpkg
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
./vcpkg integrate install
|
||||||
|
./vcpkg install glog
|
||||||
|
|
||||||
|
The glog port in vcpkg is kept up to date by Microsoft team members and
|
||||||
|
community contributors. If the version is out of date, please create an
|
||||||
|
issue or pull request on the vcpkg repository.
|
||||||
|
|
||||||
|
User Guide
|
||||||
|
----------
|
||||||
|
|
||||||
|
glog defines a series of macros that simplify many common logging tasks.
|
||||||
|
You can log messages by severity level, control logging behavior from
|
||||||
|
the command line, log based on conditionals, abort the program when
|
||||||
|
expected conditions are not met, introduce your own verbose logging
|
||||||
|
levels, customize the prefix attached to log messages, and more.
|
||||||
|
|
||||||
|
Following sections describe the functionality supported by glog. Please note
|
||||||
|
this description may not be complete but limited to the most useful ones. If you
|
||||||
|
want to find less common features, please check header files under `src/glog
|
||||||
|
<src/glog>`__ directory.
|
||||||
|
|
||||||
|
Severity Levels
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
You can specify one of the following severity levels (in increasing
|
||||||
|
order of severity): ``INFO``, ``WARNING``, ``ERROR``, and ``FATAL``.
|
||||||
|
Logging a ``FATAL`` message terminates the program (after the message is
|
||||||
|
logged). Note that messages of a given severity are logged not only in
|
||||||
|
the logfile for that severity, but also in all logfiles of lower
|
||||||
|
severity. E.g., a message of severity ``FATAL`` will be logged to the
|
||||||
|
logfiles of severity ``FATAL``, ``ERROR``, ``WARNING``, and ``INFO``.
|
||||||
|
|
||||||
|
The ``DFATAL`` severity logs a ``FATAL`` error in debug mode (i.e.,
|
||||||
|
there is no ``NDEBUG`` macro defined), but avoids halting the program in
|
||||||
|
production by automatically reducing the severity to ``ERROR``.
|
||||||
|
|
||||||
|
Unless otherwise specified, glog writes to the filename
|
||||||
|
``/tmp/\<program name\>.\<hostname\>.\<user name\>.log.\<severity level\>.\<date\>-\<time\>.\<pid\>``
|
||||||
|
(e.g.,
|
||||||
|
``/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474``).
|
||||||
|
By default, glog copies the log messages of severity level ``ERROR`` or
|
||||||
|
``FATAL`` to standard error (``stderr``) in addition to log files.
|
||||||
|
|
||||||
|
Setting Flags
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Several flags influence glog’s output behavior. If the `Google gflags library
|
||||||
|
<https://github.com/gflags/gflags>`__ is installed on your machine, the build
|
||||||
|
system will automatically detect and use it, allowing you to pass flags on the
|
||||||
|
command line. For example, if you want to turn the flag :cmd:`--logtostderr` on,
|
||||||
|
you can start your application with the following command line:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
./your_application --logtostderr=1
|
||||||
|
|
||||||
|
If the Google gflags library isn’t installed, you set flags via
|
||||||
|
environment variables, prefixing the flag name with ``GLOG_``, e.g.,
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
GLOG_logtostderr=1 ./your_application
|
||||||
|
|
||||||
|
The following flags are most commonly used:
|
||||||
|
|
||||||
|
``logtostderr`` (``bool``, default=\ ``false``)
|
||||||
|
Log messages to ``stderr`` instead of logfiles. Note: you can set
|
||||||
|
binary flags to ``true`` by specifying ``1``, ``true``, or ``yes``
|
||||||
|
(case insensitive). Also, you can set binary flags to ``false`` by
|
||||||
|
specifying ``0``, ``false``, or ``no`` (again, case insensitive).
|
||||||
|
|
||||||
|
``stderrthreshold`` (``int``, default=2, which is ``ERROR``)
|
||||||
|
Copy log messages at or above this level to stderr in addition to
|
||||||
|
logfiles. The numbers of severity levels ``INFO``, ``WARNING``,
|
||||||
|
``ERROR``, and ``FATAL`` are 0, 1, 2, and 3, respectively.
|
||||||
|
|
||||||
|
``minloglevel`` (``int``, default=0, which is ``INFO``)
|
||||||
|
Log messages at or above this level. Again, the numbers of severity
|
||||||
|
levels ``INFO``, ``WARNING``, ``ERROR``, and ``FATAL`` are 0, 1, 2,
|
||||||
|
and 3, respectively.
|
||||||
|
|
||||||
|
``log_dir`` (``string``, default="")
|
||||||
|
If specified, logfiles are written into this directory instead of the
|
||||||
|
default logging directory.
|
||||||
|
|
||||||
|
``v`` (``int``, default=0)
|
||||||
|
Show all ``VLOG(m)`` messages for ``m`` less or equal the value of
|
||||||
|
this flag. Overridable by :cmd:`--vmodule`. See `the section about
|
||||||
|
verbose logging <#verbose-logging>`__ for more detail.
|
||||||
|
|
||||||
|
``vmodule`` (``string``, default="")
|
||||||
|
Per-module verbose level. The argument has to contain a
|
||||||
|
comma-separated list of <module name>=<log level>. <module name> is a
|
||||||
|
glob pattern (e.g., ``gfs*`` for all modules whose name starts with
|
||||||
|
"gfs"), matched against the filename base (that is, name ignoring
|
||||||
|
.cc/.h./-inl.h). <log level> overrides any value given by :cmd:`--v`.
|
||||||
|
See also `the section about verbose logging <#verbose-logging>`__.
|
||||||
|
|
||||||
|
There are some other flags defined in logging.cc. Please grep the source
|
||||||
|
code for ``DEFINE_`` to see a complete list of all flags.
|
||||||
|
|
||||||
|
You can also modify flag values in your program by modifying global
|
||||||
|
variables ``FLAGS_*`` . Most settings start working immediately after
|
||||||
|
you update ``FLAGS_*`` . The exceptions are the flags related to
|
||||||
|
destination files. For example, you might want to set ``FLAGS_log_dir``
|
||||||
|
before calling :cpp:`google::InitGoogleLogging` . Here is an example:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG(INFO) << "file";
|
||||||
|
// Most flags work immediately after updating values.
|
||||||
|
FLAGS_logtostderr = 1;
|
||||||
|
LOG(INFO) << "stderr";
|
||||||
|
FLAGS_logtostderr = 0;
|
||||||
|
// This won’t change the log destination. If you want to set this
|
||||||
|
// value, you should do this before google::InitGoogleLogging .
|
||||||
|
FLAGS_log_dir = "/some/log/directory";
|
||||||
|
LOG(INFO) << "the same file";
|
||||||
|
|
||||||
|
Conditional / Occasional Logging
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Sometimes, you may only want to log a message under certain conditions.
|
||||||
|
You can use the following macros to perform conditional logging:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
|
||||||
|
|
||||||
|
The "Got lots of cookies" message is logged only when the variable
|
||||||
|
``num_cookies`` exceeds 10. If a line of code is executed many times, it
|
||||||
|
may be useful to only log a message at certain intervals. This kind of
|
||||||
|
logging is most useful for informational messages.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
|
||||||
|
|
||||||
|
The above line outputs a log messages on the 1st, 11th, 21st, ... times
|
||||||
|
it is executed. Note that the special ``google::COUNTER`` value is used
|
||||||
|
to identify which repetition is happening.
|
||||||
|
|
||||||
|
You can combine conditional and occasional logging with the following
|
||||||
|
macro.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
|
||||||
|
<< "th big cookie";
|
||||||
|
|
||||||
|
Instead of outputting a message every nth time, you can also limit the
|
||||||
|
output to the first n occurrences:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
|
||||||
|
|
||||||
|
Outputs log messages for the first 20 times it is executed. Again, the
|
||||||
|
``google::COUNTER`` identifier indicates which repetition is happening.
|
||||||
|
|
||||||
|
Other times, it is desired to only log a message periodically based on a time.
|
||||||
|
So for example, to log a message every 10ms:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG_EVERY_T(INFO, 0.01) << "Got a cookie";
|
||||||
|
|
||||||
|
Or every 2.35s:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
LOG_EVERY_T(INFO, 2.35) << "Got a cookie";
|
||||||
|
|
||||||
|
Debug Mode Support
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Special "debug mode" logging macros only have an effect in debug mode
|
||||||
|
and are compiled away to nothing for non-debug mode compiles. Use these
|
||||||
|
macros to avoid slowing down your production application due to
|
||||||
|
excessive logging.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
DLOG(INFO) << "Found cookies";
|
||||||
|
DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
|
||||||
|
DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
|
||||||
|
|
||||||
|
|
||||||
|
``CHECK`` Macros
|
||||||
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
It is a good practice to check expected conditions in your program
|
||||||
|
frequently to detect errors as early as possible. The ``CHECK`` macro
|
||||||
|
provides the ability to abort the application when a condition is not
|
||||||
|
met, similar to the ``assert`` macro defined in the standard C library.
|
||||||
|
|
||||||
|
``CHECK`` aborts the application if a condition is not true. Unlike
|
||||||
|
``assert``, it is \*not\* controlled by ``NDEBUG``, so the check will be
|
||||||
|
executed regardless of compilation mode. Therefore, ``fp->Write(x)`` in
|
||||||
|
the following example is always executed:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
CHECK(fp->Write(x) == 4) << "Write failed!";
|
||||||
|
|
||||||
|
There are various helper macros for equality/inequality checks -
|
||||||
|
``CHECK_EQ``, ``CHECK_NE``, ``CHECK_LE``, ``CHECK_LT``, ``CHECK_GE``,
|
||||||
|
and ``CHECK_GT``. They compare two values, and log a ``FATAL`` message
|
||||||
|
including the two values when the result is not as expected. The values
|
||||||
|
must have :cpp:`operator<<(ostream, ...)` defined.
|
||||||
|
|
||||||
|
You may append to the error message like so:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
CHECK_NE(1, 2) << ": The world must be ending!";
|
||||||
|
|
||||||
|
We are very careful to ensure that each argument is evaluated exactly
|
||||||
|
once, and that anything which is legal to pass as a function argument is
|
||||||
|
legal here. In particular, the arguments may be temporary expressions
|
||||||
|
which will end up being destroyed at the end of the apparent statement,
|
||||||
|
for example:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
CHECK_EQ(string("abc")[1], ’b’);
|
||||||
|
|
||||||
|
The compiler reports an error if one of the arguments is a pointer and the other
|
||||||
|
is :cpp:`NULL`. To work around this, simply :cpp:`static_cast` :cpp:`NULL` to
|
||||||
|
the type of the desired pointer.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
CHECK_EQ(some_ptr, static_cast<SomeType*>(NULL));
|
||||||
|
|
||||||
|
Better yet, use the ``CHECK_NOTNULL`` macro:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
CHECK_NOTNULL(some_ptr);
|
||||||
|
some_ptr->DoSomething();
|
||||||
|
|
||||||
|
Since this macro returns the given pointer, this is very useful in
|
||||||
|
constructor initializer lists.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
struct S {
|
||||||
|
S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
|
||||||
|
Something* ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
Note that you cannot use this macro as a C++ stream due to this feature.
|
||||||
|
Please use ``CHECK_EQ`` described above to log a custom message before
|
||||||
|
aborting the application.
|
||||||
|
|
||||||
|
If you are comparing C strings (:cpp:`char *`), a handy set of macros performs
|
||||||
|
case sensitive as well as case insensitive comparisons - ``CHECK_STREQ``,
|
||||||
|
``CHECK_STRNE``, ``CHECK_STRCASEEQ``, and ``CHECK_STRCASENE``. The CASE versions
|
||||||
|
are case-insensitive. You can safely pass :cpp:`NULL` pointers for this macro. They
|
||||||
|
treat :cpp:`NULL` and any non-:cpp:`NULL` string as not equal. Two :cpp:`NULL`\
|
||||||
|
s are equal.
|
||||||
|
|
||||||
|
Note that both arguments may be temporary strings which are destructed
|
||||||
|
at the end of the current "full expression" (e.g.,
|
||||||
|
:cpp:`CHECK_STREQ(Foo().c_str(), Bar().c_str())` where ``Foo`` and ``Bar``
|
||||||
|
return C++’s :cpp:`std::string`).
|
||||||
|
|
||||||
|
The ``CHECK_DOUBLE_EQ`` macro checks the equality of two floating point
|
||||||
|
values, accepting a small error margin. ``CHECK_NEAR`` accepts a third
|
||||||
|
floating point argument, which specifies the acceptable error margin.
|
||||||
|
|
||||||
|
Verbose Logging
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
When you are chasing difficult bugs, thorough log messages are very useful.
|
||||||
|
However, you may want to ignore too verbose messages in usual development. For
|
||||||
|
such verbose logging, glog provides the ``VLOG`` macro, which allows you to
|
||||||
|
define your own numeric logging levels. The :cmd:`--v` command line option
|
||||||
|
controls which verbose messages are logged:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
VLOG(1) << "I’m printed when you run the program with --v=1 or higher";
|
||||||
|
VLOG(2) << "I’m printed when you run the program with --v=2 or higher";
|
||||||
|
|
||||||
|
With ``VLOG``, the lower the verbose level, the more likely messages are to be
|
||||||
|
logged. For example, if :cmd:`--v==1`, ``VLOG(1)`` will log, but ``VLOG(2)``
|
||||||
|
will not log. This is opposite of the severity level, where ``INFO`` is 0, and
|
||||||
|
``ERROR`` is 2. :cmd:`--minloglevel` of 1 will log ``WARNING`` and above. Though
|
||||||
|
you can specify any integers for both ``VLOG`` macro and :cmd:`--v` flag, the
|
||||||
|
common values for them are small positive integers. For example, if you write
|
||||||
|
``VLOG(0)``, you should specify :cmd:`--v=-1` or lower to silence it. This is
|
||||||
|
less useful since we may not want verbose logs by default in most cases. The
|
||||||
|
``VLOG`` macros always log at the ``INFO`` log level (when they log at all).
|
||||||
|
|
||||||
|
Verbose logging can be controlled from the command line on a per-module
|
||||||
|
basis:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
--vmodule=mapreduce=2,file=1,gfs*=3 --v=0
|
||||||
|
|
||||||
|
will:
|
||||||
|
|
||||||
|
(a) Print ``VLOG(2)`` and lower messages from mapreduce.{h,cc}
|
||||||
|
(b) Print ``VLOG(1)`` and lower messages from file.{h,cc}
|
||||||
|
(c) Print ``VLOG(3)`` and lower messages from files prefixed with "gfs"
|
||||||
|
(d) Print ``VLOG(0)`` and lower messages from elsewhere
|
||||||
|
|
||||||
|
The wildcarding functionality shown by (c) supports both ’*’ (matches 0
|
||||||
|
or more characters) and ’?’ (matches any single character) wildcards.
|
||||||
|
Please also check the section about `command line flags <#setting-flags>`__.
|
||||||
|
|
||||||
|
There’s also ``VLOG_IS_ON(n)`` "verbose level" condition macro. This
|
||||||
|
macro returns true when the :cmd:`--v` is equal or greater than ``n``. To
|
||||||
|
be used as
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
if (VLOG_IS_ON(2)) {
|
||||||
|
// do some logging preparation and logging
|
||||||
|
// that can’t be accomplished with just VLOG(2) << ...;
|
||||||
|
}
|
||||||
|
|
||||||
|
Verbose level condition macros ``VLOG_IF``, ``VLOG_EVERY_N`` and
|
||||||
|
``VLOG_IF_EVERY_N`` behave analogous to ``LOG_IF``, ``LOG_EVERY_N``,
|
||||||
|
``LOF_IF_EVERY``, but accept a numeric verbosity level as opposed to a
|
||||||
|
severity level.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
VLOG_IF(1, (size > 1024))
|
||||||
|
<< "I’m printed when size is more than 1024 and when you run the "
|
||||||
|
"program with --v=1 or more";
|
||||||
|
VLOG_EVERY_N(1, 10)
|
||||||
|
<< "I’m printed every 10th occurrence, and when you run the program "
|
||||||
|
"with --v=1 or more. Present occurence is " << google::COUNTER;
|
||||||
|
VLOG_IF_EVERY_N(1, (size > 1024), 10)
|
||||||
|
<< "I’m printed on every 10th occurence of case when size is more "
|
||||||
|
" than 1024, when you run the program with --v=1 or more. ";
|
||||||
|
"Present occurence is " << google::COUNTER;
|
||||||
|
|
||||||
|
|
||||||
|
Custom Log Prefix Format
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
glog supports changing the format of the prefix attached to log messages by
|
||||||
|
receiving a user-provided callback to be used to generate such strings. That
|
||||||
|
feature must be enabled at compile time by the ``WITH_CUSTOM_PREFIX`` flag.
|
||||||
|
|
||||||
|
For each log entry, the callback will be invoked with a ``LogMessageInfo``
|
||||||
|
struct containing the severity, filename, line number, thread ID, and time of
|
||||||
|
the event. It will also be given a reference to the output stream, whose
|
||||||
|
contents will be prepended to the actual message in the final log line.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
/* This function writes a prefix that matches glog's default format.
|
||||||
|
* (The third parameter can be used to receive user-supplied data, and is
|
||||||
|
* NULL by default.)
|
||||||
|
*/
|
||||||
|
void CustomPrefix(std::ostream &s, const LogMessageInfo &l, void*) {
|
||||||
|
s << l.severity[0]
|
||||||
|
<< setw(4) << 1900 + l.time.year()
|
||||||
|
<< setw(2) << 1 + l.time.month()
|
||||||
|
<< setw(2) << l.time.day()
|
||||||
|
<< ' '
|
||||||
|
<< setw(2) << l.time.hour() << ':'
|
||||||
|
<< setw(2) << l.time.min() << ':'
|
||||||
|
<< setw(2) << l.time.sec() << "."
|
||||||
|
<< setw(6) << l.time.usec()
|
||||||
|
<< ' '
|
||||||
|
<< setfill(' ') << setw(5)
|
||||||
|
<< l.thread_id << setfill('0')
|
||||||
|
<< ' '
|
||||||
|
<< l.filename << ':' << l.line_number << "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
To enable the use of ``CustomPrefix()``, simply give glog a pointer to it
|
||||||
|
during initialization: ``InitGoogleLogging(argv[0], &CustomPrefix);``.
|
||||||
|
|
||||||
|
Optionally, ``InitGoogleLogging()`` takes a third argument of type ``void*``
|
||||||
|
to pass on to the callback function.
|
||||||
|
|
||||||
|
Failure Signal Handler
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The library provides a convenient signal handler that will dump useful
|
||||||
|
information when the program crashes on certain signals such as ``SIGSEGV``. The
|
||||||
|
signal handler can be installed by :cpp:`google::InstallFailureSignalHandler()`.
|
||||||
|
The following is an example of output from the signal handler.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
*** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date ***
|
||||||
|
*** SIGSEGV (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: ***
|
||||||
|
PC: @ 0x412eb1 TestWaitingLogSink::send()
|
||||||
|
@ 0x7f892fb417d0 (unknown)
|
||||||
|
@ 0x412eb1 TestWaitingLogSink::send()
|
||||||
|
@ 0x7f89304f7f06 google::LogMessage::SendToLog()
|
||||||
|
@ 0x7f89304f35af google::LogMessage::Flush()
|
||||||
|
@ 0x7f89304f3739 google::LogMessage::~LogMessage()
|
||||||
|
@ 0x408cf4 TestLogSinkWaitTillSent()
|
||||||
|
@ 0x4115de main
|
||||||
|
@ 0x7f892f7ef1c4 (unknown)
|
||||||
|
@ 0x4046f9 (unknown)
|
||||||
|
|
||||||
|
By default, the signal handler writes the failure dump to the standard
|
||||||
|
error. You can customize the destination by :cpp:`InstallFailureWriter()`.
|
||||||
|
|
||||||
|
Performance of Messages
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The conditional logging macros provided by glog (e.g., ``CHECK``,
|
||||||
|
``LOG_IF``, ``VLOG``, etc.) are carefully implemented and don’t execute
|
||||||
|
the right hand side expressions when the conditions are false. So, the
|
||||||
|
following check may not sacrifice the performance of your application.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
CHECK(obj.ok) << obj.CreatePrettyFormattedStringButVerySlow();
|
||||||
|
|
||||||
|
User-defined Failure Function
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
``FATAL`` severity level messages or unsatisfied ``CHECK`` condition
|
||||||
|
terminate your program. You can change the behavior of the termination
|
||||||
|
by :cpp:`InstallFailureFunction`.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
void YourFailureFunction() {
|
||||||
|
// Reports something...
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
google::InstallFailureFunction(&YourFailureFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
By default, glog tries to dump stacktrace and makes the program exit
|
||||||
|
with status 1. The stacktrace is produced only when you run the program
|
||||||
|
on an architecture for which glog supports stack tracing (as of
|
||||||
|
September 2008, glog supports stack tracing for x86 and x86_64).
|
||||||
|
|
||||||
|
Raw Logging
|
||||||
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
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.in
|
||||||
|
<src/glog/raw_logging.h.in>`__ for detail.
|
||||||
|
|
||||||
|
Google Style ``perror()``
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
``PLOG()`` and ``PLOG_IF()`` and ``PCHECK()`` behave exactly like their
|
||||||
|
``LOG*`` and ``CHECK`` equivalents with the addition that they append a
|
||||||
|
description of the current state of errno to their output lines. E.g.
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
PCHECK(write(1, NULL, 2) >= 0) << "Write NULL failed";
|
||||||
|
|
||||||
|
This check fails with the following error message.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
F0825 185142 test.cc:22] Check failed: write(1, NULL, 2) >= 0 Write NULL failed: Bad address [14]
|
||||||
|
|
||||||
|
Syslog
|
||||||
|
~~~~~~
|
||||||
|
|
||||||
|
``SYSLOG``, ``SYSLOG_IF``, and ``SYSLOG_EVERY_N`` macros are available.
|
||||||
|
These log to syslog in addition to the normal logs. Be aware that
|
||||||
|
logging to syslog can drastically impact performance, especially if
|
||||||
|
syslog is configured for remote logging! Make sure you understand the
|
||||||
|
implications of outputting to syslog before you use these macros. In
|
||||||
|
general, it’s wise to use these macros sparingly.
|
||||||
|
|
||||||
|
Strip Logging Messages
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Strings used in log messages can increase the size of your binary and
|
||||||
|
present a privacy concern. You can therefore instruct glog to remove all
|
||||||
|
strings which fall below a certain severity level by using the
|
||||||
|
``GOOGLE_STRIP_LOG`` macro:
|
||||||
|
|
||||||
|
If your application has code like this:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
#define GOOGLE_STRIP_LOG 1 // this must go before the #include!
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
The compiler will remove the log messages whose severities are less than
|
||||||
|
the specified integer value. Since ``VLOG`` logs at the severity level
|
||||||
|
``INFO`` (numeric value ``0``), setting ``GOOGLE_STRIP_LOG`` to 1 or
|
||||||
|
greater removes all log messages associated with ``VLOG``\ s as well as
|
||||||
|
``INFO`` log statements.
|
||||||
|
|
||||||
|
Automatically Remove Old Logs
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
To enable the log cleaner:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
google::EnableLogCleaner(3); // keep your logs for 3 days
|
||||||
|
|
||||||
|
And then glog will check if there are overdue logs whenever a flush is
|
||||||
|
performed. In this example, any log file from your project whose last
|
||||||
|
modified time is greater than 3 days will be unlink()ed.
|
||||||
|
|
||||||
|
This feature can be disabled at any time (if it has been enabled)
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
google::DisableLogCleaner();
|
||||||
|
|
||||||
|
Notes for Windows Users
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
glog defines a severity level ``ERROR``, which is also defined in
|
||||||
|
``windows.h`` . You can make glog not define ``INFO``, ``WARNING``,
|
||||||
|
``ERROR``, and ``FATAL`` by defining ``GLOG_NO_ABBREVIATED_SEVERITIES``
|
||||||
|
before including ``glog/logging.h`` . Even with this macro, you can
|
||||||
|
still use the iostream like logging facilities:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
#define GLOG_NO_ABBREVIATED_SEVERITIES
|
||||||
|
#include <windows.h>
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
LOG(ERROR) << "This should work";
|
||||||
|
LOG_IF(ERROR, x > y) << "This should be also OK";
|
||||||
|
|
||||||
|
However, you cannot use ``INFO``, ``WARNING``, ``ERROR``, and ``FATAL``
|
||||||
|
anymore for functions defined in ``glog/logging.h`` .
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
#define GLOG_NO_ABBREVIATED_SEVERITIES
|
||||||
|
#include <windows.h>
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// This won’t work.
|
||||||
|
// google::FlushLogFiles(google::ERROR);
|
||||||
|
|
||||||
|
// Use this instead.
|
||||||
|
google::FlushLogFiles(google::GLOG_ERROR);
|
||||||
|
|
||||||
|
If you don’t need ``ERROR`` defined by ``windows.h``, there are a couple
|
||||||
|
of more workarounds which sometimes don’t work:
|
||||||
|
|
||||||
|
- ``#define WIN32_LEAN_AND_MEAN`` or ``NOGDI`` **before** you
|
||||||
|
``#include windows.h``.
|
||||||
|
- ``#undef ERROR`` **after** you ``#include windows.h`` .
|
||||||
|
|
||||||
|
See `this
|
||||||
|
issue <http://code.google.com/p/google-glog/issues/detail?id=33>`__ for
|
||||||
|
more detail.
|
||||||
|
|
||||||
|
|
||||||
|
Installation Notes for 64-bit Linux Systems
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The glibc built-in stack-unwinder on 64-bit systems has some problems with glog.
|
||||||
|
(In particular, if you are using :cpp:`InstallFailureSignalHandler()`, the
|
||||||
|
signal may be raised in the middle of malloc, holding some malloc-related locks
|
||||||
|
when they invoke the stack unwinder. The built-in stack unwinder may call malloc
|
||||||
|
recursively, which may require the thread to acquire a lock it already holds:
|
||||||
|
deadlock.)
|
||||||
|
|
||||||
|
For that reason, if you use a 64-bit system and you need
|
||||||
|
:cpp:`InstallFailureSignalHandler()`, we strongly recommend you install
|
||||||
|
``libunwind`` before trying to configure or install google glog.
|
||||||
|
libunwind can be found
|
||||||
|
`here <http://download.savannah.nongnu.org/releases/libunwind/libunwind-snap-070410.tar.gz>`__.
|
||||||
|
|
||||||
|
Even if you already have ``libunwind`` installed, you will probably
|
||||||
|
still need to install from the snapshot to get the latest version.
|
||||||
|
|
||||||
|
Caution: if you install libunwind from the URL above, be aware that you
|
||||||
|
may have trouble if you try to statically link your binary with glog:
|
||||||
|
that is, if you link with ``gcc -static -lgcc_eh ...``. This is because
|
||||||
|
both ``libunwind`` and ``libgcc`` implement the same C++ exception
|
||||||
|
handling APIs, but they implement them differently on some platforms.
|
||||||
|
This is not likely to be a problem on ia64, but may be on x86-64.
|
||||||
|
|
||||||
|
Also, if you link binaries statically, make sure that you add
|
||||||
|
:cmd:`-Wl,--eh-frame-hdr` to your linker options. This is required so that
|
||||||
|
``libunwind`` can find the information generated by the compiler required for
|
||||||
|
stack unwinding.
|
||||||
|
|
||||||
|
Using :cmd:`-static` is rare, though, so unless you know this will affect you it
|
||||||
|
probably won’t.
|
||||||
|
|
||||||
|
If you cannot or do not wish to install libunwind, you can still try to
|
||||||
|
use two kinds of stack-unwinder: 1. glibc built-in stack-unwinder and 2.
|
||||||
|
frame pointer based stack-unwinder.
|
||||||
|
|
||||||
|
1. As we already mentioned, glibc’s unwinder has a deadlock issue.
|
||||||
|
However, if you don’t use :cpp:`InstallFailureSignalHandler()` or you
|
||||||
|
don’t worry about the rare possibilities of deadlocks, you can use
|
||||||
|
this stack-unwinder. If you specify no options and ``libunwind``
|
||||||
|
isn’t detected on your system, the configure script chooses this
|
||||||
|
unwinder by default.
|
||||||
|
|
||||||
|
2. The frame pointer based stack unwinder requires that your
|
||||||
|
application, the glog library, and system libraries like libc, all be
|
||||||
|
compiled with a frame pointer. This is *not* the default for x86-64.
|
||||||
|
|
||||||
|
|
||||||
|
How to Contribute
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
We’d love to accept your patches and contributions to this project.
|
||||||
|
There are a just a few small guidelines you need to follow.
|
||||||
|
|
||||||
|
Contributor License Agreement (CLA)
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Contributions to any Google project must be accompanied by a Contributor
|
||||||
|
License Agreement. This is not a copyright **assignment**, it simply
|
||||||
|
gives Google permission to use and redistribute your contributions as
|
||||||
|
part of the project.
|
||||||
|
|
||||||
|
* If you are an individual writing original source code and you’re sure
|
||||||
|
you own the intellectual property, then you’ll need to sign an
|
||||||
|
`individual
|
||||||
|
CLA <https://developers.google.com/open-source/cla/individual>`__.
|
||||||
|
* If you work for a company that wants to allow you to contribute your
|
||||||
|
work, then you’ll need to sign a `corporate
|
||||||
|
CLA <https://developers.google.com/open-source/cla/corporate>`__.
|
||||||
|
|
||||||
|
You generally only need to submit a CLA once, so if you’ve already
|
||||||
|
submitted one (even if it was for a different project), you probably
|
||||||
|
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 <./AUTHORS>`__ and `CONTRIBUTORS <./CONTRIBUTORS>`__ files. This
|
||||||
|
commit can be part of your first `pull
|
||||||
|
request <https://help.github.com/articles/creating-a-pull-request>`__.
|
||||||
|
|
||||||
|
Submitting a Patch
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
1. It’s generally best to start by opening a new issue describing the
|
||||||
|
bug or feature you’re intending to fix. Even if you think it’s
|
||||||
|
relatively minor, it’s helpful to know what people are working on.
|
||||||
|
Mention in the initial issue that you are planning to work on that
|
||||||
|
bug or feature so that it can be assigned to you.
|
||||||
|
2. Follow the normal process of
|
||||||
|
`forking <https://help.github.com/articles/fork-a-repo>`__ the
|
||||||
|
project, and setup a new branch to work in. It’s important that each
|
||||||
|
group of changes be done in separate branches in order to ensure that
|
||||||
|
a pull request only includes the commits related to that bug or
|
||||||
|
feature.
|
||||||
|
3. Do your best to have `well-formed commit
|
||||||
|
messages <http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html>`__
|
||||||
|
for each change. This provides consistency throughout the project,
|
||||||
|
and ensures that commit messages are able to be formatted properly by
|
||||||
|
various git tools.
|
||||||
|
4. Finally, push the commits to your fork and submit a `pull
|
||||||
|
request <https://help.github.com/articles/creating-a-pull-request>`__.
|
||||||
|
|
||||||
|
|
||||||
.. |Linux Github actions| image:: https://github.com/google/glog/actions/workflows/linux.yml/badge.svg
|
.. |Linux Github actions| image:: https://github.com/google/glog/actions/workflows/linux.yml/badge.svg
|
||||||
@ -19,5 +871,9 @@ Please refer to project's `documentation <https://google.github.io/glog/>`_.
|
|||||||
:target: https://github.com/google/glog/actions
|
:target: https://github.com/google/glog/actions
|
||||||
.. |macOS Github actions| image:: https://github.com/google/glog/actions/workflows/macos.yml/badge.svg
|
.. |macOS Github actions| image:: https://github.com/google/glog/actions/workflows/macos.yml/badge.svg
|
||||||
:target: https://github.com/google/glog/actions
|
:target: https://github.com/google/glog/actions
|
||||||
|
.. |Total alerts| image:: https://img.shields.io/lgtm/alerts/g/google/glog.svg?logo=lgtm&logoWidth=18
|
||||||
|
:target: https://lgtm.com/projects/g/google/glog/alerts/
|
||||||
|
.. |Language grade: C++| image:: https://img.shields.io/lgtm/grade/cpp/g/google/glog.svg?logo=lgtm&logoWidth=18)
|
||||||
|
:target: https://lgtm.com/projects/g/google/glog/context:cpp
|
||||||
.. |Codecov| image:: https://codecov.io/gh/google/glog/branch/master/graph/badge.svg?token=8an420vNju
|
.. |Codecov| image:: https://codecov.io/gh/google/glog/branch/master/graph/badge.svg?token=8an420vNju
|
||||||
:target: https://codecov.io/gh/google/glog
|
:target: https://codecov.io/gh/google/glog
|
||||||
|
|||||||
11
WORKSPACE
Normal file
11
WORKSPACE
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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",
|
||||||
|
],
|
||||||
|
)
|
||||||
@ -1 +0,0 @@
|
|||||||
# WORKSPACE marker file needed by Bazel
|
|
||||||
@ -4,6 +4,6 @@ cc_test(
|
|||||||
srcs = ["main.cc"],
|
srcs = ["main.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
"//:glog",
|
"//:glog",
|
||||||
"@gflags//:gflags",
|
"@com_github_gflags_gflags//:gflags",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
260
bazel/glog.bzl
260
bazel/glog.bzl
@ -25,9 +25,15 @@ expand_template = rule(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def glog_library(with_gflags = 1, **kwargs):
|
def dict_union(x, y):
|
||||||
|
z = {}
|
||||||
|
z.update(x)
|
||||||
|
z.update(y)
|
||||||
|
return z
|
||||||
|
|
||||||
|
def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
||||||
if native.repository_name() != "@":
|
if native.repository_name() != "@":
|
||||||
repo_name = native.repository_name()[1:] # Strip the first leading @
|
repo_name = native.repository_name().lstrip("@")
|
||||||
gendir = "$(GENDIR)/external/" + repo_name
|
gendir = "$(GENDIR)/external/" + repo_name
|
||||||
src_windows = "external/%s/src/windows" % repo_name
|
src_windows = "external/%s/src/windows" % repo_name
|
||||||
else:
|
else:
|
||||||
@ -40,16 +46,16 @@ def glog_library(with_gflags = 1, **kwargs):
|
|||||||
values = {"cpu": "wasm"},
|
values = {"cpu": "wasm"},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Detect when building with clang-cl on Windows.
|
|
||||||
native.config_setting(
|
|
||||||
name = "clang-cl",
|
|
||||||
values = {"compiler": "clang-cl"},
|
|
||||||
)
|
|
||||||
|
|
||||||
common_copts = [
|
common_copts = [
|
||||||
"-std=c++14",
|
"-DGLOG_BAZEL_BUILD",
|
||||||
|
# Inject a C++ namespace.
|
||||||
|
"-DGOOGLE_NAMESPACE='%s'" % namespace,
|
||||||
|
"-DHAVE_CXX11_NULLPTR_T",
|
||||||
|
"-DHAVE_STDINT_H",
|
||||||
|
"-DHAVE_STRING_H",
|
||||||
|
"-DGLOG_CUSTOM_PREFIX_SUPPORT",
|
||||||
"-I%s/glog_internal" % gendir,
|
"-I%s/glog_internal" % gendir,
|
||||||
] + (["-DGLOG_USE_GFLAGS"] if with_gflags else [])
|
] + (["-DHAVE_LIB_GFLAGS"] if with_gflags else [])
|
||||||
|
|
||||||
wasm_copts = [
|
wasm_copts = [
|
||||||
# Disable warnings that exists in glog.
|
# Disable warnings that exists in glog.
|
||||||
@ -57,32 +63,26 @@ def glog_library(with_gflags = 1, **kwargs):
|
|||||||
"-Wno-unused-function",
|
"-Wno-unused-function",
|
||||||
"-Wno-unused-local-typedefs",
|
"-Wno-unused-local-typedefs",
|
||||||
"-Wno-unused-variable",
|
"-Wno-unused-variable",
|
||||||
|
# Allows src/base/mutex.h to include pthread.h.
|
||||||
|
"-DHAVE_PTHREAD",
|
||||||
# Allows src/logging.cc to determine the host name.
|
# Allows src/logging.cc to determine the host name.
|
||||||
"-DHAVE_SYS_UTSNAME_H",
|
"-DHAVE_SYS_UTSNAME_H",
|
||||||
# For src/utilities.cc.
|
# For src/utilities.cc.
|
||||||
"-DHAVE_SYS_TIME_H",
|
"-DHAVE_SYS_TIME_H",
|
||||||
# NOTE: users could optionally patch -DHAVE_UNWIND off if
|
"-DHAVE_UNWIND_H",
|
||||||
# stacktrace dumping is not needed
|
|
||||||
"-DHAVE_UNWIND",
|
|
||||||
# Enable dumping stacktrace upon sigaction.
|
# Enable dumping stacktrace upon sigaction.
|
||||||
"-DHAVE_SIGACTION",
|
"-DHAVE_SIGACTION",
|
||||||
# For logging.cc.
|
# For logging.cc.
|
||||||
"-DHAVE_PREAD",
|
"-DHAVE_PREAD",
|
||||||
# -DHAVE_MODE_T prevent repeated typedef mode_t leading
|
"-DHAVE___ATTRIBUTE__",
|
||||||
# to emcc compilation failure
|
|
||||||
"-DHAVE_MODE_T",
|
|
||||||
"-DHAVE_UNISTD_H",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
linux_or_darwin_copts = wasm_copts + [
|
linux_or_darwin_copts = wasm_copts + [
|
||||||
"-DGLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
|
"-DGLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
|
||||||
"-DGLOG_NO_EXPORT=__attribute__((visibility(\\\"default\\\")))",
|
|
||||||
"-DHAVE_POSIX_FADVISE",
|
|
||||||
"-DHAVE_SSIZE_T",
|
|
||||||
"-DHAVE_SYS_TYPES_H",
|
|
||||||
# For src/utilities.cc.
|
# For src/utilities.cc.
|
||||||
"-DHAVE_SYS_SYSCALL_H",
|
"-DHAVE_SYS_SYSCALL_H",
|
||||||
# For src/logging.cc to create symlinks.
|
# For src/logging.cc to create symlinks.
|
||||||
|
"-DHAVE_UNISTD_H",
|
||||||
"-fvisibility-inlines-hidden",
|
"-fvisibility-inlines-hidden",
|
||||||
"-fvisibility=hidden",
|
"-fvisibility=hidden",
|
||||||
]
|
]
|
||||||
@ -90,97 +90,44 @@ def glog_library(with_gflags = 1, **kwargs):
|
|||||||
freebsd_only_copts = [
|
freebsd_only_copts = [
|
||||||
# Enable declaration of _Unwind_Backtrace
|
# Enable declaration of _Unwind_Backtrace
|
||||||
"-D_GNU_SOURCE",
|
"-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 = [
|
darwin_only_copts = [
|
||||||
# For stacktrace.
|
# For stacktrace.
|
||||||
"-DHAVE_DLADDR",
|
"-DHAVE_DLADDR",
|
||||||
|
# Avoid deprecated syscall().
|
||||||
|
"-DHAVE_PTHREAD_THREADID_NP",
|
||||||
]
|
]
|
||||||
|
|
||||||
windows_only_copts = [
|
windows_only_copts = [
|
||||||
# Override -DGLOG_EXPORT= from the cc_library's defines.
|
|
||||||
"-DGLOG_EXPORT=__declspec(dllexport)",
|
"-DGLOG_EXPORT=__declspec(dllexport)",
|
||||||
"-DGLOG_NO_ABBREVIATED_SEVERITIES",
|
"-DGLOG_NO_ABBREVIATED_SEVERITIES",
|
||||||
"-DGLOG_NO_EXPORT=",
|
"-DHAVE_SNPRINTF",
|
||||||
"-DGLOG_USE_WINDOWS_PORT",
|
|
||||||
"-DHAVE__CHSIZE_S",
|
|
||||||
"-DHAVE_DBGHELP",
|
|
||||||
"-I" + src_windows,
|
"-I" + src_windows,
|
||||||
]
|
]
|
||||||
|
|
||||||
clang_cl_only_copts = [
|
|
||||||
# Allow the override of -DGLOG_EXPORT.
|
|
||||||
"-Wno-macro-redefined",
|
|
||||||
]
|
|
||||||
|
|
||||||
windows_only_srcs = [
|
windows_only_srcs = [
|
||||||
|
"src/glog/log_severity.h",
|
||||||
"src/windows/dirent.h",
|
"src/windows/dirent.h",
|
||||||
"src/windows/port.cc",
|
"src/windows/port.cc",
|
||||||
"src/windows/port.h",
|
"src/windows/port.h",
|
||||||
]
|
]
|
||||||
|
|
||||||
gflags_deps = ["@gflags//:gflags"] if with_gflags else []
|
gflags_deps = ["@com_github_gflags_gflags//:gflags"] if with_gflags else []
|
||||||
|
|
||||||
final_lib_defines = select({
|
|
||||||
# GLOG_EXPORT is normally set by export.h, but that's not
|
|
||||||
# generated for Bazel.
|
|
||||||
"@bazel_tools//src/conditions:windows": [
|
|
||||||
"GLOG_DEPRECATED=__declspec(deprecated)",
|
|
||||||
"GLOG_EXPORT=",
|
|
||||||
"GLOG_NO_ABBREVIATED_SEVERITIES",
|
|
||||||
"GLOG_NO_EXPORT=",
|
|
||||||
],
|
|
||||||
"//conditions:default": [
|
|
||||||
"GLOG_DEPRECATED=__attribute__((deprecated))",
|
|
||||||
"GLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
|
|
||||||
"GLOG_NO_EXPORT=__attribute__((visibility(\\\"default\\\")))",
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
final_lib_copts = select({
|
|
||||||
"@bazel_tools//src/conditions:windows": common_copts + windows_only_copts,
|
|
||||||
"@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts,
|
|
||||||
"@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
|
|
||||||
":wasm": common_copts + wasm_copts,
|
|
||||||
"//conditions:default": common_copts + linux_or_darwin_copts + linux_only_copts,
|
|
||||||
}) + select({
|
|
||||||
":clang-cl": clang_cl_only_copts,
|
|
||||||
"//conditions:default": [],
|
|
||||||
})
|
|
||||||
|
|
||||||
# Needed to use these headers in `glog` and the test targets without exposing them as public targets in `glog`
|
|
||||||
native.filegroup(
|
|
||||||
name = "shared_headers",
|
|
||||||
srcs = [
|
|
||||||
"src/base/commandlineflags.h",
|
|
||||||
"src/stacktrace.h",
|
|
||||||
"src/utilities.h",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
native.cc_library(
|
native.cc_library(
|
||||||
name = "glog",
|
name = "glog",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
srcs = [
|
srcs = [
|
||||||
":config_h",
|
":config_h",
|
||||||
":shared_headers",
|
"src/base/commandlineflags.h",
|
||||||
"src/base/googleinit.h",
|
"src/base/googleinit.h",
|
||||||
|
"src/base/mutex.h",
|
||||||
"src/demangle.cc",
|
"src/demangle.cc",
|
||||||
"src/demangle.h",
|
"src/demangle.h",
|
||||||
"src/flags.cc",
|
|
||||||
"src/logging.cc",
|
"src/logging.cc",
|
||||||
"src/raw_logging.cc",
|
"src/raw_logging.cc",
|
||||||
"src/signalhandler.cc",
|
"src/signalhandler.cc",
|
||||||
"src/stacktrace.cc",
|
|
||||||
"src/stacktrace.h",
|
"src/stacktrace.h",
|
||||||
"src/stacktrace_generic-inl.h",
|
"src/stacktrace_generic-inl.h",
|
||||||
"src/stacktrace_libunwind-inl.h",
|
"src/stacktrace_libunwind-inl.h",
|
||||||
@ -198,87 +145,52 @@ def glog_library(with_gflags = 1, **kwargs):
|
|||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"src/glog/flags.h",
|
|
||||||
"src/glog/log_severity.h",
|
"src/glog/log_severity.h",
|
||||||
"src/glog/logging.h",
|
|
||||||
"src/glog/platform.h",
|
"src/glog/platform.h",
|
||||||
"src/glog/raw_logging.h",
|
":logging_h",
|
||||||
"src/glog/stl_logging.h",
|
":raw_logging_h",
|
||||||
"src/glog/types.h",
|
":stl_logging_h",
|
||||||
"src/glog/vlog_is_on.h",
|
":vlog_is_on_h",
|
||||||
],
|
],
|
||||||
# https://github.com/google/glog/issues/837: Replacing
|
|
||||||
# `strip_include_prefix` with `includes` would avoid spamming
|
|
||||||
# downstream projects with compiler warnings, but would also leak
|
|
||||||
# private headers like stacktrace.h, because strip_include_prefix's
|
|
||||||
# implementation only creates symlinks for the public hdrs. I suspect
|
|
||||||
# the only way to avoid this is to refactor the project including the
|
|
||||||
# CMake build, so that the private headers are in a glog_internal
|
|
||||||
# subdirectory.
|
|
||||||
strip_include_prefix = "src",
|
strip_include_prefix = "src",
|
||||||
defines = final_lib_defines,
|
defines = select({
|
||||||
copts = final_lib_copts,
|
# GLOG_EXPORT is normally set by export.h, but that's not
|
||||||
|
# generated for Bazel.
|
||||||
|
"@bazel_tools//src/conditions:windows": [
|
||||||
|
"GLOG_EXPORT=",
|
||||||
|
"GLOG_DEPRECATED=__declspec(deprecated)",
|
||||||
|
"GLOG_NO_ABBREVIATED_SEVERITIES",
|
||||||
|
],
|
||||||
|
"//conditions:default": [
|
||||||
|
"GLOG_DEPRECATED=__attribute__((deprecated))",
|
||||||
|
"GLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
copts =
|
||||||
|
select({
|
||||||
|
"@bazel_tools//src/conditions:windows": common_copts + windows_only_copts,
|
||||||
|
"@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts,
|
||||||
|
"@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
|
||||||
|
":wasm": common_copts + wasm_copts,
|
||||||
|
"//conditions:default": common_copts + linux_or_darwin_copts,
|
||||||
|
}),
|
||||||
deps = gflags_deps + select({
|
deps = gflags_deps + select({
|
||||||
"@bazel_tools//src/conditions:windows": [":strip_include_prefix_hack"],
|
"@bazel_tools//src/conditions:windows": [":strip_include_prefix_hack"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
linkopts = select({
|
|
||||||
"@bazel_tools//src/conditions:windows": ["dbghelp.lib"],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
test_list = [
|
|
||||||
"cleanup_immediately",
|
|
||||||
"cleanup_with_absolute_prefix",
|
|
||||||
"cleanup_with_relative_prefix",
|
|
||||||
# "demangle", # Broken
|
|
||||||
# "logging", # Broken
|
|
||||||
# "mock-log", # Broken
|
|
||||||
# "signalhandler", # Pointless
|
|
||||||
"stacktrace",
|
|
||||||
"stl_logging",
|
|
||||||
# "symbolize", # Broken
|
|
||||||
"utilities",
|
|
||||||
]
|
|
||||||
|
|
||||||
test_only_copts = [
|
|
||||||
"-DTEST_SRC_DIR=\\\"%s/tests\\\"" % gendir,
|
|
||||||
]
|
|
||||||
|
|
||||||
for test_name in test_list:
|
|
||||||
native.cc_test(
|
|
||||||
name = test_name + "_test",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
srcs = [
|
|
||||||
":config_h",
|
|
||||||
":shared_headers",
|
|
||||||
"src/googletest.h",
|
|
||||||
"src/" + test_name + "_unittest.cc",
|
|
||||||
],
|
|
||||||
defines = final_lib_defines,
|
|
||||||
copts = final_lib_copts + test_only_copts,
|
|
||||||
deps = gflags_deps + [
|
|
||||||
":glog",
|
|
||||||
"@googletest//:gtest",
|
|
||||||
],
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
# Workaround https://github.com/bazelbuild/bazel/issues/6337 by declaring
|
# Workaround https://github.com/bazelbuild/bazel/issues/6337 by declaring
|
||||||
# the dependencies without strip_include_prefix.
|
# the dependencies without strip_include_prefix.
|
||||||
native.cc_library(
|
native.cc_library(
|
||||||
name = "strip_include_prefix_hack",
|
name = "strip_include_prefix_hack",
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"src/glog/flags.h",
|
|
||||||
"src/glog/log_severity.h",
|
"src/glog/log_severity.h",
|
||||||
"src/glog/logging.h",
|
":logging_h",
|
||||||
"src/glog/platform.h",
|
":raw_logging_h",
|
||||||
"src/glog/raw_logging.h",
|
":stl_logging_h",
|
||||||
"src/glog/stl_logging.h",
|
":vlog_is_on_h",
|
||||||
"src/glog/types.h",
|
|
||||||
"src/glog/vlog_is_on.h",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -288,3 +200,61 @@ def glog_library(with_gflags = 1, **kwargs):
|
|||||||
out = "glog_internal/config.h",
|
out = "glog_internal/config.h",
|
||||||
substitutions = {"#cmakedefine": "//cmakedefine"},
|
substitutions = {"#cmakedefine": "//cmakedefine"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
common_config = {
|
||||||
|
"@ac_cv_cxx11_atomic@": "1",
|
||||||
|
"@ac_cv_cxx11_constexpr@": "1",
|
||||||
|
"@ac_cv_cxx11_chrono@": "1",
|
||||||
|
"@ac_cv_cxx11_nullptr_t@": "1",
|
||||||
|
"@ac_cv_cxx_using_operator@": "1",
|
||||||
|
"@ac_cv_have_inttypes_h@": "0",
|
||||||
|
"@ac_cv_have_u_int16_t@": "0",
|
||||||
|
"@ac_cv_have_glog_export@": "0",
|
||||||
|
"@ac_google_start_namespace@": "namespace google {",
|
||||||
|
"@ac_google_end_namespace@": "}",
|
||||||
|
"@ac_google_namespace@": "google",
|
||||||
|
}
|
||||||
|
|
||||||
|
posix_config = dict_union(common_config, {
|
||||||
|
"@ac_cv_have_unistd_h@": "1",
|
||||||
|
"@ac_cv_have_stdint_h@": "1",
|
||||||
|
"@ac_cv_have_systypes_h@": "1",
|
||||||
|
"@ac_cv_have_uint16_t@": "1",
|
||||||
|
"@ac_cv_have___uint16@": "0",
|
||||||
|
"@ac_cv_have___builtin_expect@": "1",
|
||||||
|
"@ac_cv_have_libgflags@": "1" if with_gflags else "0",
|
||||||
|
"@ac_cv___attribute___noinline@": "__attribute__((noinline))",
|
||||||
|
"@ac_cv___attribute___noreturn@": "__attribute__((noreturn))",
|
||||||
|
"@ac_cv___attribute___printf_4_5@": "__attribute__((__format__(__printf__, 4, 5)))",
|
||||||
|
})
|
||||||
|
|
||||||
|
windows_config = dict_union(common_config, {
|
||||||
|
"@ac_cv_have_unistd_h@": "0",
|
||||||
|
"@ac_cv_have_stdint_h@": "0",
|
||||||
|
"@ac_cv_have_systypes_h@": "0",
|
||||||
|
"@ac_cv_have_uint16_t@": "0",
|
||||||
|
"@ac_cv_have___uint16@": "1",
|
||||||
|
"@ac_cv_have___builtin_expect@": "0",
|
||||||
|
"@ac_cv_have_libgflags@": "0",
|
||||||
|
"@ac_cv___attribute___noinline@": "",
|
||||||
|
"@ac_cv___attribute___noreturn@": "__declspec(noreturn)",
|
||||||
|
"@ac_cv___attribute___printf_4_5@": "",
|
||||||
|
})
|
||||||
|
|
||||||
|
[
|
||||||
|
expand_template(
|
||||||
|
name = "%s_h" % f,
|
||||||
|
template = "src/glog/%s.h.in" % f,
|
||||||
|
out = "src/glog/%s.h" % f,
|
||||||
|
substitutions = select({
|
||||||
|
"@bazel_tools//src/conditions:windows": windows_config,
|
||||||
|
"//conditions:default": posix_config,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
for f in [
|
||||||
|
"vlog_is_on",
|
||||||
|
"stl_logging",
|
||||||
|
"raw_logging",
|
||||||
|
"logging",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
cmake_policy (PUSH)
|
cmake_policy (PUSH)
|
||||||
cmake_policy (VERSION 3.16...3.27)
|
cmake_policy (VERSION 3.3)
|
||||||
|
|
||||||
include (CMakeParseArguments)
|
include (CMakeParseArguments)
|
||||||
|
|
||||||
|
|||||||
@ -7,20 +7,16 @@ foreach (iter RANGE 1 ${RUNS})
|
|||||||
if (NOT _RESULT EQUAL 0)
|
if (NOT _RESULT EQUAL 0)
|
||||||
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
||||||
endif (NOT _RESULT EQUAL 0)
|
endif (NOT _RESULT EQUAL 0)
|
||||||
|
|
||||||
|
# Ensure the log files to have different modification timestamps such that
|
||||||
|
# exactly one log file remains at the end. Otherwise all log files will be
|
||||||
|
# retained.
|
||||||
|
execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 1)
|
||||||
endforeach (iter)
|
endforeach (iter)
|
||||||
|
|
||||||
file (GLOB LOG_FILES ${TEST_DIR}/*.foobar)
|
file (GLOB LOG_FILES ${TEST_DIR}/*.foobar)
|
||||||
list (LENGTH LOG_FILES NUM_FILES)
|
list (LENGTH LOG_FILES NUM_FILES)
|
||||||
|
|
||||||
if (WIN32)
|
if (NOT NUM_FILES EQUAL 1)
|
||||||
# On Windows open files cannot be removed and will result in a permission
|
message (SEND_ERROR "Expected 1 log file in log directory but found ${NUM_FILES}")
|
||||||
# denied error while unlinking such file. Therefore, the last file will be
|
endif (NOT NUM_FILES EQUAL 1)
|
||||||
# retained.
|
|
||||||
set (_expected 1)
|
|
||||||
else (WIN32)
|
|
||||||
set (_expected 0)
|
|
||||||
endif (WIN32)
|
|
||||||
|
|
||||||
if (NOT NUM_FILES EQUAL _expected)
|
|
||||||
message (SEND_ERROR "Expected ${_expected} log file in log directory but found ${NUM_FILES}")
|
|
||||||
endif (NOT NUM_FILES EQUAL _expected)
|
|
||||||
|
|||||||
@ -7,20 +7,16 @@ foreach (iter RANGE 1 ${RUNS})
|
|||||||
if (NOT _RESULT EQUAL 0)
|
if (NOT _RESULT EQUAL 0)
|
||||||
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
||||||
endif (NOT _RESULT EQUAL 0)
|
endif (NOT _RESULT EQUAL 0)
|
||||||
|
|
||||||
|
# Ensure the log files to have different modification timestamps such that
|
||||||
|
# exactly one log file remains at the end. Otherwise all log files will be
|
||||||
|
# retained.
|
||||||
|
execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 1)
|
||||||
endforeach (iter)
|
endforeach (iter)
|
||||||
|
|
||||||
file (GLOB LOG_FILES ${TEST_DIR}/test_cleanup_*.barfoo)
|
file (GLOB LOG_FILES ${TEST_DIR}/test_cleanup_*.barfoo)
|
||||||
list (LENGTH LOG_FILES NUM_FILES)
|
list (LENGTH LOG_FILES NUM_FILES)
|
||||||
|
|
||||||
if (WIN32)
|
if (NOT NUM_FILES EQUAL 1)
|
||||||
# On Windows open files cannot be removed and will result in a permission
|
message (SEND_ERROR "Expected 1 log file in build directory ${TEST_DIR} but found ${NUM_FILES}")
|
||||||
# denied error while unlinking such file. Therefore, the last file will be
|
endif (NOT NUM_FILES EQUAL 1)
|
||||||
# retained.
|
|
||||||
set (_expected 1)
|
|
||||||
else (WIN32)
|
|
||||||
set (_expected 0)
|
|
||||||
endif (WIN32)
|
|
||||||
|
|
||||||
if (NOT NUM_FILES EQUAL _expected)
|
|
||||||
message (SEND_ERROR "Expected ${_expected} log file in log directory but found ${NUM_FILES}")
|
|
||||||
endif (NOT NUM_FILES EQUAL _expected)
|
|
||||||
|
|||||||
@ -10,23 +10,19 @@ foreach (iter RANGE 1 ${RUNS})
|
|||||||
if (NOT _RESULT EQUAL 0)
|
if (NOT _RESULT EQUAL 0)
|
||||||
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
||||||
endif (NOT _RESULT EQUAL 0)
|
endif (NOT _RESULT EQUAL 0)
|
||||||
|
|
||||||
|
# Ensure the log files to have different modification timestamps such that
|
||||||
|
# exactly one log file remains at the end. Otherwise all log files will be
|
||||||
|
# retained.
|
||||||
|
execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 2)
|
||||||
endforeach (iter)
|
endforeach (iter)
|
||||||
|
|
||||||
file (GLOB LOG_FILES ${TEST_DIR}/${TEST_SUBDIR}/test_cleanup_*.relativefoo)
|
file (GLOB LOG_FILES ${TEST_DIR}/${TEST_SUBDIR}/test_cleanup_*.relativefoo)
|
||||||
list (LENGTH LOG_FILES NUM_FILES)
|
list (LENGTH LOG_FILES NUM_FILES)
|
||||||
|
|
||||||
if (WIN32)
|
if (NOT NUM_FILES EQUAL 1)
|
||||||
# On Windows open files cannot be removed and will result in a permission
|
message (SEND_ERROR "Expected 1 log file in build directory ${TEST_DIR}${TEST_SUBDIR} but found ${NUM_FILES}")
|
||||||
# denied error while unlinking such file. Therefore, the last file will be
|
endif (NOT NUM_FILES EQUAL 1)
|
||||||
# retained.
|
|
||||||
set (_expected 1)
|
|
||||||
else (WIN32)
|
|
||||||
set (_expected 0)
|
|
||||||
endif (WIN32)
|
|
||||||
|
|
||||||
if (NOT NUM_FILES EQUAL _expected)
|
|
||||||
message (SEND_ERROR "Expected ${_expected} log file in build directory ${TEST_DIR}${TEST_SUBDIR} but found ${NUM_FILES}")
|
|
||||||
endif (NOT NUM_FILES EQUAL _expected)
|
|
||||||
|
|
||||||
# Remove the subdirectory required by this unit test.
|
# Remove the subdirectory required by this unit test.
|
||||||
file (REMOVE_RECURSE ${TEST_DIR}/${TEST_SUBDIR})
|
file (REMOVE_RECURSE ${TEST_DIR}/${TEST_SUBDIR})
|
||||||
|
|||||||
@ -1,3 +1,13 @@
|
|||||||
|
# Create the build directory
|
||||||
|
execute_process (
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
|
||||||
|
RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
|
||||||
|
message (FATAL_ERROR "Failed to create build directory")
|
||||||
|
endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
|
||||||
|
|
||||||
if (GENERATOR_TOOLSET)
|
if (GENERATOR_TOOLSET)
|
||||||
list (APPEND _ADDITIONAL_ARGS -T ${GENERATOR_TOOLSET})
|
list (APPEND _ADDITIONAL_ARGS -T ${GENERATOR_TOOLSET})
|
||||||
endif (GENERATOR_TOOLSET)
|
endif (GENERATOR_TOOLSET)
|
||||||
@ -11,7 +21,7 @@ execute_process (
|
|||||||
# Capture the PATH environment variable content set during project generation
|
# Capture the PATH environment variable content set during project generation
|
||||||
# stage. This is required because later during the build stage the PATH is
|
# stage. This is required because later during the build stage the PATH is
|
||||||
# modified again (e.g., for MinGW AppVeyor CI builds) by adding back the
|
# modified again (e.g., for MinGW AppVeyor CI builds) by adding back the
|
||||||
# directory containing git.exe. Incidentally, the Git installation directory
|
# directory containing git.exe. Incidently, the Git installation directory
|
||||||
# also contains sh.exe which causes MinGW Makefile generation to fail.
|
# also contains sh.exe which causes MinGW Makefile generation to fail.
|
||||||
COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH}
|
COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH}
|
||||||
${CMAKE_COMMAND} -C ${INITIAL_CACHE}
|
${CMAKE_COMMAND} -C ${INITIAL_CACHE}
|
||||||
@ -19,9 +29,9 @@ execute_process (
|
|||||||
${_ADDITIONAL_ARGS}
|
${_ADDITIONAL_ARGS}
|
||||||
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
|
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
|
||||||
-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON
|
-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON
|
||||||
-Dglog_ROOT=${PACKAGE_DIR}
|
-DCMAKE_PREFIX_PATH=${PACKAGE_DIR}
|
||||||
-S ${SOURCE_DIR}
|
${SOURCE_DIR}
|
||||||
-B ${TEST_BINARY_DIR}
|
WORKING_DIRECTORY ${TEST_BINARY_DIR}
|
||||||
RESULT_VARIABLE _GENERATE_SUCCEEDED
|
RESULT_VARIABLE _GENERATE_SUCCEEDED
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
11
codecov.yml
11
codecov.yml
@ -1,11 +0,0 @@
|
|||||||
comment:
|
|
||||||
layout: "diff, flags, files"
|
|
||||||
behavior: default
|
|
||||||
require_changes: false
|
|
||||||
require_base: false
|
|
||||||
require_head: true
|
|
||||||
ignore:
|
|
||||||
- "**/*_unittest.cc"
|
|
||||||
- "src/*_unittest/**"
|
|
||||||
- "src/googletest.h"
|
|
||||||
- "src/mock-log.h"
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
# Building from Source
|
|
||||||
|
|
||||||
## Bazel
|
|
||||||
|
|
||||||
To use glog within a project which uses the [Bazel](https://bazel.build/) build
|
|
||||||
tool, add the following lines to your `MODULE.bazel` file:
|
|
||||||
|
|
||||||
``` bazel title="MODULE.bazel"
|
|
||||||
bazel_dep(name = "glog")
|
|
||||||
|
|
||||||
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 `@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.
|
|
||||||
|
|
||||||
!!! example "Using glog in a Bazel project"
|
|
||||||
``` bazel
|
|
||||||
cc_binary(
|
|
||||||
name = "main",
|
|
||||||
srcs = ["main.cc"],
|
|
||||||
deps = ["@glog//:glog"],
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
## CMake
|
|
||||||
|
|
||||||
glog can be compiled using [CMake](http://www.cmake.org) on a wide range of
|
|
||||||
platforms. The typical workflow for building glog on a Unix-like system with GNU
|
|
||||||
Make as build tool is as follows:
|
|
||||||
|
|
||||||
1. Clone the repository and change into source directory.
|
|
||||||
``` bash
|
|
||||||
git clone https://github.com/google/glog.git
|
|
||||||
cd glog
|
|
||||||
```
|
|
||||||
2. Run CMake to configure the build tree.
|
|
||||||
``` bash
|
|
||||||
cmake -S . -B build -G "Unix Makefiles"
|
|
||||||
```
|
|
||||||
CMake provides different generators, and by default will pick the most
|
|
||||||
relevant one to your environment. If you need a specific version of Visual
|
|
||||||
Studio, use `#!bash cmake . -G <generator-name>`, and see `#!bash cmake
|
|
||||||
--help` for the available generators. Also see `-T <toolset-name>`, which can
|
|
||||||
be used to request the native x64 toolchain with `-T host=x64`.
|
|
||||||
3. Afterwards, generated files can be used to compile the project.
|
|
||||||
``` bash
|
|
||||||
cmake --build build
|
|
||||||
```
|
|
||||||
4. Test the build software (optional).
|
|
||||||
``` bash
|
|
||||||
cmake --build build --target test
|
|
||||||
```
|
|
||||||
5. Install the built files (optional).
|
|
||||||
``` bash
|
|
||||||
cmake --build build --target install
|
|
||||||
```
|
|
||||||
|
|
||||||
Once successfully built, glog can be [integrated into own projects](usage.md).
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
# How to Contribute
|
|
||||||
|
|
||||||
We'd love to accept your patches and contributions to this project.
|
|
||||||
There are a just a few small guidelines you need to follow.
|
|
||||||
|
|
||||||
## Contributor License Agreement (CLA)
|
|
||||||
|
|
||||||
Contributions to any Google project must be accompanied by a Contributor
|
|
||||||
License Agreement. This is not a copyright **assignment**, it simply
|
|
||||||
gives Google permission to use and redistribute your contributions as
|
|
||||||
part of the project.
|
|
||||||
|
|
||||||
- If you are an individual writing original source code and you're
|
|
||||||
sure you own the intellectual property, then you'll need to sign an
|
|
||||||
[individual
|
|
||||||
CLA](https://developers.google.com/open-source/cla/individual).
|
|
||||||
- If you work for a company that wants to allow you to contribute your
|
|
||||||
work, then you'll need to sign a [corporate
|
|
||||||
CLA](https://developers.google.com/open-source/cla/corporate).
|
|
||||||
|
|
||||||
You generally only need to submit a CLA once, so if you've already
|
|
||||||
submitted one (even if it was for a different project), you probably
|
|
||||||
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/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).
|
|
||||||
|
|
||||||
## Submitting a Patch
|
|
||||||
|
|
||||||
1. It's generally best to start by opening a new issue describing the
|
|
||||||
bug or feature you're intending to fix. Even if you think it's
|
|
||||||
relatively minor, it's helpful to know what people are working on.
|
|
||||||
Mention in the initial issue that you are planning to work on that
|
|
||||||
bug or feature so that it can be assigned to you.
|
|
||||||
2. Follow the normal process of
|
|
||||||
[forking](https://help.github.com/articles/fork-a-repo) the project,
|
|
||||||
and setup a new branch to work in. It's important that each group of
|
|
||||||
changes be done in separate branches in order to ensure that a pull
|
|
||||||
request only includes the commits related to that bug or feature.
|
|
||||||
3. Do your best to have [well-formed commit
|
|
||||||
messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
|
||||||
for each change. This provides consistency throughout the project,
|
|
||||||
and ensures that commit messages are able to be formatted properly
|
|
||||||
by various git tools.
|
|
||||||
4. Finally, push the commits to your fork and submit a [pull
|
|
||||||
request](https://help.github.com/articles/creating-a-pull-request).
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
# Failure Signal Handler
|
|
||||||
|
|
||||||
## Stacktrace as Default Failure Handler
|
|
||||||
|
|
||||||
The library provides a convenient signal handler that will dump useful
|
|
||||||
information when the program crashes on certain signals such as `SIGSEGV`. The
|
|
||||||
signal handler can be installed by `#!cpp
|
|
||||||
google::InstallFailureSignalHandler()`. The following is an example of output
|
|
||||||
from the signal handler.
|
|
||||||
|
|
||||||
*** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date ***
|
|
||||||
*** SIGSEGV (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: ***
|
|
||||||
PC: @ 0x412eb1 TestWaitingLogSink::send()
|
|
||||||
@ 0x7f892fb417d0 (unknown)
|
|
||||||
@ 0x412eb1 TestWaitingLogSink::send()
|
|
||||||
@ 0x7f89304f7f06 google::LogMessage::SendToLog()
|
|
||||||
@ 0x7f89304f35af google::LogMessage::Flush()
|
|
||||||
@ 0x7f89304f3739 google::LogMessage::~LogMessage()
|
|
||||||
@ 0x408cf4 TestLogSinkWaitTillSent()
|
|
||||||
@ 0x4115de main
|
|
||||||
@ 0x7f892f7ef1c4 (unknown)
|
|
||||||
@ 0x4046f9 (unknown)
|
|
||||||
|
|
||||||
|
|
||||||
## Customizing Handler Output
|
|
||||||
|
|
||||||
By default, the signal handler writes the failure dump to the standard error.
|
|
||||||
However, it is possible to customize the destination by installing a callback
|
|
||||||
using the `#!cpp google::InstallFailureWriter()` function. The function expects
|
|
||||||
a pointer to a function with the following signature:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
void YourFailureWriter(const char* message/* (1)! */, std::size_t length/* (2)! */);
|
|
||||||
```
|
|
||||||
|
|
||||||
1. The pointer references the start of the failure message.
|
|
||||||
|
|
||||||
!!! danger
|
|
||||||
The string is **not null-terminated**.
|
|
||||||
|
|
||||||
2. The message length in characters.
|
|
||||||
|
|
||||||
!!! warning "Possible overflow errors"
|
|
||||||
Users should not expect the `message` string to be null-terminated.
|
|
||||||
|
|
||||||
## User-defined Failure Function
|
|
||||||
|
|
||||||
`FATAL` severity level messages or unsatisfied `CHECK` condition
|
|
||||||
terminate your program. You can change the behavior of the termination
|
|
||||||
by `google::InstallFailureFunction`.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
void YourFailureFunction() {
|
|
||||||
// Reports something...
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
google::InstallFailureFunction(&YourFailureFunction);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, glog tries to dump the stacktrace and calls `#!cpp std::abort`. The
|
|
||||||
stacktrace is generated only when running the application on a system
|
|
||||||
supported[^1] by glog.
|
|
||||||
|
|
||||||
[^1]: To extract the stack trace, glog currently supports the following targets:
|
|
||||||
|
|
||||||
* x86, x86_64,
|
|
||||||
* PowerPC architectures,
|
|
||||||
* `libunwind`,
|
|
||||||
* and the Debug Help Library (`dbghelp`) on Windows.
|
|
||||||
|
|
||||||
@ -1,93 +0,0 @@
|
|||||||
# Adjusting Output
|
|
||||||
|
|
||||||
Several flags influence glog's output behavior.
|
|
||||||
|
|
||||||
## Using Command-line Parameters and Environment Variables
|
|
||||||
|
|
||||||
If the [Google gflags
|
|
||||||
library](https://github.com/gflags/gflags) is installed on your machine,
|
|
||||||
the build system will automatically detect and use it, allowing you to
|
|
||||||
pass flags on the command line.
|
|
||||||
|
|
||||||
!!! example "Activate `--logtostderr` in an application from the command line"
|
|
||||||
A binary `you_application` that uses glog can be started using
|
|
||||||
``` bash
|
|
||||||
./your_application --logtostderr=1
|
|
||||||
```
|
|
||||||
to log to `stderr` instead of writing the output to a log file.
|
|
||||||
|
|
||||||
!!! tip
|
|
||||||
You can set boolean flags to `true` by specifying `1`, `true`, or `yes`. To
|
|
||||||
set boolean flags to `false`, specify `0`, `false`, or `no`. In either case
|
|
||||||
the spelling is case-insensitive.
|
|
||||||
|
|
||||||
|
|
||||||
If the Google gflags library isn't installed, you set flags via
|
|
||||||
environment variables, prefixing the flag name with `GLOG_`, e.g.,
|
|
||||||
|
|
||||||
!!! example "Activate `logtostderr` without gflags"
|
|
||||||
``` bash
|
|
||||||
GLOG_logtostderr=1 ./your_application
|
|
||||||
```
|
|
||||||
|
|
||||||
The following flags are most commonly used:
|
|
||||||
|
|
||||||
`logtostderr` (`bool`, default=`false`)
|
|
||||||
|
|
||||||
: Log messages to `stderr` instead of logfiles.
|
|
||||||
|
|
||||||
`stderrthreshold` (`int`, default=2, which is `ERROR`)
|
|
||||||
|
|
||||||
: Copy log messages at or above this level to `stderr` in addition to
|
|
||||||
logfiles. The numbers of severity levels `INFO`, `WARNING`, `ERROR`,
|
|
||||||
and `FATAL` are 0, 1, 2, and 3, respectively.
|
|
||||||
|
|
||||||
`minloglevel` (`int`, default=0, which is `INFO`)
|
|
||||||
|
|
||||||
: Log messages at or above this level. Again, the numbers of severity
|
|
||||||
levels `INFO`, `WARNING`, `ERROR`, and `FATAL` are 0, 1, 2, and 3,
|
|
||||||
respectively.
|
|
||||||
|
|
||||||
`log_dir` (`string`, default="")
|
|
||||||
|
|
||||||
: If specified, logfiles are written into this directory instead of
|
|
||||||
the default logging directory.
|
|
||||||
|
|
||||||
`v` (`int`, default=0)
|
|
||||||
|
|
||||||
: Show all `#!cpp VLOG(m)` messages for `m` less or equal the value of this
|
|
||||||
flag. Overridable by `#!bash --vmodule`. Refer to [verbose
|
|
||||||
logging](logging.md#verbose-logging) for more detail.
|
|
||||||
|
|
||||||
`vmodule` (`string`, default="")
|
|
||||||
|
|
||||||
: Per-module verbose level. The argument has to contain a
|
|
||||||
comma-separated list of `<module name>=<log level>`. `<module name>` is a
|
|
||||||
glob pattern (e.g., `gfs*` for all modules whose name starts with "gfs"),
|
|
||||||
matched against the filename base (that is, name ignoring .cc/.h./-inl.h).
|
|
||||||
`<log level>` overrides any value given by `--v`. See also [verbose
|
|
||||||
logging](logging.md#verbose-logging) for more details.
|
|
||||||
|
|
||||||
Additional flags are defined in
|
|
||||||
[flags.cc](https://github.com/google/glog/blob/master/src/flags.cc). Please see
|
|
||||||
the source for their complete list.
|
|
||||||
|
|
||||||
## Modifying Flags Programmatically
|
|
||||||
|
|
||||||
You can also modify flag values in your program by modifying global variables
|
|
||||||
`FLAGS_*`. Most settings start working immediately after you update `FLAGS_*`.
|
|
||||||
The exceptions are the flags related to destination files. For instance, you
|
|
||||||
might want to set `FLAGS_log_dir` before calling `google::InitGoogleLogging`.
|
|
||||||
|
|
||||||
!!! example "Setting `log_dir` at runtime"
|
|
||||||
``` cpp
|
|
||||||
LOG(INFO) << "file";
|
|
||||||
// Most flags work immediately after updating values.
|
|
||||||
FLAGS_logtostderr = 1;
|
|
||||||
LOG(INFO) << "stderr";
|
|
||||||
FLAGS_logtostderr = 0;
|
|
||||||
// This won’t change the log destination. If you want to set this
|
|
||||||
// value, you should do this before google::InitGoogleLogging .
|
|
||||||
FLAGS_log_dir = "/some/log/directory";
|
|
||||||
LOG(INFO) << "the same file";
|
|
||||||
```
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
# Google Logging Library
|
|
||||||
|
|
||||||
Google Logging (glog) is a C++14 library that implements application-level
|
|
||||||
logging. The library provides logging APIs based on C++-style streams and
|
|
||||||
various helper macros.
|
|
||||||
|
|
||||||
# How to Use
|
|
||||||
|
|
||||||
You can log a message by simply streaming things to `LOG`(<a particular
|
|
||||||
[severity level](logging.md#severity-levels)\>), e.g.,
|
|
||||||
|
|
||||||
``` cpp title="main.cpp"
|
|
||||||
#include <glog/logging.h>
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
google::InitGoogleLogging(argv[0]); // (1)!
|
|
||||||
LOG(INFO) << "Found " << num_cookies << " cookies"; // (2)!
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
1. Initialize the Google Logging Library
|
|
||||||
2. Log a message with informational severity
|
|
||||||
|
|
||||||
The library can be installed using various [package managers](packages.md) or
|
|
||||||
compiled [from source](build.md). For a detailed overview of glog features and
|
|
||||||
their usage, please refer to the [user guide](logging.md).
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
The above example requires further [Bazel](build.md#bazel) or
|
|
||||||
[CMake](usage.md) setup for use in own projects.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
# The 3-Clause BSD License
|
|
||||||
|
|
||||||
--8<-- "LICENSE.md"
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
# Automatically Remove Old Logs
|
|
||||||
|
|
||||||
To enable the log cleaner:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
google::EnableLogCleaner(24h * 3); // keep your logs for 3 days
|
|
||||||
```
|
|
||||||
|
|
||||||
In C++20 (and later) this can be shortened to:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
google::EnableLogCleaner(3d); // keep your logs for 3 days
|
|
||||||
```
|
|
||||||
|
|
||||||
And then glog will check if there are overdue logs whenever a flush is
|
|
||||||
performed. In this example, any log file from your project whose last
|
|
||||||
modified time is greater than 3 days will be `unlink`()ed.
|
|
||||||
|
|
||||||
This feature can be disabled at any time (if it has been enabled) using
|
|
||||||
``` cpp
|
|
||||||
google::DisableLogCleaner();
|
|
||||||
```
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
# Strip Logging Messages
|
|
||||||
|
|
||||||
Strings used in log messages can increase the size of your binary and
|
|
||||||
present a privacy concern. You can therefore instruct glog to remove all
|
|
||||||
strings which fall below a certain severity level by using the
|
|
||||||
`GOOGLE_STRIP_LOG` macro:
|
|
||||||
|
|
||||||
If your application has code like this:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
#define GOOGLE_STRIP_LOG 1 // this must go before the #include!
|
|
||||||
#include <glog/logging.h>
|
|
||||||
```
|
|
||||||
|
|
||||||
The compiler will remove the log messages whose severities are less than
|
|
||||||
the specified integer value. Since `VLOG` logs at the severity level
|
|
||||||
`INFO` (numeric value `0`), setting `GOOGLE_STRIP_LOG` to 1 or greater
|
|
||||||
removes all log messages associated with `VLOG`s as well as `INFO` log
|
|
||||||
statements.
|
|
||||||
|
|
||||||
424
docs/logging.md
424
docs/logging.md
@ -1,424 +0,0 @@
|
|||||||
# Logging
|
|
||||||
|
|
||||||
glog defines a series of macros that simplify many common logging tasks. You can
|
|
||||||
log messages by [severity level](#severity-levels), [control logging](flags.md)
|
|
||||||
behavior from the command line, log based on
|
|
||||||
[conditionals](#conditional-occasional-logging), abort the program when
|
|
||||||
[expected conditions](#runtime-checks) are not met, introduce your [own logging
|
|
||||||
levels](#verbose-logging), [customize the prefix](#format-customization)
|
|
||||||
attached to log messages, and more.
|
|
||||||
|
|
||||||
|
|
||||||
## Severity Levels
|
|
||||||
|
|
||||||
You can specify one of the following severity levels (in increasing order of
|
|
||||||
severity):
|
|
||||||
|
|
||||||
1. `INFO`,
|
|
||||||
2. `WARNING`,
|
|
||||||
3. `ERROR`, and
|
|
||||||
4. `FATAL`.
|
|
||||||
|
|
||||||
Logging a `FATAL` message terminates the program (after the message is logged).
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
Messages of a given severity are logged not only to corresponding severity
|
|
||||||
logfile but also to other logfiles of lower severity. For instance, a
|
|
||||||
message of severity `FATAL` will be logged to logfiles of severity `FATAL`,
|
|
||||||
`ERROR`, `WARNING`, and `INFO`.
|
|
||||||
|
|
||||||
The `DFATAL` severity logs a `FATAL` error in [debug mode](#debugging-support)
|
|
||||||
(i.e., there is no `NDEBUG` macro defined), but avoids halting the program in
|
|
||||||
production by automatically reducing the severity to `ERROR`.
|
|
||||||
|
|
||||||
## Log Files
|
|
||||||
|
|
||||||
Unless otherwise specified, glog uses the format
|
|
||||||
|
|
||||||
<tmp>/<program name>.<hostname>.<user name>.log.<severity level>.<date>-<time>.<pid>
|
|
||||||
|
|
||||||
for log filenames written to a directory designated as `<tmp>` and
|
|
||||||
determined according to the following rules.
|
|
||||||
|
|
||||||
**Windows**
|
|
||||||
|
|
||||||
: glog uses the
|
|
||||||
[GetTempPathA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha)
|
|
||||||
API function to retrieve the directory for temporary files with a
|
|
||||||
fallback to
|
|
||||||
|
|
||||||
1. `C:\TMP\`
|
|
||||||
2. `C:\TEMP\`
|
|
||||||
|
|
||||||
(in the order given.)
|
|
||||||
|
|
||||||
**non-Windows**
|
|
||||||
|
|
||||||
: The directory is determined by referencing the environment variables
|
|
||||||
|
|
||||||
1. `TMPDIR`
|
|
||||||
2. `TMP`
|
|
||||||
|
|
||||||
if set with a fallback to `/tmp/`.
|
|
||||||
|
|
||||||
The default path to a log file on Linux, for instance, could be
|
|
||||||
|
|
||||||
/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474
|
|
||||||
|
|
||||||
By default, glog echos `ERROR` and `FATAL` messages to standard error in
|
|
||||||
addition to log files.
|
|
||||||
|
|
||||||
## Log Line Prefix Format
|
|
||||||
|
|
||||||
Log lines have this form:
|
|
||||||
|
|
||||||
Lyyyymmdd hh:mm:ss.uuuuuu threadid file:line] msg...
|
|
||||||
|
|
||||||
where the fields are defined as follows:
|
|
||||||
|
|
||||||
| Placeholder | Meaning |
|
|
||||||
| ------------------- | ----------------------------------------------------------------------|
|
|
||||||
| `L` | A single character, representing the log level (e.g., `I` for `INFO`) |
|
|
||||||
| `yyyy` | The year |
|
|
||||||
| `mm` | The month (zero padded; i.e., May is `05`) |
|
|
||||||
| `dd` | The day (zero padded) |
|
|
||||||
| `hh:mm:ss.uuuuuu` | Time in hours, minutes and fractional seconds |
|
|
||||||
| `threadid` | The space-padded thread ID |
|
|
||||||
| `file` | The file name |
|
|
||||||
| `line` | The line number |
|
|
||||||
| `msg` | The user-supplied message |
|
|
||||||
|
|
||||||
!!! example "Default log line prefix format"
|
|
||||||
|
|
||||||
```
|
|
||||||
I1103 11:57:31.739339 24395 google.cc:2341] Command line: ./some_prog
|
|
||||||
I1103 11:57:31.739403 24395 google.cc:2342] Process id 24395
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
Although microseconds are useful for comparing events on a single machine,
|
|
||||||
clocks on different machines may not be well synchronized. Hence, use with
|
|
||||||
caution when comparing the low bits of timestamps from different machines.
|
|
||||||
|
|
||||||
### Format Customization
|
|
||||||
|
|
||||||
The predefined log line prefix can be replaced using a user-provided callback
|
|
||||||
that formats the corresponding output.
|
|
||||||
|
|
||||||
For each log entry, the callback will be invoked with a reference to a
|
|
||||||
`google::LogMessage` instance containing the severity, filename, line
|
|
||||||
number, thread ID, and time of the event. It will also be given a
|
|
||||||
reference to the output stream, whose contents will be prepended to the actual
|
|
||||||
message in the final log line.
|
|
||||||
|
|
||||||
To enable the use of a prefix formatter, use the
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
google::InstallPrefixFormatter(&MyPrefixFormatter);
|
|
||||||
```
|
|
||||||
|
|
||||||
function to pass a pointer to the corresponding `MyPrefixFormatter` callback
|
|
||||||
during initialization. `InstallPrefixFormatter` takes a second optional argument
|
|
||||||
of type `#!cpp void*` that allows supplying user data to the callback.
|
|
||||||
|
|
||||||
!!! example "Custom prefix formatter"
|
|
||||||
The following function outputs a prefix that matches glog's default format.
|
|
||||||
The third parameter `data` can be used to access user-supplied data which
|
|
||||||
unless specified defaults to `#!cpp nullptr`.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
void MyPrefixFormatter(std::ostream& s, const google::LogMessage& m, void* /*data*/) {
|
|
||||||
s << google::GetLogSeverityName(m.severity())[0]
|
|
||||||
<< setw(4) << 1900 + m.time().year()
|
|
||||||
<< setw(2) << 1 + m.time().month()
|
|
||||||
<< setw(2) << m.time().day()
|
|
||||||
<< ' '
|
|
||||||
<< setw(2) << m.time().hour() << ':'
|
|
||||||
<< setw(2) << m.time().min() << ':'
|
|
||||||
<< setw(2) << m.time().sec() << "."
|
|
||||||
<< setw(6) << m.time().usec()
|
|
||||||
<< ' '
|
|
||||||
<< setfill(' ') << setw(5)
|
|
||||||
<< m.thread_id() << setfill('0')
|
|
||||||
<< ' '
|
|
||||||
<< m.basename() << ':' << m.line() << "]";
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Conditional / Occasional Logging
|
|
||||||
|
|
||||||
Sometimes, you may only want to log a message under certain conditions.
|
|
||||||
You can use the following macros to perform conditional logging:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
|
|
||||||
```
|
|
||||||
|
|
||||||
The "Got lots of cookies" message is logged only when the variable
|
|
||||||
`num_cookies` exceeds 10. If a line of code is executed many times, it may be
|
|
||||||
useful to only log a message at certain intervals. This kind of logging is most
|
|
||||||
useful for informational messages.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
|
|
||||||
```
|
|
||||||
|
|
||||||
The above line outputs a log messages on the 1st, 11th, 21st, ... times
|
|
||||||
it is executed.
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
The placeholder `#!cpp google::COUNTER` identifies the recurring repetition.
|
|
||||||
|
|
||||||
You can combine conditional and occasional logging with the following
|
|
||||||
macro.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
|
|
||||||
<< "th big cookie";
|
|
||||||
```
|
|
||||||
|
|
||||||
Instead of outputting a message every nth time, you can also limit the
|
|
||||||
output to the first n occurrences:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
|
|
||||||
```
|
|
||||||
|
|
||||||
Outputs log messages for the first 20 times it is executed. The `#!cpp
|
|
||||||
google::COUNTER` identifier indicates which repetition is happening.
|
|
||||||
|
|
||||||
Other times, it is desired to only log a message periodically based on a
|
|
||||||
time. For instance, to log a message every 10ms:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
LOG_EVERY_T(INFO, 0.01) << "Got a cookie";
|
|
||||||
```
|
|
||||||
|
|
||||||
Or every 2.35s:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
LOG_EVERY_T(INFO, 2.35) << "Got a cookie";
|
|
||||||
```
|
|
||||||
|
|
||||||
## Verbose Logging
|
|
||||||
|
|
||||||
When you are chasing difficult bugs, thorough log messages are very
|
|
||||||
useful. However, you may want to ignore too verbose messages in usual
|
|
||||||
development. For such verbose logging, glog provides the `VLOG` macro, which
|
|
||||||
allows you to define your own numeric logging levels.
|
|
||||||
|
|
||||||
The `#!bash --v` command line option controls which verbose messages are logged:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
VLOG(1) << "I’m printed when you run the program with --v=1 or higher";
|
|
||||||
VLOG(2) << "I’m printed when you run the program with --v=2 or higher";
|
|
||||||
```
|
|
||||||
|
|
||||||
With `VLOG`, the lower the verbose level, the more likely messages are to be
|
|
||||||
logged. For example, if `#!bash --v==1`, `#!cpp VLOG(1)` will log, but `#!cpp
|
|
||||||
VLOG(2)` will not log.
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
The `VLOG` behavior is opposite of the severity level logging, where
|
|
||||||
`INFO`, `ERROR`, etc. are defined in increasing order and thus
|
|
||||||
`#!bash --minloglevel` of 1 will only log `WARNING` and above.
|
|
||||||
|
|
||||||
Though you can specify any integers for both `VLOG` macro and `--v` flag, the
|
|
||||||
common values for them are small positive integers. For example, if you write
|
|
||||||
`#!cpp VLOG(0)`, you should specify `--v=-1` or lower to silence it. This is less
|
|
||||||
useful since we may not want verbose logs by default in most cases. The `VLOG`
|
|
||||||
macros always log at the `INFO` log level (when they log at all).
|
|
||||||
|
|
||||||
Verbose logging can be controlled from the command line on a per-module basis:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
--vmodule=mapreduce=2,file=1,gfs*=3 --v=0
|
|
||||||
```
|
|
||||||
|
|
||||||
Specifying these options will specifically:
|
|
||||||
|
|
||||||
1. Print `#!cpp VLOG(2)` and lower messages from mapreduce.{h,cc}
|
|
||||||
2. Print `#!cpp VLOG(1)` and lower messages from file.{h,cc}
|
|
||||||
3. Print `#!cpp VLOG(3)` and lower messages from files prefixed with "gfs"
|
|
||||||
4. Print `#!cpp VLOG(0)` and lower messages from elsewhere
|
|
||||||
|
|
||||||
The wildcarding functionality 3. supports both `*` (matches 0 or more
|
|
||||||
characters) and `?` (matches any single character) wildcards. Please also refer
|
|
||||||
to [command line flags](flags.md) for more information.
|
|
||||||
|
|
||||||
There's also `#!cpp VLOG_IS_ON(n)` "verbose level" condition macro. This macro
|
|
||||||
returns `#!cpp true` when the `--v` is equal to or greater than `n`. The macro can be
|
|
||||||
used as follows:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
if (VLOG_IS_ON(2)) {
|
|
||||||
// (1)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
1. Here we can perform some logging preparation and logging that can’t be
|
|
||||||
accomplished with just `#!cpp VLOG(2) << "message ...";`
|
|
||||||
|
|
||||||
Verbose level condition macros `VLOG_IF`, `VLOG_EVERY_N` and `VLOG_IF_EVERY_N`
|
|
||||||
behave analogous to `LOG_IF`, `LOG_EVERY_N`, `LOG_IF_EVERY_N`, but accept a
|
|
||||||
numeric verbosity level as opposed to a severity level.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
VLOG_IF(1, (size > 1024))
|
|
||||||
<< "I’m printed when size is more than 1024 and when you run the "
|
|
||||||
"program with --v=1 or more";
|
|
||||||
VLOG_EVERY_N(1, 10)
|
|
||||||
<< "I’m printed every 10th occurrence, and when you run the program "
|
|
||||||
"with --v=1 or more. Present occurrence is " << google::COUNTER;
|
|
||||||
VLOG_IF_EVERY_N(1, (size > 1024), 10)
|
|
||||||
<< "I’m printed on every 10th occurrence of case when size is more "
|
|
||||||
" than 1024, when you run the program with --v=1 or more. ";
|
|
||||||
"Present occurrence is " << google::COUNTER;
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
!!! info "Performance"
|
|
||||||
The conditional logging macros provided by glog (e.g., `CHECK`, `LOG_IF`,
|
|
||||||
`VLOG`, etc.) are carefully implemented and don't execute the right hand
|
|
||||||
side expressions when the conditions are false. So, the following check may
|
|
||||||
not sacrifice the performance of your application.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK(obj.ok) << obj.CreatePrettyFormattedStringButVerySlow();
|
|
||||||
```
|
|
||||||
|
|
||||||
## Debugging Support
|
|
||||||
|
|
||||||
Special debug mode logging macros only have an effect in debug mode and are
|
|
||||||
compiled away to nothing for non-debug mode compiles. Use these macros to avoid
|
|
||||||
slowing down your production application due to excessive logging.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
DLOG(INFO) << "Found cookies";
|
|
||||||
DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
|
|
||||||
DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
|
|
||||||
DLOG_FIRST_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
|
|
||||||
DLOG_EVERY_T(INFO, 0.01) << "Got a cookie";
|
|
||||||
```
|
|
||||||
|
|
||||||
## Runtime Checks
|
|
||||||
|
|
||||||
It is a good practice to check expected conditions in your program
|
|
||||||
frequently to detect errors as early as possible. The `CHECK` macro
|
|
||||||
provides the ability to abort the application when a condition is not met,
|
|
||||||
similar to the `assert` macro defined in the standard C library.
|
|
||||||
|
|
||||||
`CHECK` aborts the application if a condition is not true. Unlike
|
|
||||||
`assert`, it is **not** controlled by `NDEBUG`, so the check will be executed
|
|
||||||
regardless of compilation mode. Therefore, `fp->Write(x)` in the following
|
|
||||||
example is always executed:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK(fp->Write(x) == 4) << "Write failed!";
|
|
||||||
```
|
|
||||||
|
|
||||||
There are various helper macros for equality/inequality checks
|
|
||||||
-`CHECK_EQ`, `CHECK_NE`, `CHECK_LE`, `CHECK_LT`, `CHECK_GE`, and
|
|
||||||
`CHECK_GT`. They compare two values, and log a `FATAL` message including the two
|
|
||||||
values when the result is not as expected. The values must have
|
|
||||||
`#!cpp operator<<(ostream, ...)` defined.
|
|
||||||
|
|
||||||
You may append to the error message like so:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK_NE(1, 2) << ": The world must be ending!";
|
|
||||||
```
|
|
||||||
|
|
||||||
We are very careful to ensure that each argument is evaluated exactly
|
|
||||||
once, and that anything which is legal to pass as a function argument is legal
|
|
||||||
here. In particular, the arguments may be temporary expressions which will end
|
|
||||||
up being destroyed at the end of the apparent statement, for example:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK_EQ(string("abc")[1], ’b’);
|
|
||||||
```
|
|
||||||
|
|
||||||
The compiler reports an error if one of the arguments is a pointer and the other
|
|
||||||
is `#!cpp nullptr`. To work around this, simply `#!cpp static_cast` `#!cpp
|
|
||||||
nullptr` to the type of the desired pointer.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK_EQ(some_ptr, static_cast<SomeType*>(nullptr));
|
|
||||||
```
|
|
||||||
|
|
||||||
Better yet, use the `CHECK_NOTNULL` macro:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK_NOTNULL(some_ptr);
|
|
||||||
some_ptr->DoSomething();
|
|
||||||
```
|
|
||||||
|
|
||||||
Since this macro returns the given pointer, this is very useful in
|
|
||||||
constructor initializer lists.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
struct S {
|
|
||||||
S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
|
|
||||||
Something* ptr_;
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
Due to the argument forwarding, `CHECK_NOTNULL` cannot be used to
|
|
||||||
simultaneously stream an additional custom message. To provide a custom
|
|
||||||
message, one can use the macro `CHECK_EQ` prior to the failing check.
|
|
||||||
|
|
||||||
If you are comparing C strings (`#!cpp char *`), a handy set of macros performs
|
|
||||||
both case sensitive and insensitive comparisons - `CHECK_STREQ`, `CHECK_STRNE`,
|
|
||||||
`CHECK_STRCASEEQ`, and `CHECK_STRCASENE`. The `CHECK_*CASE*` macro variants are
|
|
||||||
case-insensitive. You can safely pass `#!cpp nullptr` pointers to this macro.
|
|
||||||
They treat `#!cpp nullptr` and any non-`#!cpp nullptr` string as not equal. Two
|
|
||||||
`#!cpp nullptr`s are equal.
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
Both arguments may be temporary objects which are destructed at the
|
|
||||||
end of the current *full expression*, such as
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
CHECK_STREQ(Foo().c_str(), Bar().c_str());
|
|
||||||
```
|
|
||||||
|
|
||||||
where `Foo` and `Bar` return `std::string`.
|
|
||||||
|
|
||||||
The `CHECK_DOUBLE_EQ` macro checks the equality of two floating point values,
|
|
||||||
accepting a small error margin. `CHECK_NEAR` accepts a third floating point
|
|
||||||
argument, which specifies the acceptable error margin.
|
|
||||||
|
|
||||||
|
|
||||||
## Raw Logging
|
|
||||||
|
|
||||||
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/master/src/glog/raw_logging.h)
|
|
||||||
for detail.
|
|
||||||
|
|
||||||
## Google Style `perror()`
|
|
||||||
|
|
||||||
`PLOG()` and `PLOG_IF()` and `PCHECK()` behave exactly like their `LOG*` and
|
|
||||||
`CHECK` equivalents with the addition that they append a description of the
|
|
||||||
current state of `errno` to their output lines. E.g.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
PCHECK(write(1, nullptr, 2) >= 0) << "Write nullptr failed";
|
|
||||||
```
|
|
||||||
|
|
||||||
This check fails with the following error message.
|
|
||||||
|
|
||||||
F0825 185142 test.cc:22] Check failed: write(1, nullptr, 2) >= 0 Write nullptr failed: Bad address [14]
|
|
||||||
|
|
||||||
## Syslog
|
|
||||||
|
|
||||||
`SYSLOG`, `SYSLOG_IF`, and `SYSLOG_EVERY_N` macros are available. These log to
|
|
||||||
syslog in addition to the normal logs. Be aware that logging to syslog can
|
|
||||||
drastically impact performance, especially if syslog is configured for remote
|
|
||||||
logging! Make sure you understand the implications of outputting to syslog
|
|
||||||
before you use these macros. In general, it's wise to use these macros
|
|
||||||
sparingly.
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% block outdated %}
|
|
||||||
You're not viewing the latest version.
|
|
||||||
<a href="{{ '../' ~ base_url }}">
|
|
||||||
<strong>Click here to go to latest.</strong>
|
|
||||||
</a>
|
|
||||||
{% endblock %}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
# Installation using Package Managers
|
|
||||||
|
|
||||||
## conan
|
|
||||||
|
|
||||||
You can download and install glog using the [conan](https://conan.io)
|
|
||||||
package manager:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
pip install conan
|
|
||||||
conan install -r conancenter glog/<glog-version>@
|
|
||||||
```
|
|
||||||
|
|
||||||
The glog recipe in conan center is kept up to date by conan center index
|
|
||||||
community contributors. If the version is out of date, please create an
|
|
||||||
issue or pull request on the
|
|
||||||
[conan-center-index](https://github.com/conan-io/conan-center-index)
|
|
||||||
repository.
|
|
||||||
|
|
||||||
## vcpkg
|
|
||||||
|
|
||||||
You can download and install glog using the
|
|
||||||
[vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
git clone https://github.com/Microsoft/vcpkg.git
|
|
||||||
cd vcpkg
|
|
||||||
./bootstrap-vcpkg.sh
|
|
||||||
./vcpkg integrate install
|
|
||||||
./vcpkg install glog
|
|
||||||
```
|
|
||||||
|
|
||||||
The glog port in vcpkg is kept up to date by Microsoft team members and
|
|
||||||
community contributors. If the version is out of date, please create an
|
|
||||||
issue or pull request on the vcpkg repository.
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
mike>=2.1.1
|
|
||||||
mkdocs-git-committers-plugin-2>=2.3.0
|
|
||||||
mkdocs-git-revision-date-localized-plugin>=1.2.6
|
|
||||||
mkdocs-material-extensions>=1.3.1
|
|
||||||
mkdocs-material>=9.5.26
|
|
||||||
mkdocs>=1.6.0
|
|
||||||
@ -1,84 +0,0 @@
|
|||||||
# Custom Sinks
|
|
||||||
|
|
||||||
Under certain circumstances, it is useful to send the log output to a
|
|
||||||
destination other than a file, `stderr` and/or `stdout`. In case, the library
|
|
||||||
provides the `#!cpp google::LogSink` interface whose implementations can be used
|
|
||||||
to write the log output to arbitrary locations.
|
|
||||||
|
|
||||||
## Basic Interface
|
|
||||||
|
|
||||||
The sink interface is defined as follows:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
class LogSink {
|
|
||||||
public:
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
The user must implement `#!cpp google::LogSink::send`, which is called by the
|
|
||||||
library every time a message is logged.
|
|
||||||
|
|
||||||
!!! warning "Possible deadlock due to nested logging"
|
|
||||||
This method can't use `LOG()` or `CHECK()` as logging system mutex(s) are
|
|
||||||
held during this call.
|
|
||||||
|
|
||||||
## Registering Log Sinks
|
|
||||||
|
|
||||||
To use the custom sink and instance of the above interface implementation must
|
|
||||||
be registered using `google::AddLogSink` which expects a pointer to the
|
|
||||||
`google::LogSink` instance. To unregister use `google::RemoveLogSink`. Both
|
|
||||||
functions are thread-safe.
|
|
||||||
|
|
||||||
!!! danger "`LogSink` ownership"
|
|
||||||
The `google::LogSink` instance must not be destroyed until the referencing
|
|
||||||
pointer is unregistered.
|
|
||||||
|
|
||||||
## Direct Logging
|
|
||||||
|
|
||||||
Instead of registering the sink, we can directly use to log messages. While `#!
|
|
||||||
LOG_TO_SINK(sink, severity)` allows to log both to the sink and to a global log
|
|
||||||
registry, e.g., a file, `#!cpp LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity)`
|
|
||||||
will avoid the latter.
|
|
||||||
|
|
||||||
!!! example "Using a custom sink"
|
|
||||||
``` cpp title="custom_sink.cc"
|
|
||||||
-8<- "examples/custom_sink.cc:33:"
|
|
||||||
```
|
|
||||||
|
|
||||||
1. `MySink` implements a custom sink that sends log messages to `std::cout`.
|
|
||||||
2. The custom sink must be registered to for use with existing logging
|
|
||||||
macros.
|
|
||||||
3. Once the custom sink is no longer needed we remove it from the registry.
|
|
||||||
4. A sink does not need to be registered globally. However, then, messages
|
|
||||||
must be logged using dedicated macros.
|
|
||||||
|
|
||||||
Running the above example as `#!bash GLOG_log_dir=. ./custom_sink_example`
|
|
||||||
will produce
|
|
||||||
|
|
||||||
<div class="annotate" markdown>
|
|
||||||
|
|
||||||
``` title="Custom sink output"
|
|
||||||
INFO custom_sink.cc:63 logging to MySink
|
|
||||||
INFO custom_sink.cc:68 direct logging
|
|
||||||
INFO custom_sink.cc:69 direct logging but not to file (1)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
1. This line is not present in the log file because we used
|
|
||||||
`LOG_TO_SINK_BUT_NOT_TO_LOGFILE` to log the message.
|
|
||||||
|
|
||||||
and the corresponding log file will contain
|
|
||||||
|
|
||||||
``` title="Log file generated with the custom sink"
|
|
||||||
Log file created at: 2024/06/11 13:24:27
|
|
||||||
Running on machine: pc
|
|
||||||
Running duration (h:mm:ss): 0:00:00
|
|
||||||
Log line format: [IWEF]yyyymmdd hh:mm:ss.uuuuuu threadid file:line] msg
|
|
||||||
I20240611 13:24:27.476620 126237946035776 custom_sink.cc:63] logging to MySink
|
|
||||||
I20240611 13:24:27.476796 126237946035776 custom_sink.cc:68] direct logging
|
|
||||||
```
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
# Installation Notes for 64-bit Linux Systems
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
The description on this page is possibly not up-to-date.
|
|
||||||
|
|
||||||
The [glibc built-in stack-unwinder](#glibc-built-in-stack-unwinder) on 64-bit
|
|
||||||
systems has some problems with glog. In particular, if you are using
|
|
||||||
[`InstallFailureSignalHandler()`](failures.md), the signal may be raised in the
|
|
||||||
middle of `malloc`, holding some `malloc`-related locks when they invoke the
|
|
||||||
stack unwinder. The built-in stack unwinder may call `malloc` recursively, which
|
|
||||||
may require the thread to acquire a lock it already holds resulting in a
|
|
||||||
deadlock.
|
|
||||||
|
|
||||||
## Recommended Approach: `libunwind`
|
|
||||||
|
|
||||||
For above reason, if you use a 64-bit system and you need
|
|
||||||
`InstallFailureSignalHandler()`, we strongly recommend you install `libunwind`
|
|
||||||
before trying to configure or install google glog. libunwind can be found
|
|
||||||
[here](http://download.savannah.nongnu.org/releases/libunwind/libunwind-snap-070410.tar.gz).
|
|
||||||
|
|
||||||
Even if you already have `libunwind` installed, you will probably still need to
|
|
||||||
install from the snapshot to get the latest version.
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
If you install libunwind from the URL above, be aware that you may have
|
|
||||||
trouble if you try to statically link your binary with glog: that is, if you
|
|
||||||
link with `gcc -static -lgcc_eh ...`. This is because both `libunwind` and
|
|
||||||
`libgcc` implement the same C++ exception handling APIs, but they implement
|
|
||||||
them differently on some platforms. This is not likely to be a problem on
|
|
||||||
ia64, but may be on x86-64.
|
|
||||||
|
|
||||||
Also, if you link binaries statically, make sure that you add
|
|
||||||
`-Wl,--eh-frame-hdr` to your linker options. This is required so that
|
|
||||||
`libunwind` can find the information generated by the compiler required for
|
|
||||||
stack unwinding.
|
|
||||||
|
|
||||||
Using `-static` is rare, though, so unless you know this will affect you it
|
|
||||||
probably won't.
|
|
||||||
|
|
||||||
## Alternative Stack-unwinder
|
|
||||||
|
|
||||||
If you cannot or do not wish to install `libunwind`, you can still try to use
|
|
||||||
two kinds of stack-unwinder:
|
|
||||||
|
|
||||||
### glibc Built-in Stack-unwinder
|
|
||||||
|
|
||||||
As we already mentioned, glibc's unwinder has a deadlock issue. However, if you
|
|
||||||
don't use `InstallFailureSignalHandler()` or you don't worry about the rare
|
|
||||||
possibilities of deadlocks, you can use this stack-unwinder. If you specify no
|
|
||||||
options and `libunwind` isn't detected on your system, the configure script
|
|
||||||
chooses this unwinder by default.
|
|
||||||
|
|
||||||
### Frame Pointer based Stack-unwinder
|
|
||||||
|
|
||||||
The frame pointer based stack unwinder requires that your application, the glog
|
|
||||||
library, and system libraries like libc, all be compiled with a frame pointer.
|
|
||||||
This is *not* the default for x86-64.
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
# Using glog in a CMake Project
|
|
||||||
|
|
||||||
Assuming that glog was previously [built using CMake](build.md#cmake) or
|
|
||||||
installed using a package manager, you can use the CMake command `#!cmake
|
|
||||||
find_package` to build against glog in your CMake project as follows:
|
|
||||||
|
|
||||||
``` cmake title="CMakeLists.txt"
|
|
||||||
cmake_minimum_required (VERSION 3.16)
|
|
||||||
project (myproj VERSION 1.0)
|
|
||||||
|
|
||||||
find_package (glog 0.8.0 REQUIRED)
|
|
||||||
|
|
||||||
add_executable (myapp main.cpp)
|
|
||||||
target_link_libraries (myapp glog::glog)
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile definitions and options will be added automatically to your target as
|
|
||||||
needed.
|
|
||||||
|
|
||||||
Alternatively, glog can be incorporated into using the CMake command `#!cmake
|
|
||||||
add_subdirectory` to include glog directly from a subdirectory of your project
|
|
||||||
by replacing the `#!cmake find_package` call from the previous snippet by
|
|
||||||
`add_subdirectory`. The `#!cmake glog::glog` target is in this case an `#!cmake
|
|
||||||
ALIAS` library target for the `glog` library target.
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
# Notes for Windows Users
|
|
||||||
|
|
||||||
glog defines the severity level `ERROR`, which is also defined by `windows.h`.
|
|
||||||
You can make glog not define `INFO`, `WARNING`, `ERROR`, and `FATAL` by defining
|
|
||||||
`GLOG_NO_ABBREVIATED_SEVERITIES` before including `glog/logging.h`. Even with
|
|
||||||
this macro, you can still use the iostream like logging facilities:
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
#define GLOG_NO_ABBREVIATED_SEVERITIES
|
|
||||||
#include <windows.h>
|
|
||||||
#include <glog/logging.h>
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
LOG(ERROR) << "This should work";
|
|
||||||
LOG_IF(ERROR, x > y) << "This should be also OK";
|
|
||||||
```
|
|
||||||
|
|
||||||
However, you cannot use `INFO`, `WARNING`, `ERROR`, and `FATAL` anymore for
|
|
||||||
functions defined in `glog/logging.h`.
|
|
||||||
|
|
||||||
``` cpp
|
|
||||||
#define GLOG_NO_ABBREVIATED_SEVERITIES
|
|
||||||
#include <windows.h>
|
|
||||||
#include <glog/logging.h>
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// This won’t work.
|
|
||||||
// google::FlushLogFiles(google::ERROR);
|
|
||||||
|
|
||||||
// Use this instead.
|
|
||||||
google::FlushLogFiles(google::GLOG_ERROR);
|
|
||||||
```
|
|
||||||
|
|
||||||
If you don't need `ERROR` defined by `windows.h`, there are a couple of more
|
|
||||||
workarounds which sometimes don't work[^1]:
|
|
||||||
|
|
||||||
- `#!cpp #define WIN32_LEAN_AND_MEAN` or `NOGDI` **before**
|
|
||||||
`#!cpp #include <windows.h>`.
|
|
||||||
- `#!cpp #undef ERROR` **after** `#!cpp #include <windows.h>`.
|
|
||||||
|
|
||||||
[^1]: For more information refer to [this
|
|
||||||
issue](http://code.google.com/p/google-glog/issues/detail?id=33).
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
// 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 <glog/logging.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
struct MyLogSink : google::LogSink { // (1)!
|
|
||||||
void send(google::LogSeverity severity, const char* /*full_filename*/,
|
|
||||||
const char* base_filename, int line,
|
|
||||||
const google::LogMessageTime& /*time*/, const char* message,
|
|
||||||
std::size_t message_len) override {
|
|
||||||
std::cout << google::GetLogSeverityName(severity) << ' ' << base_filename
|
|
||||||
<< ':' << line << ' ';
|
|
||||||
std::copy_n(message, message_len,
|
|
||||||
std::ostreambuf_iterator<char>{std::cout});
|
|
||||||
std::cout << '\n';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
int main(int /*argc*/, char** argv) {
|
|
||||||
google::InitGoogleLogging(argv[0]);
|
|
||||||
|
|
||||||
MyLogSink sink;
|
|
||||||
google::AddLogSink(&sink); // (2)!
|
|
||||||
|
|
||||||
LOG(INFO) << "logging to MySink";
|
|
||||||
|
|
||||||
google::RemoveLogSink(&sink); // (3)!
|
|
||||||
|
|
||||||
// We can directly log to a sink without registering it
|
|
||||||
LOG_TO_SINK(&sink, INFO) << "direct logging"; // (4)!
|
|
||||||
LOG_TO_SINK_BUT_NOT_TO_LOGFILE(&sink, INFO)
|
|
||||||
<< "direct logging but not to file";
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
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
|
|
||||||
filter = src/
|
|
||||||
@ -7,8 +7,6 @@ endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@)
|
|||||||
include (CMakeFindDependencyMacro)
|
include (CMakeFindDependencyMacro)
|
||||||
include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake)
|
include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake)
|
||||||
|
|
||||||
find_dependency (Threads)
|
|
||||||
|
|
||||||
@gflags_DEPENDENCY@
|
@gflags_DEPENDENCY@
|
||||||
@Unwind_DEPENDENCY@
|
@Unwind_DEPENDENCY@
|
||||||
|
|
||||||
|
|||||||
123
mkdocs.yml
123
mkdocs.yml
@ -1,123 +0,0 @@
|
|||||||
---
|
|
||||||
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/master/docs/
|
|
||||||
copyright: Copyright © 2024 Google Inc. & contributors - <a href="#__consent">Change cookie settings</a>
|
|
||||||
markdown_extensions:
|
|
||||||
- admonition
|
|
||||||
- attr_list
|
|
||||||
- def_list
|
|
||||||
- footnotes
|
|
||||||
- md_in_html
|
|
||||||
- pymdownx.details
|
|
||||||
- pymdownx.highlight:
|
|
||||||
anchor_linenums: true
|
|
||||||
line_spans: __span
|
|
||||||
pygments_lang_class: true
|
|
||||||
- pymdownx.inlinehilite
|
|
||||||
- pymdownx.snippets:
|
|
||||||
base_path:
|
|
||||||
- '.'
|
|
||||||
check_paths: true
|
|
||||||
- pymdownx.superfences
|
|
||||||
- tables
|
|
||||||
- toc:
|
|
||||||
permalink: true
|
|
||||||
theme:
|
|
||||||
name: material
|
|
||||||
custom_dir: docs/overrides
|
|
||||||
icon:
|
|
||||||
annotation: material/chevron-right-circle
|
|
||||||
edit: material/pencil
|
|
||||||
repo: fontawesome/brands/git-alt
|
|
||||||
view: material/eye
|
|
||||||
language: en
|
|
||||||
features:
|
|
||||||
- content.action.edit
|
|
||||||
- content.code.annotate
|
|
||||||
- content.code.copy
|
|
||||||
- content.code.select
|
|
||||||
- header.autohide
|
|
||||||
- navigation.expand
|
|
||||||
- navigation.instant.preview
|
|
||||||
- navigation.instant.progress
|
|
||||||
- navigation.prune
|
|
||||||
- navigation.indexes
|
|
||||||
- toc.follow
|
|
||||||
- navigation.top
|
|
||||||
- navigation.path
|
|
||||||
# - navigation.sections
|
|
||||||
# - navigation.tabs
|
|
||||||
# - navigation.tabs.sticky
|
|
||||||
- navigation.tracking
|
|
||||||
- search.highlight
|
|
||||||
- search.share
|
|
||||||
- search.suggest
|
|
||||||
palette:
|
|
||||||
# Palette toggle for automatic mode
|
|
||||||
- media: "(prefers-color-scheme)"
|
|
||||||
toggle:
|
|
||||||
icon: material/brightness-auto
|
|
||||||
name: Switch to light mode
|
|
||||||
# Palette toggle for light mode
|
|
||||||
- media: "(prefers-color-scheme: light)"
|
|
||||||
scheme: default
|
|
||||||
primary: teal
|
|
||||||
accent: green
|
|
||||||
toggle:
|
|
||||||
icon: material/brightness-7
|
|
||||||
name: Switch to dark mode
|
|
||||||
# Palette toggle for dark mode
|
|
||||||
- media: "(prefers-color-scheme: dark)"
|
|
||||||
scheme: slate
|
|
||||||
primary: black
|
|
||||||
toggle:
|
|
||||||
icon: material/brightness-4
|
|
||||||
name: Switch to system preference
|
|
||||||
plugins:
|
|
||||||
- git-revision-date-localized:
|
|
||||||
enable_creation_date: true
|
|
||||||
- git-committers:
|
|
||||||
repository: google/glog
|
|
||||||
branch: master
|
|
||||||
- privacy
|
|
||||||
- search
|
|
||||||
- tags
|
|
||||||
extra:
|
|
||||||
version:
|
|
||||||
alias: true
|
|
||||||
default:
|
|
||||||
- dev
|
|
||||||
- stable
|
|
||||||
provider: mike
|
|
||||||
consent:
|
|
||||||
actions:
|
|
||||||
- manage
|
|
||||||
- accept
|
|
||||||
- reject
|
|
||||||
title: Cookie consent
|
|
||||||
description: >-
|
|
||||||
We use cookies to recognize your repeated visits and preferences, as well
|
|
||||||
as to measure the effectiveness of our documentation and whether users
|
|
||||||
find what they're searching for. With your consent, you're helping us to
|
|
||||||
make our documentation better.
|
|
||||||
nav:
|
|
||||||
- Getting Started:
|
|
||||||
- Overview: index.md
|
|
||||||
- Usage in CMake Projects: usage.md
|
|
||||||
- Building from Source: build.md
|
|
||||||
- Installation using Package Managers: packages.md
|
|
||||||
- User Guide:
|
|
||||||
- Logging: logging.md
|
|
||||||
- Adjusting Output: flags.md
|
|
||||||
- Custom Sinks: sinks.md
|
|
||||||
- Failure Handler: failures.md
|
|
||||||
- Log Removal: log_cleaner.md
|
|
||||||
- Stripping Log Messages: log_stripping.md
|
|
||||||
- System-specific Considerations:
|
|
||||||
- Usage on Windows: windows.md
|
|
||||||
- Linux Unwinder: unwinder.md
|
|
||||||
- Contributing: contribute.md
|
|
||||||
- License: license.md
|
|
||||||
@ -48,66 +48,67 @@
|
|||||||
#ifndef BASE_COMMANDLINEFLAGS_H__
|
#ifndef BASE_COMMANDLINEFLAGS_H__
|
||||||
#define BASE_COMMANDLINEFLAGS_H__
|
#define BASE_COMMANDLINEFLAGS_H__
|
||||||
|
|
||||||
#include <cstdlib> // for getenv
|
#include "config.h"
|
||||||
#include <cstring> // for memchr
|
#include <cstdlib> // for getenv
|
||||||
|
#include <cstring> // for memchr
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "config.h"
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#include <gflags/gflags.h>
|
||||||
|
|
||||||
# include <gflags/gflags.h>
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# include "glog/logging.h"
|
#include <glog/logging.h>
|
||||||
|
|
||||||
# define DECLARE_VARIABLE(type, shorttype, name, tn) \
|
#define DECLARE_VARIABLE(type, shorttype, name, tn) \
|
||||||
namespace fL##shorttype { \
|
namespace fL##shorttype { \
|
||||||
extern GLOG_EXPORT type FLAGS_##name; \
|
extern GLOG_EXPORT type FLAGS_##name; \
|
||||||
} \
|
} \
|
||||||
using fL##shorttype::FLAGS_##name
|
using fL##shorttype::FLAGS_##name
|
||||||
# define DEFINE_VARIABLE(type, shorttype, name, value, meaning, tn) \
|
#define DEFINE_VARIABLE(type, shorttype, name, value, meaning, tn) \
|
||||||
namespace fL##shorttype { \
|
namespace fL##shorttype { \
|
||||||
GLOG_EXPORT type FLAGS_##name(value); \
|
GLOG_EXPORT type FLAGS_##name(value); \
|
||||||
char FLAGS_no##name; \
|
char FLAGS_no##name; \
|
||||||
} \
|
} \
|
||||||
using fL##shorttype::FLAGS_##name
|
using fL##shorttype::FLAGS_##name
|
||||||
|
|
||||||
// bool specialization
|
// bool specialization
|
||||||
# define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name, bool)
|
#define DECLARE_bool(name) \
|
||||||
# define DEFINE_bool(name, value, meaning) \
|
DECLARE_VARIABLE(bool, B, name, bool)
|
||||||
DEFINE_VARIABLE(bool, B, name, value, meaning, bool)
|
#define DEFINE_bool(name, value, meaning) \
|
||||||
|
DEFINE_VARIABLE(bool, B, name, value, meaning, bool)
|
||||||
|
|
||||||
// int32 specialization
|
// int32 specialization
|
||||||
# define DECLARE_int32(name) DECLARE_VARIABLE(google::int32, I, name, int32)
|
#define DECLARE_int32(name) \
|
||||||
# define DEFINE_int32(name, value, meaning) \
|
DECLARE_VARIABLE(GOOGLE_NAMESPACE::int32, I, name, int32)
|
||||||
DEFINE_VARIABLE(google::int32, I, name, value, meaning, int32)
|
#define DEFINE_int32(name, value, meaning) \
|
||||||
|
DEFINE_VARIABLE(GOOGLE_NAMESPACE::int32, I, name, value, meaning, int32)
|
||||||
|
|
||||||
// uint32 specialization
|
// uint32 specialization
|
||||||
# ifndef DECLARE_uint32
|
#ifndef DECLARE_uint32
|
||||||
# define DECLARE_uint32(name) \
|
#define DECLARE_uint32(name) \
|
||||||
DECLARE_VARIABLE(google::uint32, U, name, uint32)
|
DECLARE_VARIABLE(GOOGLE_NAMESPACE::uint32, U, name, uint32)
|
||||||
# endif // DECLARE_uint64
|
#endif // DECLARE_uint64
|
||||||
# define DEFINE_uint32(name, value, meaning) \
|
#define DEFINE_uint32(name, value, meaning) \
|
||||||
DEFINE_VARIABLE(google::uint32, U, name, value, meaning, uint32)
|
DEFINE_VARIABLE(GOOGLE_NAMESPACE::uint32, U, name, value, meaning, uint32)
|
||||||
|
|
||||||
// Special case for string, because we have to specify the namespace
|
// Special case for string, because we have to specify the namespace
|
||||||
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
|
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
|
||||||
# define DECLARE_string(name) \
|
#define DECLARE_string(name) \
|
||||||
namespace fLS { \
|
namespace fLS { \
|
||||||
extern GLOG_EXPORT std::string& FLAGS_##name; \
|
extern GLOG_EXPORT std::string& FLAGS_##name; \
|
||||||
} \
|
} \
|
||||||
using fLS::FLAGS_##name
|
using fLS::FLAGS_##name
|
||||||
# define DEFINE_string(name, value, meaning) \
|
#define DEFINE_string(name, value, meaning) \
|
||||||
namespace fLS { \
|
namespace fLS { \
|
||||||
std::string FLAGS_##name##_buf(value); \
|
std::string FLAGS_##name##_buf(value); \
|
||||||
GLOG_EXPORT std::string& FLAGS_##name = FLAGS_##name##_buf; \
|
GLOG_EXPORT std::string& FLAGS_##name = FLAGS_##name##_buf; \
|
||||||
char FLAGS_no##name; \
|
char FLAGS_no##name; \
|
||||||
} \
|
} \
|
||||||
using fLS::FLAGS_##name
|
using fLS::FLAGS_##name
|
||||||
|
|
||||||
#endif // GLOG_USE_GFLAGS
|
#endif // HAVE_LIB_GFLAGS
|
||||||
|
|
||||||
// Define GLOG_DEFINE_* using DEFINE_* . By using these macros, we
|
// Define GLOG_DEFINE_* using DEFINE_* . By using these macros, we
|
||||||
// have GLOG_* environ variables even if we have gflags installed.
|
// have GLOG_* environ variables even if we have gflags installed.
|
||||||
@ -131,19 +132,16 @@
|
|||||||
// These macros (could be functions, but I don't want to bother with a .cc
|
// These macros (could be functions, but I don't want to bother with a .cc
|
||||||
// file), make it easier to initialize flags from the environment.
|
// file), make it easier to initialize flags from the environment.
|
||||||
|
|
||||||
#define EnvToString(envname, dflt) (!getenv(envname) ? (dflt) : getenv(envname))
|
#define EnvToString(envname, dflt) \
|
||||||
|
(!getenv(envname) ? (dflt) : getenv(envname))
|
||||||
|
|
||||||
#define EnvToBool(envname, dflt) \
|
#define EnvToBool(envname, dflt) \
|
||||||
(!getenv(envname) ? (dflt) \
|
(!getenv(envname) ? (dflt) : memchr("tTyY1\0", getenv(envname)[0], 6) != NULL)
|
||||||
: memchr("tTyY1\0", getenv(envname)[0], 6) != nullptr)
|
|
||||||
|
|
||||||
#define EnvToInt(envname, dflt) \
|
#define EnvToInt(envname, dflt) \
|
||||||
(!getenv(envname) ? (dflt) \
|
(!getenv(envname) ? (dflt) : strtol(getenv(envname), NULL, 10))
|
||||||
: static_cast<int>(strtol(getenv(envname), nullptr, 10)))
|
|
||||||
|
|
||||||
#define EnvToUInt(envname, dflt) \
|
#define EnvToUInt(envname, dflt) \
|
||||||
(!getenv(envname) \
|
(!getenv(envname) ? (dflt) : strtoul(getenv(envname), NULL, 10))
|
||||||
? (dflt) \
|
|
||||||
: static_cast<unsigned>(strtoul(getenv(envname), nullptr, 10)))
|
|
||||||
|
|
||||||
#endif // BASE_COMMANDLINEFLAGS_H__
|
#endif // BASE_COMMANDLINEFLAGS_H__
|
||||||
|
|||||||
@ -35,15 +35,17 @@
|
|||||||
|
|
||||||
class GoogleInitializer {
|
class GoogleInitializer {
|
||||||
public:
|
public:
|
||||||
using void_function = void (*)();
|
typedef void (*void_function)(void);
|
||||||
GoogleInitializer(const char*, void_function f) { f(); }
|
GoogleInitializer(const char*, void_function f) {
|
||||||
|
f();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_MODULE_INITIALIZER(name, body) \
|
#define REGISTER_MODULE_INITIALIZER(name, body) \
|
||||||
namespace { \
|
namespace { \
|
||||||
static void google_init_module_##name() { body; } \
|
static void google_init_module_##name () { body; } \
|
||||||
GoogleInitializer google_initializer_module_##name( \
|
GoogleInitializer google_initializer_module_##name(#name, \
|
||||||
#name, google_init_module_##name); \
|
google_init_module_##name); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _GOOGLEINIT_H */
|
#endif /* _GOOGLEINIT_H */
|
||||||
|
|||||||
333
src/base/mutex.h
Normal file
333
src/base/mutex.h
Normal file
@ -0,0 +1,333 @@
|
|||||||
|
// Copyright (c) 2007, 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: Craig Silverstein.
|
||||||
|
//
|
||||||
|
// A simple mutex wrapper, supporting locks and read-write locks.
|
||||||
|
// You should assume the locks are *not* re-entrant.
|
||||||
|
//
|
||||||
|
// To use: you should define the following macros in your configure.ac:
|
||||||
|
// ACX_PTHREAD
|
||||||
|
// AC_RWLOCK
|
||||||
|
// The latter is defined in ../autoconf.
|
||||||
|
//
|
||||||
|
// This class is meant to be internal-only and should be wrapped by an
|
||||||
|
// internal namespace. Before you use this module, please give the
|
||||||
|
// name of your internal namespace for this module. Or, if you want
|
||||||
|
// to expose it, you'll want to move it to the Google namespace. We
|
||||||
|
// cannot put this class in global namespace because there can be some
|
||||||
|
// problems when we have multiple versions of Mutex in each shared object.
|
||||||
|
//
|
||||||
|
// NOTE: by default, we have #ifdef'ed out the TryLock() method.
|
||||||
|
// This is for two reasons:
|
||||||
|
// 1) TryLock() under Windows is a bit annoying (it requires a
|
||||||
|
// #define to be defined very early).
|
||||||
|
// 2) TryLock() is broken for NO_THREADS mode, at least in NDEBUG
|
||||||
|
// mode.
|
||||||
|
// If you need TryLock(), and either these two caveats are not a
|
||||||
|
// problem for you, or you're willing to work around them, then
|
||||||
|
// feel free to #define GMUTEX_TRYLOCK, or to remove the #ifdefs
|
||||||
|
// in the code below.
|
||||||
|
//
|
||||||
|
// CYGWIN NOTE: Cygwin support for rwlock seems to be buggy:
|
||||||
|
// http://www.cygwin.com/ml/cygwin/2008-12/msg00017.html
|
||||||
|
// Because of that, we might as well use windows locks for
|
||||||
|
// cygwin. They seem to be more reliable than the cygwin pthreads layer.
|
||||||
|
//
|
||||||
|
// TRICKY IMPLEMENTATION NOTE:
|
||||||
|
// This class is designed to be safe to use during
|
||||||
|
// dynamic-initialization -- that is, by global constructors that are
|
||||||
|
// run before main() starts. The issue in this case is that
|
||||||
|
// dynamic-initialization happens in an unpredictable order, and it
|
||||||
|
// could be that someone else's dynamic initializer could call a
|
||||||
|
// function that tries to acquire this mutex -- but that all happens
|
||||||
|
// before this mutex's constructor has run. (This can happen even if
|
||||||
|
// the mutex and the function that uses the mutex are in the same .cc
|
||||||
|
// file.) Basically, because Mutex does non-trivial work in its
|
||||||
|
// constructor, it's not, in the naive implementation, safe to use
|
||||||
|
// before dynamic initialization has run on it.
|
||||||
|
//
|
||||||
|
// The solution used here is to pair the actual mutex primitive with a
|
||||||
|
// bool that is set to true when the mutex is dynamically initialized.
|
||||||
|
// (Before that it's false.) Then we modify all mutex routines to
|
||||||
|
// look at the bool, and not try to lock/unlock until the bool makes
|
||||||
|
// it to true (which happens after the Mutex constructor has run.)
|
||||||
|
//
|
||||||
|
// This works because before main() starts -- particularly, during
|
||||||
|
// dynamic initialization -- there are no threads, so a) it's ok that
|
||||||
|
// the mutex operations are a no-op, since we don't need locking then
|
||||||
|
// anyway; and b) we can be quite confident our bool won't change
|
||||||
|
// state between a call to Lock() and a call to Unlock() (that would
|
||||||
|
// require a global constructor in one translation unit to call Lock()
|
||||||
|
// and another global constructor in another translation unit to call
|
||||||
|
// Unlock() later, which is pretty perverse).
|
||||||
|
//
|
||||||
|
// That said, it's tricky, and can conceivably fail; it's safest to
|
||||||
|
// avoid trying to acquire a mutex in a global constructor, if you
|
||||||
|
// can. One way it can fail is that a really smart compiler might
|
||||||
|
// initialize the bool to true at static-initialization time (too
|
||||||
|
// early) rather than at dynamic-initialization time. To discourage
|
||||||
|
// that, we set is_safe_ to true in code (not the constructor
|
||||||
|
// colon-initializer) and set it to true via a function that always
|
||||||
|
// evaluates to true, but that the compiler can't know always
|
||||||
|
// evaluates to true. This should be good enough.
|
||||||
|
|
||||||
|
#ifndef GOOGLE_MUTEX_H_
|
||||||
|
#define GOOGLE_MUTEX_H_
|
||||||
|
|
||||||
|
#include "config.h" // to figure out pthreads support
|
||||||
|
|
||||||
|
#if defined(NO_THREADS)
|
||||||
|
typedef int MutexType; // to keep a lock-count
|
||||||
|
#elif defined(_WIN32) || defined(__CYGWIN__)
|
||||||
|
# ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
# define WIN32_LEAN_AND_MEAN // We only need minimal includes
|
||||||
|
# endif
|
||||||
|
# ifdef GMUTEX_TRYLOCK
|
||||||
|
// We need Windows NT or later for TryEnterCriticalSection(). If you
|
||||||
|
// don't need that functionality, you can remove these _WIN32_WINNT
|
||||||
|
// lines, and change TryLock() to assert(0) or something.
|
||||||
|
# ifndef _WIN32_WINNT
|
||||||
|
# define _WIN32_WINNT 0x0400
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
// To avoid macro definition of ERROR.
|
||||||
|
# ifndef NOGDI
|
||||||
|
# define NOGDI
|
||||||
|
# endif
|
||||||
|
// To avoid macro definition of min/max.
|
||||||
|
# ifndef NOMINMAX
|
||||||
|
# define NOMINMAX
|
||||||
|
# endif
|
||||||
|
# include <windows.h>
|
||||||
|
typedef CRITICAL_SECTION MutexType;
|
||||||
|
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||||
|
// Needed for pthread_rwlock_*. If it causes problems, you could take it
|
||||||
|
// out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it
|
||||||
|
// *does* cause problems for FreeBSD, or MacOSX, but isn't needed
|
||||||
|
// for locking there.)
|
||||||
|
# ifdef __linux__
|
||||||
|
# ifndef _XOPEN_SOURCE // Some other header might have already set it for us.
|
||||||
|
# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# include <pthread.h>
|
||||||
|
typedef pthread_rwlock_t MutexType;
|
||||||
|
#elif defined(HAVE_PTHREAD)
|
||||||
|
# include <pthread.h>
|
||||||
|
typedef pthread_mutex_t MutexType;
|
||||||
|
#else
|
||||||
|
# error Need to implement mutex.h for your architecture, or #define NO_THREADS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// We need to include these header files after defining _XOPEN_SOURCE
|
||||||
|
// as they may define the _XOPEN_SOURCE macro.
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdlib> // for abort()
|
||||||
|
|
||||||
|
#define MUTEX_NAMESPACE glog_internal_namespace_
|
||||||
|
|
||||||
|
namespace MUTEX_NAMESPACE {
|
||||||
|
|
||||||
|
class Mutex {
|
||||||
|
public:
|
||||||
|
// Create a Mutex that is not held by anybody. This constructor is
|
||||||
|
// typically used for Mutexes allocated on the heap or the stack.
|
||||||
|
// See below for a recommendation for constructing global Mutex
|
||||||
|
// objects.
|
||||||
|
inline Mutex();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
inline ~Mutex();
|
||||||
|
|
||||||
|
inline void Lock(); // Block if needed until free then acquire exclusively
|
||||||
|
inline void Unlock(); // Release a lock acquired via Lock()
|
||||||
|
#ifdef GMUTEX_TRYLOCK
|
||||||
|
inline bool TryLock(); // If free, Lock() and return true, else return false
|
||||||
|
#endif
|
||||||
|
// Note that on systems that don't support read-write locks, these may
|
||||||
|
// be implemented as synonyms to Lock() and Unlock(). So you can use
|
||||||
|
// these for efficiency, but don't use them anyplace where being able
|
||||||
|
// to do shared reads is necessary to avoid deadlock.
|
||||||
|
inline void ReaderLock(); // Block until free or shared then acquire a share
|
||||||
|
inline void ReaderUnlock(); // Release a read share of this Mutex
|
||||||
|
inline void WriterLock() { Lock(); } // Acquire an exclusive lock
|
||||||
|
inline void WriterUnlock() { Unlock(); } // Release a lock from WriterLock()
|
||||||
|
|
||||||
|
// TODO(hamaji): Do nothing, implement correctly.
|
||||||
|
inline void AssertHeld() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
MutexType mutex_;
|
||||||
|
// We want to make sure that the compiler sets is_safe_ to true only
|
||||||
|
// when we tell it to, and never makes assumptions is_safe_ is
|
||||||
|
// always true. volatile is the most reliable way to do that.
|
||||||
|
volatile bool is_safe_;
|
||||||
|
|
||||||
|
inline void SetIsSafe() { is_safe_ = true; }
|
||||||
|
|
||||||
|
// Catch the error of writing Mutex when intending MutexLock.
|
||||||
|
Mutex(Mutex* /*ignored*/) {}
|
||||||
|
// Disallow "evil" constructors
|
||||||
|
Mutex(const Mutex&);
|
||||||
|
void operator=(const Mutex&);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Now the implementation of Mutex for various systems
|
||||||
|
#if defined(NO_THREADS)
|
||||||
|
|
||||||
|
// When we don't have threads, we can be either reading or writing,
|
||||||
|
// but not both. We can have lots of readers at once (in no-threads
|
||||||
|
// mode, that's most likely to happen in recursive function calls),
|
||||||
|
// but only one writer. We represent this by having mutex_ be -1 when
|
||||||
|
// writing and a number > 0 when reading (and 0 when no lock is held).
|
||||||
|
//
|
||||||
|
// In debug mode, we assert these invariants, while in non-debug mode
|
||||||
|
// we do nothing, for efficiency. That's why everything is in an
|
||||||
|
// assert.
|
||||||
|
|
||||||
|
Mutex::Mutex() : mutex_(0) { }
|
||||||
|
Mutex::~Mutex() { assert(mutex_ == 0); }
|
||||||
|
void Mutex::Lock() { assert(--mutex_ == -1); }
|
||||||
|
void Mutex::Unlock() { assert(mutex_++ == -1); }
|
||||||
|
#ifdef GMUTEX_TRYLOCK
|
||||||
|
bool Mutex::TryLock() { if (mutex_) return false; Lock(); return true; }
|
||||||
|
#endif
|
||||||
|
void Mutex::ReaderLock() { assert(++mutex_ > 0); }
|
||||||
|
void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
|
||||||
|
|
||||||
|
#elif defined(_WIN32) || defined(__CYGWIN__)
|
||||||
|
|
||||||
|
Mutex::Mutex() { InitializeCriticalSection(&mutex_); SetIsSafe(); }
|
||||||
|
Mutex::~Mutex() { DeleteCriticalSection(&mutex_); }
|
||||||
|
void Mutex::Lock() { if (is_safe_) EnterCriticalSection(&mutex_); }
|
||||||
|
void Mutex::Unlock() { if (is_safe_) LeaveCriticalSection(&mutex_); }
|
||||||
|
#ifdef GMUTEX_TRYLOCK
|
||||||
|
bool Mutex::TryLock() { return is_safe_ ?
|
||||||
|
TryEnterCriticalSection(&mutex_) != 0 : true; }
|
||||||
|
#endif
|
||||||
|
void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
|
||||||
|
void Mutex::ReaderUnlock() { Unlock(); }
|
||||||
|
|
||||||
|
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||||
|
|
||||||
|
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
|
||||||
|
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
Mutex::Mutex() {
|
||||||
|
SetIsSafe();
|
||||||
|
if (is_safe_ && pthread_rwlock_init(&mutex_, NULL) != 0) abort();
|
||||||
|
}
|
||||||
|
Mutex::~Mutex() { SAFE_PTHREAD(pthread_rwlock_destroy); }
|
||||||
|
void Mutex::Lock() { SAFE_PTHREAD(pthread_rwlock_wrlock); }
|
||||||
|
void Mutex::Unlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
|
||||||
|
#ifdef GMUTEX_TRYLOCK
|
||||||
|
bool Mutex::TryLock() { return is_safe_ ?
|
||||||
|
pthread_rwlock_trywrlock(&mutex_) == 0 :
|
||||||
|
true; }
|
||||||
|
#endif
|
||||||
|
void Mutex::ReaderLock() { SAFE_PTHREAD(pthread_rwlock_rdlock); }
|
||||||
|
void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
|
||||||
|
#undef SAFE_PTHREAD
|
||||||
|
|
||||||
|
#elif defined(HAVE_PTHREAD)
|
||||||
|
|
||||||
|
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
|
||||||
|
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
Mutex::Mutex() {
|
||||||
|
SetIsSafe();
|
||||||
|
if (is_safe_ && pthread_mutex_init(&mutex_, NULL) != 0) abort();
|
||||||
|
}
|
||||||
|
Mutex::~Mutex() { SAFE_PTHREAD(pthread_mutex_destroy); }
|
||||||
|
void Mutex::Lock() { SAFE_PTHREAD(pthread_mutex_lock); }
|
||||||
|
void Mutex::Unlock() { SAFE_PTHREAD(pthread_mutex_unlock); }
|
||||||
|
#ifdef GMUTEX_TRYLOCK
|
||||||
|
bool Mutex::TryLock() { return is_safe_ ?
|
||||||
|
pthread_mutex_trylock(&mutex_) == 0 : true; }
|
||||||
|
#endif
|
||||||
|
void Mutex::ReaderLock() { Lock(); }
|
||||||
|
void Mutex::ReaderUnlock() { Unlock(); }
|
||||||
|
#undef SAFE_PTHREAD
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// Some helper classes
|
||||||
|
|
||||||
|
// MutexLock(mu) acquires mu when constructed and releases it when destroyed.
|
||||||
|
class MutexLock {
|
||||||
|
public:
|
||||||
|
explicit MutexLock(Mutex *mu) : mu_(mu) { mu_->Lock(); }
|
||||||
|
~MutexLock() { mu_->Unlock(); }
|
||||||
|
private:
|
||||||
|
Mutex * const mu_;
|
||||||
|
// Disallow "evil" constructors
|
||||||
|
MutexLock(const MutexLock&);
|
||||||
|
void operator=(const MutexLock&);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ReaderMutexLock and WriterMutexLock do the same, for rwlocks
|
||||||
|
class ReaderMutexLock {
|
||||||
|
public:
|
||||||
|
explicit ReaderMutexLock(Mutex *mu) : mu_(mu) { mu_->ReaderLock(); }
|
||||||
|
~ReaderMutexLock() { mu_->ReaderUnlock(); }
|
||||||
|
private:
|
||||||
|
Mutex * const mu_;
|
||||||
|
// Disallow "evil" constructors
|
||||||
|
ReaderMutexLock(const ReaderMutexLock&);
|
||||||
|
void operator=(const ReaderMutexLock&);
|
||||||
|
};
|
||||||
|
|
||||||
|
class WriterMutexLock {
|
||||||
|
public:
|
||||||
|
explicit WriterMutexLock(Mutex *mu) : mu_(mu) { mu_->WriterLock(); }
|
||||||
|
~WriterMutexLock() { mu_->WriterUnlock(); }
|
||||||
|
private:
|
||||||
|
Mutex * const mu_;
|
||||||
|
// Disallow "evil" constructors
|
||||||
|
WriterMutexLock(const WriterMutexLock&);
|
||||||
|
void operator=(const WriterMutexLock&);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Catch bug where variable name is omitted, e.g. MutexLock (&mu);
|
||||||
|
#define MutexLock(x) COMPILE_ASSERT(0, mutex_lock_decl_missing_var_name)
|
||||||
|
#define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name)
|
||||||
|
#define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name)
|
||||||
|
|
||||||
|
} // namespace MUTEX_NAMESPACE
|
||||||
|
|
||||||
|
using namespace MUTEX_NAMESPACE;
|
||||||
|
|
||||||
|
#undef MUTEX_NAMESPACE
|
||||||
|
|
||||||
|
#endif /* #define GOOGLE_MUTEX_H__ */
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2021, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -27,22 +27,23 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#include <glog/logging.h>
|
||||||
|
#include <glog/raw_logging.h>
|
||||||
|
|
||||||
#include "base/commandlineflags.h"
|
#include "base/commandlineflags.h"
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "glog/raw_logging.h"
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
# include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
using namespace GFLAGS_NAMESPACE;
|
using namespace GFLAGS_NAMESPACE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIB_GMOCK
|
#ifdef HAVE_LIB_GMOCK
|
||||||
# include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
# include "mock-log.h"
|
#include "mock-log.h"
|
||||||
// Introduce several symbols from gmock.
|
// Introduce several symbols from gmock.
|
||||||
using google::glog_testing::ScopedMockLog;
|
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::AnyNumber;
|
using testing::AnyNumber;
|
||||||
@ -52,12 +53,11 @@ using testing::StrictMock;
|
|||||||
using testing::StrNe;
|
using testing::StrNe;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace google;
|
using namespace GOOGLE_NAMESPACE;
|
||||||
|
|
||||||
TEST(CleanImmediately, logging) {
|
TEST(CleanImmediately, logging) {
|
||||||
using namespace std::chrono_literals;
|
|
||||||
google::SetLogFilenameExtension(".foobar");
|
google::SetLogFilenameExtension(".foobar");
|
||||||
google::EnableLogCleaner(0h);
|
google::EnableLogCleaner(0);
|
||||||
|
|
||||||
for (unsigned i = 0; i < 1000; ++i) {
|
for (unsigned i = 0; i < 1000; ++i) {
|
||||||
LOG(INFO) << "cleanup test";
|
LOG(INFO) << "cleanup test";
|
||||||
@ -66,15 +66,15 @@ TEST(CleanImmediately, logging) {
|
|||||||
google::DisableLogCleaner();
|
google::DisableLogCleaner();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv) {
|
||||||
FLAGS_colorlogtostderr = false;
|
FLAGS_colorlogtostderr = false;
|
||||||
FLAGS_timestamp_in_logfile_name = true;
|
FLAGS_timestamp_in_logfile_name = true;
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
ParseCommandLineFlags(&argc, &argv, true);
|
ParseCommandLineFlags(&argc, &argv, true);
|
||||||
#endif
|
#endif
|
||||||
// Make sure stderr is not buffered as stderr seems to be buffered
|
// Make sure stderr is not buffered as stderr seems to be buffered
|
||||||
// on recent windows.
|
// on recent windows.
|
||||||
setbuf(stderr, nullptr);
|
setbuf(stderr, NULL);
|
||||||
|
|
||||||
// Test some basics before InitGoogleLogging:
|
// Test some basics before InitGoogleLogging:
|
||||||
CaptureTestStderr();
|
CaptureTestStderr();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2021, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -27,22 +27,23 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#include <glog/logging.h>
|
||||||
|
#include <glog/raw_logging.h>
|
||||||
|
|
||||||
#include "base/commandlineflags.h"
|
#include "base/commandlineflags.h"
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "glog/raw_logging.h"
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
# include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
using namespace GFLAGS_NAMESPACE;
|
using namespace GFLAGS_NAMESPACE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIB_GMOCK
|
#ifdef HAVE_LIB_GMOCK
|
||||||
# include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
# include "mock-log.h"
|
#include "mock-log.h"
|
||||||
// Introduce several symbols from gmock.
|
// Introduce several symbols from gmock.
|
||||||
using google::glog_testing::ScopedMockLog;
|
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::AnyNumber;
|
using testing::AnyNumber;
|
||||||
@ -52,11 +53,10 @@ using testing::StrictMock;
|
|||||||
using testing::StrNe;
|
using testing::StrNe;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace google;
|
using namespace GOOGLE_NAMESPACE;
|
||||||
|
|
||||||
TEST(CleanImmediatelyWithAbsolutePrefix, logging) {
|
TEST(CleanImmediatelyWithAbsolutePrefix, logging) {
|
||||||
using namespace std::chrono_literals;
|
google::EnableLogCleaner(0);
|
||||||
google::EnableLogCleaner(0h);
|
|
||||||
google::SetLogFilenameExtension(".barfoo");
|
google::SetLogFilenameExtension(".barfoo");
|
||||||
google::SetLogDestination(GLOG_INFO, "test_cleanup_");
|
google::SetLogDestination(GLOG_INFO, "test_cleanup_");
|
||||||
|
|
||||||
@ -71,15 +71,15 @@ TEST(CleanImmediatelyWithAbsolutePrefix, logging) {
|
|||||||
google::DisableLogCleaner();
|
google::DisableLogCleaner();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv) {
|
||||||
FLAGS_colorlogtostderr = false;
|
FLAGS_colorlogtostderr = false;
|
||||||
FLAGS_timestamp_in_logfile_name = true;
|
FLAGS_timestamp_in_logfile_name = true;
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
ParseCommandLineFlags(&argc, &argv, true);
|
ParseCommandLineFlags(&argc, &argv, true);
|
||||||
#endif
|
#endif
|
||||||
// Make sure stderr is not buffered as stderr seems to be buffered
|
// Make sure stderr is not buffered as stderr seems to be buffered
|
||||||
// on recent windows.
|
// on recent windows.
|
||||||
setbuf(stderr, nullptr);
|
setbuf(stderr, NULL);
|
||||||
|
|
||||||
// Test some basics before InitGoogleLogging:
|
// Test some basics before InitGoogleLogging:
|
||||||
CaptureTestStderr();
|
CaptureTestStderr();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2021, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -27,22 +27,23 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#include <glog/logging.h>
|
||||||
|
#include <glog/raw_logging.h>
|
||||||
|
|
||||||
#include "base/commandlineflags.h"
|
#include "base/commandlineflags.h"
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "glog/raw_logging.h"
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
# include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
using namespace GFLAGS_NAMESPACE;
|
using namespace GFLAGS_NAMESPACE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIB_GMOCK
|
#ifdef HAVE_LIB_GMOCK
|
||||||
# include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
# include "mock-log.h"
|
#include "mock-log.h"
|
||||||
// Introduce several symbols from gmock.
|
// Introduce several symbols from gmock.
|
||||||
using google::glog_testing::ScopedMockLog;
|
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::AnyNumber;
|
using testing::AnyNumber;
|
||||||
@ -52,11 +53,10 @@ using testing::StrictMock;
|
|||||||
using testing::StrNe;
|
using testing::StrNe;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace google;
|
using namespace GOOGLE_NAMESPACE;
|
||||||
|
|
||||||
TEST(CleanImmediatelyWithRelativePrefix, logging) {
|
TEST(CleanImmediatelyWithRelativePrefix, logging) {
|
||||||
using namespace std::chrono_literals;
|
google::EnableLogCleaner(0);
|
||||||
google::EnableLogCleaner(0h);
|
|
||||||
google::SetLogFilenameExtension(".relativefoo");
|
google::SetLogFilenameExtension(".relativefoo");
|
||||||
google::SetLogDestination(GLOG_INFO, "test_subdir/test_cleanup_");
|
google::SetLogDestination(GLOG_INFO, "test_subdir/test_cleanup_");
|
||||||
|
|
||||||
@ -67,15 +67,15 @@ TEST(CleanImmediatelyWithRelativePrefix, logging) {
|
|||||||
google::DisableLogCleaner();
|
google::DisableLogCleaner();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv) {
|
||||||
FLAGS_colorlogtostderr = false;
|
FLAGS_colorlogtostderr = false;
|
||||||
FLAGS_timestamp_in_logfile_name = true;
|
FLAGS_timestamp_in_logfile_name = true;
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
ParseCommandLineFlags(&argc, &argv, true);
|
ParseCommandLineFlags(&argc, &argv, true);
|
||||||
#endif
|
#endif
|
||||||
// Make sure stderr is not buffered as stderr seems to be buffered
|
// Make sure stderr is not buffered as stderr seems to be buffered
|
||||||
// on recent windows.
|
// on recent windows.
|
||||||
setbuf(stderr, nullptr);
|
setbuf(stderr, NULL);
|
||||||
|
|
||||||
// Test some basics before InitGoogleLogging:
|
// Test some basics before InitGoogleLogging:
|
||||||
CaptureTestStderr();
|
CaptureTestStderr();
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
#ifndef GLOG_CONFIG_H
|
#ifndef GLOG_CONFIG_H
|
||||||
#define GLOG_CONFIG_H
|
#define GLOG_CONFIG_H
|
||||||
|
|
||||||
|
/* define if glog doesn't use RTTI */
|
||||||
|
#cmakedefine DISABLE_RTTI
|
||||||
|
|
||||||
|
/* Namespace for Google classes */
|
||||||
|
#cmakedefine GOOGLE_NAMESPACE ${GOOGLE_NAMESPACE}
|
||||||
|
|
||||||
/* Define if you have the `dladdr' function */
|
/* Define if you have the `dladdr' function */
|
||||||
#cmakedefine HAVE_DLADDR
|
#cmakedefine HAVE_DLADDR
|
||||||
|
|
||||||
|
/* Define if you have the `snprintf' function */
|
||||||
|
#cmakedefine HAVE_SNPRINTF
|
||||||
|
|
||||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
#cmakedefine HAVE_DLFCN_H
|
#cmakedefine HAVE_DLFCN_H
|
||||||
|
|
||||||
/* Define if you have the `backtrace' function in <execinfo.h> */
|
/* Define to 1 if you have the <execinfo.h> header file. */
|
||||||
#cmakedefine HAVE_EXECINFO_BACKTRACE
|
#cmakedefine HAVE_EXECINFO_H
|
||||||
|
|
||||||
/* Define if you have the `backtrace_symbols' function in <execinfo.h> */
|
|
||||||
#cmakedefine HAVE_EXECINFO_BACKTRACE_SYMBOLS
|
|
||||||
|
|
||||||
/* Define if you have the `fcntl' function */
|
/* Define if you have the `fcntl' function */
|
||||||
#cmakedefine HAVE_FCNTL
|
#cmakedefine HAVE_FCNTL
|
||||||
@ -19,6 +25,15 @@
|
|||||||
/* Define to 1 if you have the <glob.h> header file. */
|
/* Define to 1 if you have the <glob.h> header file. */
|
||||||
#cmakedefine HAVE_GLOB_H
|
#cmakedefine HAVE_GLOB_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `pthread' library (-lpthread). */
|
||||||
|
#cmakedefine HAVE_LIBPTHREAD
|
||||||
|
|
||||||
|
/* define if you have google gflags library */
|
||||||
|
#cmakedefine HAVE_LIB_GFLAGS
|
||||||
|
|
||||||
/* define if you have google gmock library */
|
/* define if you have google gmock library */
|
||||||
#cmakedefine HAVE_LIB_GMOCK
|
#cmakedefine HAVE_LIB_GMOCK
|
||||||
|
|
||||||
@ -28,11 +43,23 @@
|
|||||||
/* define if you have dbghelp library */
|
/* define if you have dbghelp library */
|
||||||
#cmakedefine HAVE_DBGHELP
|
#cmakedefine HAVE_DBGHELP
|
||||||
|
|
||||||
|
/* define if you have libunwind */
|
||||||
|
#cmakedefine HAVE_LIB_UNWIND
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
|
#cmakedefine HAVE_MEMORY_H
|
||||||
|
|
||||||
|
/* define to disable multithreading support. */
|
||||||
|
#cmakedefine NO_THREADS
|
||||||
|
|
||||||
|
/* define if the compiler implements namespaces */
|
||||||
|
#cmakedefine HAVE_NAMESPACES
|
||||||
|
|
||||||
/* Define if you have the 'pread' function */
|
/* Define if you have the 'pread' function */
|
||||||
#cmakedefine HAVE_PREAD
|
#cmakedefine HAVE_PREAD
|
||||||
|
|
||||||
/* Define if you have the 'posix_fadvise' function in <fcntl.h> */
|
/* Define if you have POSIX threads libraries and header files. */
|
||||||
#cmakedefine HAVE_POSIX_FADVISE
|
#cmakedefine HAVE_PTHREAD
|
||||||
|
|
||||||
/* Define to 1 if you have the <pwd.h> header file. */
|
/* Define to 1 if you have the <pwd.h> header file. */
|
||||||
#cmakedefine HAVE_PWD_H
|
#cmakedefine HAVE_PWD_H
|
||||||
@ -40,26 +67,29 @@
|
|||||||
/* Define if you have the 'pwrite' function */
|
/* Define if you have the 'pwrite' function */
|
||||||
#cmakedefine HAVE_PWRITE
|
#cmakedefine HAVE_PWRITE
|
||||||
|
|
||||||
|
/* define if the compiler implements pthread_rwlock_* */
|
||||||
|
#cmakedefine HAVE_RWLOCK
|
||||||
|
|
||||||
/* Define if you have the 'sigaction' function */
|
/* Define if you have the 'sigaction' function */
|
||||||
#cmakedefine HAVE_SIGACTION
|
#cmakedefine HAVE_SIGACTION
|
||||||
|
|
||||||
/* Define if you have the `sigaltstack' function */
|
/* Define if you have the `sigaltstack' function */
|
||||||
#cmakedefine HAVE_SIGALTSTACK
|
#cmakedefine HAVE_SIGALTSTACK
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdint.h> header file. */
|
||||||
|
#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <strings.h> header file. */
|
||||||
|
#cmakedefine HAVE_STRINGS_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <syscall.h> header file. */
|
/* Define to 1 if you have the <syscall.h> header file. */
|
||||||
#cmakedefine HAVE_SYSCALL_H
|
#cmakedefine HAVE_SYSCALL_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <syslog.h> header file. */
|
/* Define to 1 if you have the <syslog.h> header file. */
|
||||||
#cmakedefine HAVE_SYSLOG_H
|
#cmakedefine HAVE_SYSLOG_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <elf.h> header file. */
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
#cmakedefine HAVE_ELF_H
|
#cmakedefine HAVE_SYS_STAT_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/exec_elf.h> header file. */
|
|
||||||
#cmakedefine HAVE_SYS_EXEC_ELF_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <link.h> header file. */
|
|
||||||
#cmakedefine HAVE_LINK_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_SYSCALL_H
|
#cmakedefine HAVE_SYS_SYSCALL_H
|
||||||
@ -68,7 +98,7 @@
|
|||||||
#cmakedefine HAVE_SYS_TIME_H
|
#cmakedefine HAVE_SYS_TIME_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_TYPES_H
|
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/ucontext.h> header file. */
|
/* Define to 1 if you have the <sys/ucontext.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_UCONTEXT_H
|
#cmakedefine HAVE_SYS_UCONTEXT_H
|
||||||
@ -85,11 +115,23 @@
|
|||||||
/* Define to 1 if you have the <unistd.h> header file. */
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
|
#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
|
||||||
|
|
||||||
/* define if you have unwind */
|
/* Define if you have the <unwind.h> header file. */
|
||||||
#cmakedefine HAVE_UNWIND
|
#cmakedefine HAVE_UNWIND_H
|
||||||
|
|
||||||
/* define if you have libunwind */
|
/* Define if you linking to _Unwind_Backtrace is possible. */
|
||||||
#cmakedefine HAVE_LIBUNWIND
|
#cmakedefine HAVE__UNWIND_BACKTRACE
|
||||||
|
|
||||||
|
/* define if the compiler supports using expression for operator */
|
||||||
|
#cmakedefine HAVE_USING_OPERATOR
|
||||||
|
|
||||||
|
/* define if your compiler has __attribute__ */
|
||||||
|
#cmakedefine HAVE___ATTRIBUTE__
|
||||||
|
|
||||||
|
/* define if your compiler has __builtin_expect */
|
||||||
|
#cmakedefine HAVE___BUILTIN_EXPECT ${HAVE___BUILTIN_EXPECT}
|
||||||
|
|
||||||
|
/* define if your compiler has __sync_val_compare_and_swap */
|
||||||
|
#cmakedefine HAVE___SYNC_VAL_COMPARE_AND_SWAP
|
||||||
|
|
||||||
/* define if symbolize support is available */
|
/* define if symbolize support is available */
|
||||||
#cmakedefine HAVE_SYMBOLIZE
|
#cmakedefine HAVE_SYMBOLIZE
|
||||||
@ -100,43 +142,90 @@
|
|||||||
/* define if gmtime_r is available in time.h */
|
/* define if gmtime_r is available in time.h */
|
||||||
#cmakedefine HAVE_GMTIME_R
|
#cmakedefine HAVE_GMTIME_R
|
||||||
|
|
||||||
/* define if _chsize_s is available in io.h */
|
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||||
#cmakedefine HAVE__CHSIZE_S
|
*/
|
||||||
|
#cmakedefine LT_OBJDIR
|
||||||
|
|
||||||
/* define if ssize_t is defined */
|
/* Name of package */
|
||||||
#cmakedefine HAVE_SSIZE_T
|
#cmakedefine PACKAGE
|
||||||
|
|
||||||
/* define if mode_t is defined */
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
#cmakedefine HAVE_MODE_T
|
#cmakedefine PACKAGE_BUGREPORT
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#cmakedefine PACKAGE_NAME
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#cmakedefine PACKAGE_STRING
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#cmakedefine PACKAGE_TARNAME
|
||||||
|
|
||||||
|
/* Define to the home page for this package. */
|
||||||
|
#cmakedefine PACKAGE_URL
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#cmakedefine PACKAGE_VERSION
|
||||||
|
|
||||||
/* How to access the PC from a struct ucontext */
|
/* How to access the PC from a struct ucontext */
|
||||||
#cmakedefine PC_FROM_UCONTEXT ${PC_FROM_UCONTEXT}
|
#cmakedefine PC_FROM_UCONTEXT
|
||||||
|
|
||||||
/* define if we should print file offsets in traces instead of symbolizing. */
|
/* define if we should print file offsets in traces instead of symbolizing. */
|
||||||
#cmakedefine PRINT_UNSYMBOLIZED_STACK_TRACES
|
#cmakedefine PRINT_UNSYMBOLIZED_STACK_TRACES
|
||||||
|
|
||||||
|
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||||
|
your system. */
|
||||||
|
#cmakedefine PTHREAD_CREATE_JOINABLE
|
||||||
|
|
||||||
/* The size of `void *', as computed by sizeof. */
|
/* The size of `void *', as computed by sizeof. */
|
||||||
#cmakedefine SIZEOF_VOID_P ${SIZEOF_VOID_P}
|
#cmakedefine SIZEOF_VOID_P ${SIZEOF_VOID_P}
|
||||||
|
|
||||||
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
|
#cmakedefine STDC_HEADERS
|
||||||
|
|
||||||
|
/* the namespace where STL code like vector<> is defined */
|
||||||
|
#cmakedefine STL_NAMESPACE ${STL_NAMESPACE}
|
||||||
|
|
||||||
/* location of source code */
|
/* location of source code */
|
||||||
#cmakedefine TEST_SRC_DIR ${TEST_SRC_DIR}
|
#cmakedefine TEST_SRC_DIR ${TEST_SRC_DIR}
|
||||||
|
|
||||||
/* Define if thread-local storage is enabled. */
|
/* Define to necessary thread-local storage attribute. */
|
||||||
#cmakedefine GLOG_THREAD_LOCAL_STORAGE
|
#cmakedefine GLOG_THREAD_LOCAL_STORAGE ${GLOG_THREAD_LOCAL_STORAGE}
|
||||||
|
|
||||||
/* define if abi::__cxa_demangle is available in cxxabi.h */
|
/* Check whether aligned_storage and alignof present */
|
||||||
#cmakedefine HAVE___CXA_DEMANGLE
|
#cmakedefine HAVE_ALIGNED_STORAGE ${HAVE_ALIGNED_STORAGE}
|
||||||
|
|
||||||
/* define if __argv is available in cstdlib */
|
/* Check whether C++11 atomic is available */
|
||||||
#cmakedefine HAVE___ARGV
|
#cmakedefine HAVE_CXX11_ATOMIC ${HAVE_CXX11_ATOMIC}
|
||||||
|
|
||||||
/* define if __progname is available */
|
/* Check whether C++11 chrono is available */
|
||||||
#cmakedefine HAVE___PROGNAME
|
#cmakedefine HAVE_CXX11_CHRONO ${HAVE_CXX11_CHRONO}
|
||||||
|
|
||||||
/* define if getprogname is available in cstdlib */
|
/* Check whether C++11 nullptr_t is available */
|
||||||
#cmakedefine HAVE_GETPROGNAME
|
#cmakedefine HAVE_CXX11_NULLPTR_T ${HAVE_CXX11_NULLPTR_T}
|
||||||
|
|
||||||
/* define if program_invocation_short_name is available in cerrno */
|
/* Version number of package */
|
||||||
#cmakedefine HAVE_PROGRAM_INVOCATION_SHORT_NAME
|
#cmakedefine VERSION
|
||||||
|
|
||||||
|
#ifdef GLOG_BAZEL_BUILD
|
||||||
|
|
||||||
|
/* TODO(rodrigoq): remove this workaround once bazel#3979 is resolved:
|
||||||
|
* https://github.com/bazelbuild/bazel/issues/3979 */
|
||||||
|
#define _START_GOOGLE_NAMESPACE_ namespace GOOGLE_NAMESPACE {
|
||||||
|
|
||||||
|
#define _END_GOOGLE_NAMESPACE_ }
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* Stops putting the code inside the Google namespace */
|
||||||
|
#cmakedefine _END_GOOGLE_NAMESPACE_ ${_END_GOOGLE_NAMESPACE_}
|
||||||
|
|
||||||
|
/* Puts following code inside the Google namespace */
|
||||||
|
#cmakedefine _START_GOOGLE_NAMESPACE_ ${_START_GOOGLE_NAMESPACE_}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Replacement for deprecated syscall(SYS_gettid) on macOS. */
|
||||||
|
#cmakedefine HAVE_PTHREAD_THREADID_NP ${HAVE_PTHREAD_THREADID_NP}
|
||||||
|
|
||||||
#endif // GLOG_CONFIG_H
|
#endif // GLOG_CONFIG_H
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
cmake_minimum_required (VERSION 3.16)
|
|
||||||
project (glog_log_severity LANGUAGES CXX)
|
|
||||||
|
|
||||||
find_package (glog REQUIRED NO_MODULE)
|
|
||||||
|
|
||||||
add_executable (glog_dcheck glog_dcheck.cc)
|
|
||||||
target_link_libraries (glog_dcheck PRIVATE glog::glog)
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
// 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 <glog/logging.h>
|
|
||||||
|
|
||||||
int main(int /*argc*/, char** argv) {
|
|
||||||
google::InitGoogleLogging(argv[0]);
|
|
||||||
google::InstallFailureSignalHandler();
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
// Avoid presenting an interactive dialog that will cause the test to time
|
|
||||||
// out.
|
|
||||||
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
|
||||||
#endif // defined(_MSC_VER)
|
|
||||||
|
|
||||||
DLOG(INFO) << "no output";
|
|
||||||
DLOG(WARNING) << "no output";
|
|
||||||
DLOG(ERROR) << "no output";
|
|
||||||
|
|
||||||
// Must not fail in release build
|
|
||||||
DLOG_ASSERT(false);
|
|
||||||
|
|
||||||
// Must be the last expression
|
|
||||||
DLOG(FATAL) << "no output";
|
|
||||||
}
|
|
||||||
693
src/demangle.cc
693
src/demangle.cc
File diff suppressed because it is too large
Load Diff
@ -67,28 +67,19 @@
|
|||||||
// C++ ABI in the future.
|
// C++ ABI in the future.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef GLOG_INTERNAL_DEMANGLE_H
|
#ifndef BASE_DEMANGLE_H_
|
||||||
#define GLOG_INTERNAL_DEMANGLE_H
|
#define BASE_DEMANGLE_H_
|
||||||
|
|
||||||
#include <cstddef>
|
#include "config.h"
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
_START_GOOGLE_NAMESPACE_
|
||||||
# include "glog/export.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(GLOG_NO_EXPORT)
|
|
||||||
# error "demangle.h" was not included correctly.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace google {
|
|
||||||
inline namespace glog_internal_namespace_ {
|
|
||||||
|
|
||||||
// Demangle "mangled". On success, return true and write the
|
// Demangle "mangled". On success, return true and write the
|
||||||
// demangled symbol name to "out". Otherwise, return false.
|
// demangled symbol name to "out". Otherwise, return false.
|
||||||
// "out" is modified even if demangling is unsuccessful.
|
// "out" is modified even if demangling is unsuccessful.
|
||||||
bool GLOG_NO_EXPORT Demangle(const char* mangled, char* out, size_t out_size);
|
bool GLOG_EXPORT Demangle(const char *mangled, char *out, size_t out_size);
|
||||||
|
|
||||||
} // namespace glog_internal_namespace_
|
_END_GOOGLE_NAMESPACE_
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
#endif // GLOG_INTERNAL_DEMANGLE_H
|
#endif // BASE_DEMANGLE_H_
|
||||||
|
|||||||
@ -31,19 +31,18 @@
|
|||||||
//
|
//
|
||||||
// Unit tests for functions in demangle.c.
|
// Unit tests for functions in demangle.c.
|
||||||
|
|
||||||
#include "demangle.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "googletest.h"
|
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#include <iostream>
|
||||||
# include <gflags/gflags.h>
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <glog/logging.h>
|
||||||
|
#include "demangle.h"
|
||||||
|
#include "googletest.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
|
#include <gflags/gflags.h>
|
||||||
using namespace GFLAGS_NAMESPACE;
|
using namespace GFLAGS_NAMESPACE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -51,10 +50,10 @@ GLOG_DEFINE_bool(demangle_filter, false,
|
|||||||
"Run demangle_unittest in filter mode");
|
"Run demangle_unittest in filter mode");
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace google;
|
using namespace GOOGLE_NAMESPACE;
|
||||||
|
|
||||||
// A wrapper function for Demangle() to make the unit test simple.
|
// A wrapper function for Demangle() to make the unit test simple.
|
||||||
static const char* DemangleIt(const char* const mangled) {
|
static const char *DemangleIt(const char * const mangled) {
|
||||||
static char demangled[4096];
|
static char demangled[4096];
|
||||||
if (Demangle(mangled, demangled, sizeof(demangled))) {
|
if (Demangle(mangled, demangled, sizeof(demangled))) {
|
||||||
return demangled;
|
return demangled;
|
||||||
@ -65,25 +64,28 @@ static const char* DemangleIt(const char* const mangled) {
|
|||||||
|
|
||||||
#if defined(GLOG_OS_WINDOWS)
|
#if defined(GLOG_OS_WINDOWS)
|
||||||
|
|
||||||
# if defined(HAVE_DBGHELP) && !defined(NDEBUG)
|
#if defined(HAVE_DBGHELP) && !defined(NDEBUG)
|
||||||
TEST(Demangle, Windows) {
|
TEST(Demangle, Windows) {
|
||||||
EXPECT_STREQ("public: static void __cdecl Foo::func(int)",
|
EXPECT_STREQ(
|
||||||
DemangleIt("?func@Foo@@SAXH@Z"));
|
"public: static void __cdecl Foo::func(int)",
|
||||||
EXPECT_STREQ("public: static void __cdecl Foo::func(int)",
|
DemangleIt("?func@Foo@@SAXH@Z"));
|
||||||
DemangleIt("@ILT+1105(?func@Foo@@SAXH@Z)"));
|
EXPECT_STREQ(
|
||||||
EXPECT_STREQ("int __cdecl foobarArray(int * const)",
|
"public: static void __cdecl Foo::func(int)",
|
||||||
DemangleIt("?foobarArray@@YAHQAH@Z"));
|
DemangleIt("@ILT+1105(?func@Foo@@SAXH@Z)"));
|
||||||
|
EXPECT_STREQ(
|
||||||
|
"int __cdecl foobarArray(int * const)",
|
||||||
|
DemangleIt("?foobarArray@@YAHQAH@Z"));
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Test corner cases of boundary conditions.
|
// Test corner cases of bounary conditions.
|
||||||
TEST(Demangle, CornerCases) {
|
TEST(Demangle, CornerCases) {
|
||||||
const size_t size = 10;
|
const size_t size = 10;
|
||||||
char tmp[size] = {0};
|
char tmp[size] = { 0 };
|
||||||
const char* demangled = "foobar()";
|
const char *demangled = "foobar()";
|
||||||
const char* mangled = "_Z6foobarv";
|
const char *mangled = "_Z6foobarv";
|
||||||
EXPECT_TRUE(Demangle(mangled, tmp, sizeof(tmp)));
|
EXPECT_TRUE(Demangle(mangled, tmp, sizeof(tmp)));
|
||||||
// sizeof("foobar()") == size - 1
|
// sizeof("foobar()") == size - 1
|
||||||
EXPECT_STREQ(demangled, tmp);
|
EXPECT_STREQ(demangled, tmp);
|
||||||
@ -92,7 +94,7 @@ TEST(Demangle, CornerCases) {
|
|||||||
EXPECT_FALSE(Demangle(mangled, tmp, size - 2)); // Not enough.
|
EXPECT_FALSE(Demangle(mangled, tmp, size - 2)); // Not enough.
|
||||||
EXPECT_FALSE(Demangle(mangled, tmp, 1));
|
EXPECT_FALSE(Demangle(mangled, tmp, 1));
|
||||||
EXPECT_FALSE(Demangle(mangled, tmp, 0));
|
EXPECT_FALSE(Demangle(mangled, tmp, 0));
|
||||||
EXPECT_FALSE(Demangle(mangled, nullptr, 0)); // Should not cause SEGV.
|
EXPECT_FALSE(Demangle(mangled, NULL, 0)); // Should not cause SEGV.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test handling of functions suffixed with .clone.N, which is used by GCC
|
// Test handling of functions suffixed with .clone.N, which is used by GCC
|
||||||
@ -144,11 +146,11 @@ TEST(Demangle, FromFile) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv) {
|
||||||
InitGoogleTest(&argc, argv);
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
#ifdef GLOG_USE_GFLAGS
|
|
||||||
ParseCommandLineFlags(&argc, &argv, true);
|
ParseCommandLineFlags(&argc, &argv, true);
|
||||||
#endif
|
#endif
|
||||||
|
InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
FLAGS_logtostderr = true;
|
FLAGS_logtostderr = true;
|
||||||
InitGoogleLogging(argv[0]);
|
InitGoogleLogging(argv[0]);
|
||||||
|
|||||||
@ -143,10 +143,3 @@ _Zrm1XS_ operator%()
|
|||||||
# Template argument packs can start with I or J.
|
# Template argument packs can start with I or J.
|
||||||
_Z3addIIiEEvDpT_ add<>()
|
_Z3addIIiEEvDpT_ add<>()
|
||||||
_Z3addIJiEEvDpT_ add<>()
|
_Z3addIJiEEvDpT_ add<>()
|
||||||
|
|
||||||
# Nested templates with pack expansion
|
|
||||||
_ZSt13__invoke_implIvPFvPiEJDnEET_St14__invoke_otherOT0_DpOT1_ std::__invoke_impl<>()
|
|
||||||
_ZSt8__invokeIPFvPiEJDnEENSt15__invoke_resultIT_JDpT0_EE4typeEOS4_DpOS5_ std::__invoke<>()
|
|
||||||
_ZNSt6thread8_InvokerISt5tupleIJPFvPiEDnEEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE std::thread::_Invoker<>::_M_invoke<>()
|
|
||||||
_ZNSt6thread8_InvokerISt5tupleIJPFvPiEDnEEEclEv std::thread::_Invoker<>::operator()()
|
|
||||||
_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFvPiEDnEEEEE6_M_runEv std::thread::_State_impl<>::_M_run()
|
|
||||||
|
|||||||
158
src/flags.cc
158
src/flags.cc
@ -1,158 +0,0 @@
|
|||||||
// 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 <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#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.
|
|
||||||
GLOG_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 <module name>=<log level>."
|
|
||||||
" <module name> is a glob pattern, matched against the filename base"
|
|
||||||
" (that is, name ignoring .cc/.h./-inl.h)."
|
|
||||||
" <log level> overrides any value given by --v.");
|
|
||||||
|
|
||||||
GLOG_DEFINE_bool(symbolize_stacktrace, true,
|
|
||||||
"Symbolize the stack trace in the tombstone");
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
// Copyright 2023 Google LLC
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include "demangle.h"
|
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const unsigned char* Data,
|
|
||||||
unsigned Size) {
|
|
||||||
if (Size >= 4095) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char Buffer[Size + 1];
|
|
||||||
std::memcpy(Buffer, Data, Size);
|
|
||||||
Buffer[Size] = 0;
|
|
||||||
char demangled[4096];
|
|
||||||
google::Demangle(Buffer, demangled, Size);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
191
src/glog/flags.h
191
src/glog/flags.h
@ -1,191 +0,0 @@
|
|||||||
// 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 <string>
|
|
||||||
|
|
||||||
#if defined(GLOG_USE_GFLAGS)
|
|
||||||
# include <gflags/gflags.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
|
||||||
# include "glog/export.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(GLOG_EXPORT)
|
|
||||||
# error <glog/flags.h> was not included correctly. See the documentation for how to consume the library.
|
|
||||||
#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
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2007, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -30,16 +30,6 @@
|
|||||||
#ifndef BASE_LOG_SEVERITY_H__
|
#ifndef BASE_LOG_SEVERITY_H__
|
||||||
#define BASE_LOG_SEVERITY_H__
|
#define BASE_LOG_SEVERITY_H__
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
|
||||||
# include "glog/export.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(GLOG_EXPORT)
|
|
||||||
# error <glog/log_severity.h> was not included correctly. See the documentation for how to consume the library.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace google {
|
|
||||||
|
|
||||||
// The recommended semantics of the log levels are as follows:
|
// The recommended semantics of the log levels are as follows:
|
||||||
//
|
//
|
||||||
// INFO:
|
// INFO:
|
||||||
@ -58,43 +48,27 @@ namespace google {
|
|||||||
// Variables of type LogSeverity are widely taken to lie in the range
|
// Variables of type LogSeverity are widely taken to lie in the range
|
||||||
// [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if
|
// [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if
|
||||||
// you ever need to change their values or add a new severity.
|
// you ever need to change their values or add a new severity.
|
||||||
|
typedef int LogSeverity;
|
||||||
|
|
||||||
enum LogSeverity {
|
const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3,
|
||||||
GLOG_INFO = 0,
|
NUM_SEVERITIES = 4;
|
||||||
GLOG_WARNING = 1,
|
|
||||||
GLOG_ERROR = 2,
|
|
||||||
GLOG_FATAL = 3,
|
|
||||||
#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
|
#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
|
||||||
# ifdef ERROR
|
# ifdef ERROR
|
||||||
# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
|
# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
|
||||||
# endif
|
# endif
|
||||||
INFO = GLOG_INFO,
|
const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
|
||||||
WARNING = GLOG_WARNING,
|
ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
|
||||||
ERROR = GLOG_ERROR,
|
|
||||||
FATAL = GLOG_FATAL
|
|
||||||
#endif
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(__cpp_inline_variables)
|
|
||||||
# if (__cpp_inline_variables >= 201606L)
|
|
||||||
# define GLOG_INLINE_VARIABLE inline
|
|
||||||
# endif // (__cpp_inline_variables >= 201606L)
|
|
||||||
#endif // defined(__cpp_inline_variables)
|
|
||||||
|
|
||||||
#if !defined(GLOG_INLINE_VARIABLE)
|
|
||||||
# define GLOG_INLINE_VARIABLE
|
|
||||||
#endif // !defined(GLOG_INLINE_VARIABLE)
|
|
||||||
|
|
||||||
GLOG_INLINE_VARIABLE
|
|
||||||
constexpr int NUM_SEVERITIES = 4;
|
|
||||||
|
|
||||||
// DFATAL is FATAL in debug mode, ERROR in normal mode
|
// DFATAL is FATAL in debug mode, ERROR in normal mode
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
# define DFATAL_LEVEL ERROR
|
#define DFATAL_LEVEL ERROR
|
||||||
#else
|
#else
|
||||||
# define DFATAL_LEVEL FATAL
|
#define DFATAL_LEVEL FATAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern GLOG_EXPORT const char* const LogSeverityNames[NUM_SEVERITIES];
|
||||||
|
|
||||||
// NDEBUG usage helpers related to (RAW_)DCHECK:
|
// NDEBUG usage helpers related to (RAW_)DCHECK:
|
||||||
//
|
//
|
||||||
// DEBUG_MODE is for small !NDEBUG uses like
|
// DEBUG_MODE is for small !NDEBUG uses like
|
||||||
@ -115,12 +89,10 @@ constexpr int NUM_SEVERITIES = 4;
|
|||||||
//
|
//
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
enum { DEBUG_MODE = 0 };
|
enum { DEBUG_MODE = 0 };
|
||||||
# define IF_DEBUG_MODE(x)
|
#define IF_DEBUG_MODE(x)
|
||||||
#else
|
#else
|
||||||
enum { DEBUG_MODE = 1 };
|
enum { DEBUG_MODE = 1 };
|
||||||
# define IF_DEBUG_MODE(x) x
|
#define IF_DEBUG_MODE(x) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
#endif // BASE_LOG_SEVERITY_H__
|
#endif // BASE_LOG_SEVERITY_H__
|
||||||
|
|||||||
1679
src/glog/logging.h
1679
src/glog/logging.h
File diff suppressed because it is too large
Load Diff
2002
src/glog/logging.h.in
Normal file
2002
src/glog/logging.h.in
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2008, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -35,27 +35,24 @@
|
|||||||
#define GLOG_PLATFORM_H
|
#define GLOG_PLATFORM_H
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||||
# define GLOG_OS_WINDOWS
|
#define GLOG_OS_WINDOWS
|
||||||
#elif defined(__CYGWIN__) || defined(__CYGWIN32__)
|
#elif defined(__CYGWIN__) || defined(__CYGWIN32__)
|
||||||
# define GLOG_OS_CYGWIN
|
#define GLOG_OS_CYGWIN
|
||||||
#elif defined(linux) || defined(__linux) || defined(__linux__)
|
#elif defined(linux) || defined(__linux) || defined(__linux__)
|
||||||
# define GLOG_OS_LINUX
|
#ifndef GLOG_OS_LINUX
|
||||||
# if defined(__ANDROID__)
|
#define GLOG_OS_LINUX
|
||||||
# define GLOG_OS_ANDROID
|
#endif
|
||||||
# endif
|
|
||||||
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
|
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
|
||||||
# define GLOG_OS_MACOSX
|
#define GLOG_OS_MACOSX
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
# define GLOG_OS_FREEBSD
|
#define GLOG_OS_FREEBSD
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
# define GLOG_OS_NETBSD
|
#define GLOG_OS_NETBSD
|
||||||
#elif defined(__OpenBSD__)
|
#elif defined(__OpenBSD__)
|
||||||
# define GLOG_OS_OPENBSD
|
#define GLOG_OS_OPENBSD
|
||||||
#elif defined(__EMSCRIPTEN__)
|
|
||||||
# define GLOG_OS_EMSCRIPTEN
|
|
||||||
#else
|
#else
|
||||||
// TODO(hamaji): Add other platforms.
|
// TODO(hamaji): Add other platforms.
|
||||||
#error Platform not supported by glog. Please consider to contribute platform information by submitting a pull request on Github.
|
#error Platform not supported by glog. Please consider to contribute platform information by submitting a pull request on Github.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // GLOG_PLATFORM_H
|
#endif // GLOG_PLATFORM_H
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2006, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -36,19 +36,19 @@
|
|||||||
#ifndef GLOG_RAW_LOGGING_H
|
#ifndef GLOG_RAW_LOGGING_H
|
||||||
#define GLOG_RAW_LOGGING_H
|
#define GLOG_RAW_LOGGING_H
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
#include <ctime>
|
||||||
# include "glog/export.h"
|
|
||||||
|
@ac_google_start_namespace@
|
||||||
|
|
||||||
|
#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"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(GLOG_EXPORT)
|
|
||||||
# error <glog/raw_logging.h> was not included correctly. See the documentation for how to consume the library.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "glog/log_severity.h"
|
|
||||||
#include "glog/vlog_is_on.h"
|
|
||||||
|
|
||||||
namespace google {
|
|
||||||
|
|
||||||
// This is similar to LOG(severity) << format... and VLOG(level) << format..,
|
// This is similar to LOG(severity) << format... and VLOG(level) << format..,
|
||||||
// but
|
// but
|
||||||
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
||||||
@ -63,101 +63,108 @@ namespace google {
|
|||||||
// These will print an almost standard log lines like this to stderr only:
|
// These will print an almost standard log lines like this to stderr only:
|
||||||
// E20200821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
// E20200821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
||||||
// I20200821 211317 file.cc:142] RAW: status is 20
|
// I20200821 211317 file.cc:142] RAW: status is 20
|
||||||
#define RAW_LOG(severity, ...) \
|
#define RAW_LOG(severity, ...) \
|
||||||
do { \
|
do { \
|
||||||
switch (google::GLOG_##severity) { \
|
switch (@ac_google_namespace@::GLOG_ ## severity) { \
|
||||||
case 0: \
|
case 0: \
|
||||||
RAW_LOG_INFO(__VA_ARGS__); \
|
RAW_LOG_INFO(__VA_ARGS__); \
|
||||||
break; \
|
break; \
|
||||||
case 1: \
|
case 1: \
|
||||||
RAW_LOG_WARNING(__VA_ARGS__); \
|
RAW_LOG_WARNING(__VA_ARGS__); \
|
||||||
break; \
|
break; \
|
||||||
case 2: \
|
case 2: \
|
||||||
RAW_LOG_ERROR(__VA_ARGS__); \
|
RAW_LOG_ERROR(__VA_ARGS__); \
|
||||||
break; \
|
break; \
|
||||||
case 3: \
|
case 3: \
|
||||||
RAW_LOG_FATAL(__VA_ARGS__); \
|
RAW_LOG_FATAL(__VA_ARGS__); \
|
||||||
break; \
|
break; \
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// The following STRIP_LOG testing is performed in the header file so that it's
|
// The following STRIP_LOG testing is performed in the header file so that it's
|
||||||
// possible to completely compile out the logging code and the log messages.
|
// possible to completely compile out the logging code and the log messages.
|
||||||
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
||||||
# define RAW_VLOG(verboselevel, ...) \
|
#define RAW_VLOG(verboselevel, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (VLOG_IS_ON(verboselevel)) { \
|
if (VLOG_IS_ON(verboselevel)) { \
|
||||||
RAW_LOG_INFO(__VA_ARGS__); \
|
RAW_LOG_INFO(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
# define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
|
#define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
|
||||||
#endif // STRIP_LOG == 0
|
#endif // STRIP_LOG == 0
|
||||||
|
|
||||||
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
||||||
# define RAW_LOG_INFO(...) \
|
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_INFO, \
|
||||||
google::RawLog__(google::GLOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
|
__FILE__, __LINE__, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
# define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
|
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
||||||
#endif // STRIP_LOG == 0
|
#endif // STRIP_LOG == 0
|
||||||
|
|
||||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 1
|
#if !defined(STRIP_LOG) || STRIP_LOG <= 1
|
||||||
# define RAW_LOG_WARNING(...) \
|
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_WARNING, \
|
||||||
google::RawLog__(google::GLOG_WARNING, __FILE__, __LINE__, __VA_ARGS__)
|
__FILE__, __LINE__, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
# define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
|
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
||||||
#endif // STRIP_LOG <= 1
|
#endif // STRIP_LOG <= 1
|
||||||
|
|
||||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 2
|
#if !defined(STRIP_LOG) || STRIP_LOG <= 2
|
||||||
# define RAW_LOG_ERROR(...) \
|
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_ERROR, \
|
||||||
google::RawLog__(google::GLOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
|
__FILE__, __LINE__, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
# define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
|
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
||||||
#endif // STRIP_LOG <= 2
|
#endif // STRIP_LOG <= 2
|
||||||
|
|
||||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 3
|
#if !defined(STRIP_LOG) || STRIP_LOG <= 3
|
||||||
# define RAW_LOG_FATAL(...) \
|
#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_FATAL, \
|
||||||
google::RawLog__(google::GLOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)
|
__FILE__, __LINE__, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
# define RAW_LOG_FATAL(...) \
|
#define RAW_LOG_FATAL(...) \
|
||||||
do { \
|
do { \
|
||||||
google::RawLogStub__(0, __VA_ARGS__); \
|
@ac_google_namespace@::RawLogStub__(0, __VA_ARGS__); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif // STRIP_LOG <= 3
|
#endif // STRIP_LOG <= 3
|
||||||
|
|
||||||
// Similar to CHECK(condition) << message,
|
// Similar to CHECK(condition) << message,
|
||||||
// but for low-level modules: we use only RAW_LOG that does not allocate memory.
|
// but for low-level modules: we use only RAW_LOG that does not allocate memory.
|
||||||
// We do not want to provide args list here to encourage this usage:
|
// We do not want to provide args list here to encourage this usage:
|
||||||
// if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
// if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
||||||
// so that the args are not computed when not needed.
|
// so that the args are not computed when not needed.
|
||||||
#define RAW_CHECK(condition, message) \
|
#define RAW_CHECK(condition, message) \
|
||||||
do { \
|
do { \
|
||||||
if (!(condition)) { \
|
if (!(condition)) { \
|
||||||
RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Debug versions of RAW_LOG and RAW_CHECK
|
// Debug versions of RAW_LOG and RAW_CHECK
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
||||||
# define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
|
#define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
|
||||||
# define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
|
#define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
|
||||||
|
|
||||||
#else // NDEBUG
|
#else // NDEBUG
|
||||||
|
|
||||||
# define RAW_DLOG(severity, ...) \
|
#define RAW_DLOG(severity, ...) \
|
||||||
while (false) RAW_LOG(severity, __VA_ARGS__)
|
while (false) \
|
||||||
# define RAW_DCHECK(condition, message) \
|
RAW_LOG(severity, __VA_ARGS__)
|
||||||
while (false) RAW_CHECK(condition, message)
|
#define RAW_DCHECK(condition, message) \
|
||||||
|
while (false) \
|
||||||
|
RAW_CHECK(condition, message)
|
||||||
|
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
// Stub log function used to work around for unused variable warnings when
|
// Stub log function used to work around for unused variable warnings when
|
||||||
// building with STRIP_LOG > 0.
|
// building with STRIP_LOG > 0.
|
||||||
static inline void RawLogStub__(int /* ignored */, ...) {}
|
static inline void RawLogStub__(int /* ignored */, ...) {
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to implement RAW_LOG and RAW_VLOG
|
// Helper function to implement RAW_LOG and RAW_VLOG
|
||||||
// Logs format... at "severity" level, reporting it
|
// Logs format... at "severity" level, reporting it
|
||||||
@ -165,12 +172,8 @@ static inline void RawLogStub__(int /* ignored */, ...) {}
|
|||||||
// This does not allocate memory or acquire locks.
|
// This does not allocate memory or acquire locks.
|
||||||
GLOG_EXPORT void RawLog__(LogSeverity severity, const char* file, int line,
|
GLOG_EXPORT void RawLog__(LogSeverity severity, const char* file, int line,
|
||||||
const char* format, ...)
|
const char* format, ...)
|
||||||
#if defined(__has_attribute)
|
@ac_cv___attribute___printf_4_5@;
|
||||||
# if __has_attribute(used)
|
|
||||||
__attribute__((__format__(__printf__, 4, 5)))
|
@ac_google_end_namespace@
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
#endif // GLOG_RAW_LOGGING_H
|
#endif // GLOG_RAW_LOGGING_H
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2023, Google Inc.
|
// Copyright (c) 2003, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -35,95 +35,149 @@
|
|||||||
// vector<int> v1, v2;
|
// vector<int> v1, v2;
|
||||||
// CHECK_EQ(v1, v2);
|
// CHECK_EQ(v1, v2);
|
||||||
//
|
//
|
||||||
|
// If you want to use this header file with hash maps or slist, you
|
||||||
|
// need to define macros before including this file:
|
||||||
|
//
|
||||||
|
// - GLOG_STL_LOGGING_FOR_UNORDERED - <unordered_map> and <unordered_set>
|
||||||
|
// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - <tr1/unordered_(map|set)>
|
||||||
|
// - GLOG_STL_LOGGING_FOR_EXT_HASH - <ext/hash_(map|set)>
|
||||||
|
// - GLOG_STL_LOGGING_FOR_EXT_SLIST - <ext/slist>
|
||||||
|
//
|
||||||
|
|
||||||
#ifndef GLOG_STL_LOGGING_H
|
#ifndef UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
#define GLOG_STL_LOGGING_H
|
#define UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
|
|
||||||
|
#if !@ac_cv_cxx_using_operator@
|
||||||
|
# error We do not support stl_logging for this compiler
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#if defined(GLOG_STL_LOGGING_FOR_UNORDERED) && __cplusplus >= 201103L
|
||||||
|
# include <unordered_map>
|
||||||
|
# include <unordered_set>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED
|
||||||
|
# include <tr1/unordered_map>
|
||||||
|
# include <tr1/unordered_set>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
|
# include <ext/hash_set>
|
||||||
|
# include <ext/hash_map>
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
|
||||||
|
# include <ext/slist>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Forward declare these two, and define them after all the container streams
|
// Forward declare these two, and define them after all the container streams
|
||||||
// operators so that we can recurse from pair -> container -> container -> pair
|
// operators so that we can recurse from pair -> container -> container -> pair
|
||||||
// properly.
|
// properly.
|
||||||
template <class First, class Second>
|
template<class First, class Second>
|
||||||
std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& p);
|
std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& p);
|
||||||
|
|
||||||
namespace google {
|
@ac_google_start_namespace@
|
||||||
|
|
||||||
template <class Iter>
|
template<class Iter>
|
||||||
void PrintSequence(std::ostream& out, Iter begin, Iter end);
|
void PrintSequence(std::ostream& out, Iter begin, Iter end);
|
||||||
|
|
||||||
|
@ac_google_end_namespace@
|
||||||
|
|
||||||
|
#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
|
||||||
|
template<class T1, class T2> \
|
||||||
|
inline std::ostream& operator<<(std::ostream& out, \
|
||||||
|
const Sequence<T1, T2>& seq) { \
|
||||||
|
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||||
|
return out; \
|
||||||
}
|
}
|
||||||
#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
|
|
||||||
template <class T1, class T2> \
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, \
|
|
||||||
const Sequence<T1, T2>& seq) { \
|
|
||||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
|
||||||
return out; \
|
|
||||||
}
|
|
||||||
|
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::vector)
|
OUTPUT_TWO_ARG_CONTAINER(std::vector)
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
|
||||||
|
OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef OUTPUT_TWO_ARG_CONTAINER
|
#undef OUTPUT_TWO_ARG_CONTAINER
|
||||||
|
|
||||||
#define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
|
#define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
|
||||||
template <class T1, class T2, class T3> \
|
template<class T1, class T2, class T3> \
|
||||||
inline std::ostream& operator<<(std::ostream& out, \
|
inline std::ostream& operator<<(std::ostream& out, \
|
||||||
const Sequence<T1, T2, T3>& seq) { \
|
const Sequence<T1, T2, T3>& seq) { \
|
||||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||||
return out; \
|
return out; \
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT_THREE_ARG_CONTAINER(std::set)
|
OUTPUT_THREE_ARG_CONTAINER(std::set)
|
||||||
OUTPUT_THREE_ARG_CONTAINER(std::multiset)
|
OUTPUT_THREE_ARG_CONTAINER(std::multiset)
|
||||||
|
|
||||||
#undef OUTPUT_THREE_ARG_CONTAINER
|
#undef OUTPUT_THREE_ARG_CONTAINER
|
||||||
|
|
||||||
#define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
|
#define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
|
||||||
template <class T1, class T2, class T3, class T4> \
|
template<class T1, class T2, class T3, class T4> \
|
||||||
inline std::ostream& operator<<(std::ostream& out, \
|
inline std::ostream& operator<<(std::ostream& out, \
|
||||||
const Sequence<T1, T2, T3, T4>& seq) { \
|
const Sequence<T1, T2, T3, T4>& seq) { \
|
||||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||||
return out; \
|
return out; \
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::map)
|
OUTPUT_FOUR_ARG_CONTAINER(std::map)
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
|
OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
|
||||||
|
#if defined(GLOG_STL_LOGGING_FOR_UNORDERED) && __cplusplus >= 201103L
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set)
|
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set)
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset)
|
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset)
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED
|
||||||
|
OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_set)
|
||||||
|
OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_multiset)
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
|
OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set)
|
||||||
|
OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef OUTPUT_FOUR_ARG_CONTAINER
|
#undef OUTPUT_FOUR_ARG_CONTAINER
|
||||||
|
|
||||||
#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
|
#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
|
||||||
template <class T1, class T2, class T3, class T4, class T5> \
|
template<class T1, class T2, class T3, class T4, class T5> \
|
||||||
inline std::ostream& operator<<(std::ostream& out, \
|
inline std::ostream& operator<<(std::ostream& out, \
|
||||||
const Sequence<T1, T2, T3, T4, T5>& seq) { \
|
const Sequence<T1, T2, T3, T4, T5>& seq) { \
|
||||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||||
return out; \
|
return out; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GLOG_STL_LOGGING_FOR_UNORDERED) && __cplusplus >= 201103L
|
||||||
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map)
|
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map)
|
||||||
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap)
|
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap)
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED
|
||||||
|
OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_map)
|
||||||
|
OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_multimap)
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
|
OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map)
|
||||||
|
OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef OUTPUT_FIVE_ARG_CONTAINER
|
#undef OUTPUT_FIVE_ARG_CONTAINER
|
||||||
|
|
||||||
template <class First, class Second>
|
template<class First, class Second>
|
||||||
inline std::ostream& operator<<(std::ostream& out,
|
inline std::ostream& operator<<(std::ostream& out,
|
||||||
const std::pair<First, Second>& p) {
|
const std::pair<First, Second>& p) {
|
||||||
out << '(' << p.first << ", " << p.second << ')';
|
out << '(' << p.first << ", " << p.second << ')';
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace google {
|
@ac_google_start_namespace@
|
||||||
|
|
||||||
template <class Iter>
|
template<class Iter>
|
||||||
inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
|
inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
|
||||||
// Output at most 100 elements -- appropriate if used for logging.
|
// Output at most 100 elements -- appropriate if used for logging.
|
||||||
for (int i = 0; begin != end && i < 100; ++i, ++begin) {
|
for (int i = 0; begin != end && i < 100; ++i, ++begin) {
|
||||||
@ -135,7 +189,7 @@ inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace google
|
@ac_google_end_namespace@
|
||||||
|
|
||||||
// Note that this is technically undefined behavior! We are adding things into
|
// Note that this is technically undefined behavior! We are adding things into
|
||||||
// the std namespace for a reason though -- we are providing new operations on
|
// the std namespace for a reason though -- we are providing new operations on
|
||||||
@ -161,8 +215,6 @@ inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
|
|||||||
// move all of the *definitions* into namespace std, bet we need to ensure no
|
// move all of the *definitions* into namespace std, bet we need to ensure no
|
||||||
// one references them first. This lets us take that step. We cannot define them
|
// one references them first. This lets us take that step. We cannot define them
|
||||||
// in both because that would create ambiguous overloads when both are found.
|
// in both because that would create ambiguous overloads when both are found.
|
||||||
namespace std {
|
namespace std { using ::operator<<; }
|
||||||
using ::operator<<;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // GLOG_STL_LOGGING_H
|
#endif // UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
@ -1,81 +0,0 @@
|
|||||||
|
|
||||||
// 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 <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
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
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 1999, 2007, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -58,21 +58,10 @@
|
|||||||
// CAVEAT: --vmodule functionality is not available in non gcc compilers.
|
// CAVEAT: --vmodule functionality is not available in non gcc compilers.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef GLOG_VLOG_IS_ON_H
|
#ifndef BASE_VLOG_IS_ON_H_
|
||||||
#define GLOG_VLOG_IS_ON_H
|
#define BASE_VLOG_IS_ON_H_
|
||||||
|
|
||||||
#include <cstddef>
|
#include <glog/log_severity.h>
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
|
||||||
# include "glog/export.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(GLOG_EXPORT)
|
|
||||||
# error <glog/vlog_is_on.h> was not included correctly. See the documentation for how to consume the library.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "glog/flags.h"
|
|
||||||
#include "glog/types.h"
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
// We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
|
// We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
|
||||||
@ -81,25 +70,19 @@
|
|||||||
// it's either FLAGS_v or an appropriate internal variable
|
// it's either FLAGS_v or an appropriate internal variable
|
||||||
// matching the current source file that represents results of
|
// matching the current source file that represents results of
|
||||||
// parsing of --vmodule flag and/or SetVLOGLevel calls.
|
// parsing of --vmodule flag and/or SetVLOGLevel calls.
|
||||||
# define VLOG_IS_ON(verboselevel) \
|
#define VLOG_IS_ON(verboselevel) \
|
||||||
__extension__({ \
|
__extension__ \
|
||||||
static google::SiteFlag vlocal__ = {nullptr, nullptr, 0, nullptr}; \
|
({ static @ac_google_namespace@::SiteFlag vlocal__ = {NULL, NULL, 0, NULL}; \
|
||||||
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
|
@ac_google_namespace@::int32 verbose_level__ = (verboselevel); \
|
||||||
__FILE__, __LINE__, &vlocal__, sizeof(google::SiteFlag), "")); \
|
(vlocal__.level == NULL ? @ac_google_namespace@::InitVLOG3__(&vlocal__, &FLAGS_v, \
|
||||||
google::int32 verbose_level__ = (verboselevel); \
|
__FILE__, verbose_level__) : *vlocal__.level >= verbose_level__); \
|
||||||
(vlocal__.level == nullptr \
|
})
|
||||||
? google::InitVLOG3__(&vlocal__, &FLAGS_v, __FILE__, \
|
|
||||||
verbose_level__) \
|
|
||||||
: *vlocal__.level >= verbose_level__); \
|
|
||||||
})
|
|
||||||
#else
|
#else
|
||||||
// GNU extensions not available, so we do not support --vmodule.
|
// GNU extensions not available, so we do not support --vmodule.
|
||||||
// Dynamic value of FLAGS_v always controls the logging level.
|
// Dynamic value of FLAGS_v always controls the logging level.
|
||||||
# define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
|
#define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace google {
|
|
||||||
|
|
||||||
// Set VLOG(_IS_ON) level for module_pattern to log_level.
|
// Set VLOG(_IS_ON) level for module_pattern to log_level.
|
||||||
// This lets us dynamically control what is normally set by the --vmodule flag.
|
// This lets us dynamically control what is normally set by the --vmodule flag.
|
||||||
// Returns the level that previously applied to module_pattern.
|
// Returns the level that previously applied to module_pattern.
|
||||||
@ -113,13 +96,13 @@ extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level);
|
|||||||
// Various declarations needed for VLOG_IS_ON above: =========================
|
// Various declarations needed for VLOG_IS_ON above: =========================
|
||||||
|
|
||||||
struct SiteFlag {
|
struct SiteFlag {
|
||||||
int32* level;
|
@ac_google_namespace@::int32* level;
|
||||||
const char* base_name;
|
const char* base_name;
|
||||||
std::size_t base_len;
|
size_t base_len;
|
||||||
SiteFlag* next;
|
SiteFlag* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper routine which determines the logging info for a particular VLOG site.
|
// Helper routine which determines the logging info for a particalur VLOG site.
|
||||||
// site_flag is the address of the site-local pointer to the controlling
|
// site_flag is the address of the site-local pointer to the controlling
|
||||||
// verbosity level
|
// verbosity level
|
||||||
// site_default is the default to use for *site_flag
|
// site_default is the default to use for *site_flag
|
||||||
@ -127,10 +110,9 @@ struct SiteFlag {
|
|||||||
// verbose_level is the argument to VLOG_IS_ON
|
// verbose_level is the argument to VLOG_IS_ON
|
||||||
// We will return the return value for VLOG_IS_ON
|
// We will return the return value for VLOG_IS_ON
|
||||||
// and if possible set *site_flag appropriately.
|
// and if possible set *site_flag appropriately.
|
||||||
extern GLOG_EXPORT bool InitVLOG3__(SiteFlag* site_flag,
|
extern GLOG_EXPORT bool InitVLOG3__(
|
||||||
int32* site_default,
|
@ac_google_namespace@::SiteFlag* site_flag,
|
||||||
const char* fname,
|
@ac_google_namespace@::int32* site_default, const char* fname,
|
||||||
int32 verbose_level);
|
@ac_google_namespace@::int32 verbose_level);
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
#endif // GLOG_VLOG_IS_ON_H
|
#endif // BASE_VLOG_IS_ON_H_
|
||||||
482
src/googletest.h
482
src/googletest.h
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2009, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -31,13 +31,11 @@
|
|||||||
// (based on googletest: http://code.google.com/p/googletest/)
|
// (based on googletest: http://code.google.com/p/googletest/)
|
||||||
|
|
||||||
#ifdef GOOGLETEST_H__
|
#ifdef GOOGLETEST_H__
|
||||||
# error You must not include this file twice.
|
#error You must not include this file twice.
|
||||||
#endif
|
#endif
|
||||||
#define GOOGLETEST_H__
|
#define GOOGLETEST_H__
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include "utilities.h"
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <csetjmp>
|
#include <csetjmp>
|
||||||
@ -45,46 +43,41 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <new>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "config.h"
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GLOG_USE_WINDOWS_PORT)
|
|
||||||
# include "port.h"
|
|
||||||
#endif // defined(GLOG_USE_WINDOWS_PORT)
|
|
||||||
#include "base/commandlineflags.h"
|
#include "base/commandlineflags.h"
|
||||||
#include "utilities.h"
|
|
||||||
|
|
||||||
#if __cplusplus < 201103L && !defined(_MSC_VER)
|
#if __cplusplus < 201103L && !defined(_MSC_VER)
|
||||||
# define GOOGLE_GLOG_THROW_BAD_ALLOC throw(std::bad_alloc)
|
#define GOOGLE_GLOG_THROW_BAD_ALLOC throw (std::bad_alloc)
|
||||||
#else
|
#else
|
||||||
# define GOOGLE_GLOG_THROW_BAD_ALLOC
|
#define GOOGLE_GLOG_THROW_BAD_ALLOC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
extern void (*g_logging_fail_func)();
|
|
||||||
extern void GetExistingTempDirectories(std::vector<std::string>& list);
|
extern GLOG_EXPORT void (*g_logging_fail_func)();
|
||||||
extern int posix_strerror_r(int err, char* buf, size_t len);
|
|
||||||
extern std::string StrError(int err);
|
_END_GOOGLE_NAMESPACE_
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
#undef GLOG_EXPORT
|
#undef GLOG_EXPORT
|
||||||
#define GLOG_EXPORT
|
#define GLOG_EXPORT
|
||||||
|
|
||||||
static inline string GetTempDir() {
|
static inline string GetTempDir() {
|
||||||
vector<string> temp_directories_list;
|
vector<string> temp_directories_list;
|
||||||
google::GetExistingTempDirectories(temp_directories_list);
|
google::GetExistingTempDirectories(&temp_directories_list);
|
||||||
|
|
||||||
if (temp_directories_list.empty()) {
|
if (temp_directories_list.empty()) {
|
||||||
fprintf(stderr, "No temporary directory found\n");
|
fprintf(stderr, "No temporary directory found\n");
|
||||||
@ -100,7 +93,7 @@ static inline string GetTempDir() {
|
|||||||
// (e.g., glog/vsproject/logging_unittest).
|
// (e.g., glog/vsproject/logging_unittest).
|
||||||
static const char TEST_SRC_DIR[] = "../..";
|
static const char TEST_SRC_DIR[] = "../..";
|
||||||
#elif !defined(TEST_SRC_DIR)
|
#elif !defined(TEST_SRC_DIR)
|
||||||
# warning TEST_SRC_DIR should be defined in config.h
|
# warning TEST_SRC_DIR should be defined in config.h
|
||||||
static const char TEST_SRC_DIR[] = ".";
|
static const char TEST_SRC_DIR[] = ".";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -117,14 +110,14 @@ DEFINE_int32(benchmark_iters, 100000, "Number of iterations per benchmark");
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIB_GTEST
|
#ifdef HAVE_LIB_GTEST
|
||||||
# include <gtest/gtest.h>
|
# include <gtest/gtest.h>
|
||||||
// Use our ASSERT_DEATH implementation.
|
// Use our ASSERT_DEATH implementation.
|
||||||
# undef ASSERT_DEATH
|
# undef ASSERT_DEATH
|
||||||
# undef ASSERT_DEBUG_DEATH
|
# undef ASSERT_DEBUG_DEATH
|
||||||
using testing::InitGoogleTest;
|
using testing::InitGoogleTest;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
void InitGoogleTest(int*, char**);
|
void InitGoogleTest(int*, char**);
|
||||||
|
|
||||||
@ -132,94 +125,81 @@ void InitGoogleTest(int*, char**) {}
|
|||||||
|
|
||||||
// The following is some bare-bones testing infrastructure
|
// The following is some bare-bones testing infrastructure
|
||||||
|
|
||||||
# define EXPECT_NEAR(val1, val2, abs_error) \
|
#define EXPECT_NEAR(val1, val2, abs_error) \
|
||||||
do { \
|
do { \
|
||||||
if (abs(val1 - val2) > abs_error) { \
|
if (abs(val1 - val2) > abs_error) { \
|
||||||
fprintf(stderr, "Check failed: %s within %s of %s\n", #val1, \
|
fprintf(stderr, "Check failed: %s within %s of %s\n", #val1, #abs_error, \
|
||||||
#abs_error, #val2); \
|
#val2); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_TRUE(cond) \
|
#define EXPECT_TRUE(cond) \
|
||||||
do { \
|
do { \
|
||||||
if (!(cond)) { \
|
if (!(cond)) { \
|
||||||
fprintf(stderr, "Check failed: %s\n", #cond); \
|
fprintf(stderr, "Check failed: %s\n", #cond); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_FALSE(cond) EXPECT_TRUE(!(cond))
|
#define EXPECT_FALSE(cond) EXPECT_TRUE(!(cond))
|
||||||
|
|
||||||
# define EXPECT_OP(op, val1, val2) \
|
#define EXPECT_OP(op, val1, val2) \
|
||||||
do { \
|
do { \
|
||||||
if (!((val1)op(val2))) { \
|
if (!((val1) op (val2))) { \
|
||||||
fprintf(stderr, "Check failed: %s %s %s\n", #val1, #op, #val2); \
|
fprintf(stderr, "Check failed: %s %s %s\n", #val1, #op, #val2); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_EQ(val1, val2) EXPECT_OP(==, val1, val2)
|
#define EXPECT_EQ(val1, val2) EXPECT_OP(==, val1, val2)
|
||||||
# define EXPECT_NE(val1, val2) EXPECT_OP(!=, val1, val2)
|
#define EXPECT_NE(val1, val2) EXPECT_OP(!=, val1, val2)
|
||||||
# define EXPECT_GT(val1, val2) EXPECT_OP(>, val1, val2)
|
#define EXPECT_GT(val1, val2) EXPECT_OP(>, val1, val2)
|
||||||
# define EXPECT_LT(val1, val2) EXPECT_OP(<, val1, val2)
|
#define EXPECT_LT(val1, val2) EXPECT_OP(<, val1, val2)
|
||||||
|
|
||||||
# define EXPECT_NAN(arg) \
|
#define EXPECT_NAN(arg) \
|
||||||
do { \
|
do { \
|
||||||
if (!isnan(arg)) { \
|
if (!isnan(arg)) { \
|
||||||
fprintf(stderr, "Check failed: isnan(%s)\n", #arg); \
|
fprintf(stderr, "Check failed: isnan(%s)\n", #arg); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_INF(arg) \
|
#define EXPECT_INF(arg) \
|
||||||
do { \
|
do { \
|
||||||
if (!isinf(arg)) { \
|
if (!isinf(arg)) { \
|
||||||
fprintf(stderr, "Check failed: isinf(%s)\n", #arg); \
|
fprintf(stderr, "Check failed: isinf(%s)\n", #arg); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_DOUBLE_EQ(val1, val2) \
|
#define EXPECT_DOUBLE_EQ(val1, val2) \
|
||||||
do { \
|
do { \
|
||||||
if (((val1) < (val2)-0.001 || (val1) > (val2) + 0.001)) { \
|
if (((val1) < (val2) - 0.001 || (val1) > (val2) + 0.001)) { \
|
||||||
fprintf(stderr, "Check failed: %s == %s\n", #val1, #val2); \
|
fprintf(stderr, "Check failed: %s == %s\n", #val1, #val2); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_STREQ(val1, val2) \
|
#define EXPECT_STREQ(val1, val2) \
|
||||||
do { \
|
do { \
|
||||||
if (strcmp((val1), (val2)) != 0) { \
|
if (strcmp((val1), (val2)) != 0) { \
|
||||||
fprintf(stderr, "Check failed: streq(%s, %s)\n", #val1, #val2); \
|
fprintf(stderr, "Check failed: streq(%s, %s)\n", #val1, #val2); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define EXPECT_THROW(statement, exception) \
|
|
||||||
do { \
|
|
||||||
try { \
|
|
||||||
statement; \
|
|
||||||
} catch (const exception&) { \
|
|
||||||
printf("ok\n"); \
|
|
||||||
} catch (...) { \
|
|
||||||
fprintf(stderr, "%s\n", "Unexpected exception thrown"); \
|
|
||||||
exit(EXIT_FAILURE); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
vector<void (*)()> g_testlist; // the tests to run
|
vector<void (*)()> g_testlist; // the tests to run
|
||||||
# define TEST(a, b) \
|
|
||||||
struct Test_##a##_##b { \
|
#define TEST(a, b) \
|
||||||
Test_##a##_##b() { g_testlist.push_back(&Run); } \
|
struct Test_##a##_##b { \
|
||||||
static void Run() { \
|
Test_##a##_##b() { g_testlist.push_back(&Run); } \
|
||||||
FlagSaver fs; \
|
static void Run() { FlagSaver fs; RunTest(); } \
|
||||||
RunTest(); \
|
static void RunTest(); \
|
||||||
} \
|
}; \
|
||||||
static void RunTest(); \
|
static Test_##a##_##b g_test_##a##_##b; \
|
||||||
}; \
|
void Test_##a##_##b::RunTest()
|
||||||
static Test_##a##_##b g_test_##a##_##b; \
|
|
||||||
void Test_##a##_##b::RunTest()
|
|
||||||
|
|
||||||
static inline int RUN_ALL_TESTS() {
|
static inline int RUN_ALL_TESTS() {
|
||||||
vector<void (*)()>::const_iterator it;
|
vector<void (*)()>::const_iterator it;
|
||||||
@ -231,11 +211,11 @@ static inline int RUN_ALL_TESTS() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace google
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
#endif // ! HAVE_LIB_GTEST
|
#endif // ! HAVE_LIB_GTEST
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
static bool g_called_abort;
|
static bool g_called_abort;
|
||||||
static jmp_buf g_jmp_buf;
|
static jmp_buf g_jmp_buf;
|
||||||
@ -246,33 +226,33 @@ static inline void CalledAbort() {
|
|||||||
|
|
||||||
#ifdef GLOG_OS_WINDOWS
|
#ifdef GLOG_OS_WINDOWS
|
||||||
// TODO(hamaji): Death test somehow doesn't work in Windows.
|
// TODO(hamaji): Death test somehow doesn't work in Windows.
|
||||||
# define ASSERT_DEATH(fn, msg)
|
#define ASSERT_DEATH(fn, msg)
|
||||||
#else
|
#else
|
||||||
# define ASSERT_DEATH(fn, msg) \
|
#define ASSERT_DEATH(fn, msg) \
|
||||||
do { \
|
do { \
|
||||||
g_called_abort = false; \
|
g_called_abort = false; \
|
||||||
/* in logging.cc */ \
|
/* in logging.cc */ \
|
||||||
void (*original_logging_fail_func)() = g_logging_fail_func; \
|
void (*original_logging_fail_func)() = g_logging_fail_func; \
|
||||||
g_logging_fail_func = &CalledAbort; \
|
g_logging_fail_func = &CalledAbort; \
|
||||||
if (!setjmp(g_jmp_buf)) fn; \
|
if (!setjmp(g_jmp_buf)) fn; \
|
||||||
/* set back to their default */ \
|
/* set back to their default */ \
|
||||||
g_logging_fail_func = original_logging_fail_func; \
|
g_logging_fail_func = original_logging_fail_func; \
|
||||||
if (!g_called_abort) { \
|
if (!g_called_abort) { \
|
||||||
fprintf(stderr, "Function didn't die (%s): %s\n", msg, #fn); \
|
fprintf(stderr, "Function didn't die (%s): %s\n", msg, #fn); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
# define ASSERT_DEBUG_DEATH(fn, msg)
|
#define ASSERT_DEBUG_DEATH(fn, msg)
|
||||||
#else
|
#else
|
||||||
# define ASSERT_DEBUG_DEATH(fn, msg) ASSERT_DEATH(fn, msg)
|
#define ASSERT_DEBUG_DEATH(fn, msg) ASSERT_DEATH(fn, msg)
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
// Benchmark tools.
|
// Benchmark tools.
|
||||||
|
|
||||||
#define BENCHMARK(n) static BenchmarkRegisterer __benchmark_##n(#n, &n);
|
#define BENCHMARK(n) static BenchmarkRegisterer __benchmark_ ## n (#n, &n);
|
||||||
|
|
||||||
map<string, void (*)(int)> g_benchlist; // the benchmarks to run
|
map<string, void (*)(int)> g_benchlist; // the benchmarks to run
|
||||||
|
|
||||||
@ -290,19 +270,21 @@ static inline void RunSpecifiedBenchmarks() {
|
|||||||
|
|
||||||
int iter_cnt = FLAGS_benchmark_iters;
|
int iter_cnt = FLAGS_benchmark_iters;
|
||||||
puts("Benchmark\tTime(ns)\tIterations");
|
puts("Benchmark\tTime(ns)\tIterations");
|
||||||
for (auto& iter : g_benchlist) {
|
for (map<string, void (*)(int)>::const_iterator iter = g_benchlist.begin();
|
||||||
|
iter != g_benchlist.end();
|
||||||
|
++iter) {
|
||||||
clock_t start = clock();
|
clock_t start = clock();
|
||||||
iter.second(iter_cnt);
|
iter->second(iter_cnt);
|
||||||
double elapsed_ns = (static_cast<double>(clock()) - start) /
|
double elapsed_ns = (static_cast<double>(clock()) - start) /
|
||||||
CLOCKS_PER_SEC * 1000 * 1000 * 1000;
|
CLOCKS_PER_SEC * 1000 * 1000 * 1000;
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
#if defined(__GNUC__) && !defined(__clang__)
|
||||||
# pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
# pragma GCC diagnostic ignored "-Wformat="
|
#pragma GCC diagnostic ignored "-Wformat="
|
||||||
#endif
|
#endif
|
||||||
printf("%s\t%8.2lf\t%10d\n", iter.first.c_str(), elapsed_ns / iter_cnt,
|
printf("%s\t%8.2lf\t%10d\n",
|
||||||
iter_cnt);
|
iter->first.c_str(), elapsed_ns / iter_cnt, iter_cnt);
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
#if defined(__GNUC__) && !defined(__clang__)
|
||||||
# pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
puts("");
|
puts("");
|
||||||
@ -314,70 +296,78 @@ static inline void RunSpecifiedBenchmarks() {
|
|||||||
|
|
||||||
class CapturedStream {
|
class CapturedStream {
|
||||||
public:
|
public:
|
||||||
CapturedStream(int fd, string filename)
|
CapturedStream(int fd, const string & filename) :
|
||||||
: fd_(fd), filename_(std::move(filename)) {
|
fd_(fd),
|
||||||
|
uncaptured_fd_(-1),
|
||||||
|
filename_(filename) {
|
||||||
Capture();
|
Capture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~CapturedStream() {
|
||||||
|
if (uncaptured_fd_ != -1) {
|
||||||
|
CHECK(close(uncaptured_fd_) != -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start redirecting output to a file
|
// Start redirecting output to a file
|
||||||
void Capture() {
|
void Capture() {
|
||||||
// Keep original stream for later
|
// Keep original stream for later
|
||||||
CHECK(!uncaptured_fd_) << ", Stream " << fd_ << " already captured!";
|
CHECK(uncaptured_fd_ == -1) << ", Stream " << fd_ << " already captured!";
|
||||||
uncaptured_fd_.reset(dup(fd_));
|
uncaptured_fd_ = dup(fd_);
|
||||||
CHECK(uncaptured_fd_);
|
CHECK(uncaptured_fd_ != -1);
|
||||||
|
|
||||||
// Open file to save stream to
|
// Open file to save stream to
|
||||||
FileDescriptor cap_fd{open(filename_.c_str(), O_CREAT | O_TRUNC | O_WRONLY,
|
int cap_fd = open(filename_.c_str(),
|
||||||
S_IRUSR | S_IWUSR)};
|
O_CREAT | O_TRUNC | O_WRONLY,
|
||||||
CHECK(cap_fd);
|
S_IRUSR | S_IWUSR);
|
||||||
|
CHECK(cap_fd != -1);
|
||||||
|
|
||||||
// Send stdout/stderr to this file
|
// Send stdout/stderr to this file
|
||||||
fflush(nullptr);
|
fflush(NULL);
|
||||||
CHECK(dup2(cap_fd.get(), fd_) != -1);
|
CHECK(dup2(cap_fd, fd_) != -1);
|
||||||
CHECK(cap_fd.close() != -1);
|
CHECK(close(cap_fd) != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove output redirection
|
// Remove output redirection
|
||||||
void StopCapture() {
|
void StopCapture() {
|
||||||
// Restore original stream
|
// Restore original stream
|
||||||
if (uncaptured_fd_) {
|
if (uncaptured_fd_ != -1) {
|
||||||
fflush(nullptr);
|
fflush(NULL);
|
||||||
CHECK(dup2(uncaptured_fd_.get(), fd_) != -1);
|
CHECK(dup2(uncaptured_fd_, fd_) != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& filename() const { return filename_; }
|
const string & filename() const { return filename_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fd_; // file descriptor being captured
|
int fd_; // file descriptor being captured
|
||||||
FileDescriptor
|
int uncaptured_fd_; // where the stream was originally being sent to
|
||||||
uncaptured_fd_; // where the stream was originally being sent to
|
|
||||||
string filename_; // file where stream is being saved
|
string filename_; // file where stream is being saved
|
||||||
};
|
};
|
||||||
static std::map<int, std::unique_ptr<CapturedStream>> s_captured_streams;
|
static CapturedStream * s_captured_streams[STDERR_FILENO+1];
|
||||||
// Redirect a file descriptor to a file.
|
// Redirect a file descriptor to a file.
|
||||||
// fd - Should be stdout or stderr
|
// fd - Should be STDOUT_FILENO or STDERR_FILENO
|
||||||
// filename - File where output should be stored
|
// filename - File where output should be stored
|
||||||
static inline void CaptureTestOutput(int fd, const string& filename) {
|
static inline void CaptureTestOutput(int fd, const string & filename) {
|
||||||
CHECK((fd == fileno(stdout)) || (fd == fileno(stderr)));
|
CHECK((fd == STDOUT_FILENO) || (fd == STDERR_FILENO));
|
||||||
CHECK(s_captured_streams.find(fd) == s_captured_streams.end());
|
CHECK(s_captured_streams[fd] == NULL);
|
||||||
s_captured_streams[fd] = std::make_unique<CapturedStream>(fd, filename);
|
s_captured_streams[fd] = new CapturedStream(fd, filename);
|
||||||
}
|
}
|
||||||
static inline void CaptureTestStdout() {
|
static inline void CaptureTestStdout() {
|
||||||
CaptureTestOutput(fileno(stdout), FLAGS_test_tmpdir + "/captured.out");
|
CaptureTestOutput(STDOUT_FILENO, FLAGS_test_tmpdir + "/captured.out");
|
||||||
}
|
}
|
||||||
static inline void CaptureTestStderr() {
|
static inline void CaptureTestStderr() {
|
||||||
CaptureTestOutput(fileno(stderr), FLAGS_test_tmpdir + "/captured.err");
|
CaptureTestOutput(STDERR_FILENO, FLAGS_test_tmpdir + "/captured.err");
|
||||||
}
|
}
|
||||||
// Return the size (in bytes) of a file
|
// Return the size (in bytes) of a file
|
||||||
static inline size_t GetFileSize(FILE* file) {
|
static inline size_t GetFileSize(FILE * file) {
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
return static_cast<size_t>(ftell(file));
|
return static_cast<size_t>(ftell(file));
|
||||||
}
|
}
|
||||||
// Read the entire content of a file as a string
|
// Read the entire content of a file as a string
|
||||||
static inline string ReadEntireFile(FILE* file) {
|
static inline string ReadEntireFile(FILE * file) {
|
||||||
const size_t file_size = GetFileSize(file);
|
const size_t file_size = GetFileSize(file);
|
||||||
std::vector<char> content(file_size);
|
char * const buffer = new char[file_size];
|
||||||
|
|
||||||
size_t bytes_last_read = 0; // # of bytes read in the last fread()
|
size_t bytes_last_read = 0; // # of bytes read in the last fread()
|
||||||
size_t bytes_read = 0; // # of bytes read so far
|
size_t bytes_read = 0; // # of bytes read so far
|
||||||
@ -387,33 +377,39 @@ static inline string ReadEntireFile(FILE* file) {
|
|||||||
// Keep reading the file until we cannot read further or the
|
// Keep reading the file until we cannot read further or the
|
||||||
// pre-determined file size is reached.
|
// pre-determined file size is reached.
|
||||||
do {
|
do {
|
||||||
bytes_last_read =
|
bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
|
||||||
fread(content.data() + bytes_read, 1, file_size - bytes_read, file);
|
|
||||||
bytes_read += bytes_last_read;
|
bytes_read += bytes_last_read;
|
||||||
} while (bytes_last_read > 0 && bytes_read < file_size);
|
} while (bytes_last_read > 0 && bytes_read < file_size);
|
||||||
|
|
||||||
return std::string(content.data(), bytes_read);
|
const string content = string(buffer, buffer+bytes_read);
|
||||||
|
delete[] buffer;
|
||||||
|
|
||||||
|
return content;
|
||||||
}
|
}
|
||||||
// Get the captured stdout or stderr as a string
|
// Get the captured stdout (when fd is STDOUT_FILENO) or stderr (when
|
||||||
|
// fd is STDERR_FILENO) as a string
|
||||||
static inline string GetCapturedTestOutput(int fd) {
|
static inline string GetCapturedTestOutput(int fd) {
|
||||||
CHECK((fd == fileno(stdout)) || (fd == fileno(stderr)));
|
CHECK(fd == STDOUT_FILENO || fd == STDERR_FILENO);
|
||||||
std::unique_ptr<CapturedStream> cap = std::move(s_captured_streams.at(fd));
|
CapturedStream * const cap = s_captured_streams[fd];
|
||||||
s_captured_streams.erase(fd);
|
CHECK(cap)
|
||||||
CHECK(cap) << ": did you forget CaptureTestStdout() or CaptureTestStderr()?";
|
<< ": did you forget CaptureTestStdout() or CaptureTestStderr()?";
|
||||||
|
|
||||||
// Make sure everything is flushed.
|
// Make sure everything is flushed.
|
||||||
cap->StopCapture();
|
cap->StopCapture();
|
||||||
|
|
||||||
// Read the captured file.
|
// Read the captured file.
|
||||||
std::unique_ptr<FILE> file{fopen(cap->filename().c_str(), "r")};
|
FILE * const file = fopen(cap->filename().c_str(), "r");
|
||||||
const string content = ReadEntireFile(file.get());
|
const string content = ReadEntireFile(file);
|
||||||
file.reset();
|
fclose(file);
|
||||||
|
|
||||||
|
delete cap;
|
||||||
|
s_captured_streams[fd] = NULL;
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
// Get the captured stderr of a test as a string.
|
// Get the captured stderr of a test as a string.
|
||||||
static inline string GetCapturedTestStderr() {
|
static inline string GetCapturedTestStderr() {
|
||||||
return GetCapturedTestOutput(fileno(stderr));
|
return GetCapturedTestOutput(STDERR_FILENO);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::size_t kLoggingPrefixLength = 9;
|
static const std::size_t kLoggingPrefixLength = 9;
|
||||||
@ -425,7 +421,7 @@ static inline bool IsLoggingPrefix(const string& s) {
|
|||||||
}
|
}
|
||||||
if (!strchr("IWEF", s[0])) return false;
|
if (!strchr("IWEF", s[0])) return false;
|
||||||
for (size_t i = 1; i <= 8; ++i) {
|
for (size_t i = 1; i <= 8; ++i) {
|
||||||
if (!isdigit(s[i]) && s[i] != "YEARDATE"[i - 1]) return false;
|
if (!isdigit(s[i]) && s[i] != "YEARDATE"[i-1]) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -465,15 +461,16 @@ static inline string MungeLine(const string& line) {
|
|||||||
}
|
}
|
||||||
size_t index = thread_lineinfo.find(':');
|
size_t index = thread_lineinfo.find(':');
|
||||||
CHECK_NE(string::npos, index);
|
CHECK_NE(string::npos, index);
|
||||||
thread_lineinfo = thread_lineinfo.substr(0, index + 1) + "LINE]";
|
thread_lineinfo = thread_lineinfo.substr(0, index+1) + "LINE]";
|
||||||
string rest;
|
string rest;
|
||||||
std::getline(iss, rest);
|
std::getline(iss, rest);
|
||||||
return (before + logcode_date[0] + "YEARDATE TIME__ " + thread_lineinfo +
|
return (before + logcode_date[0] + "YEARDATE TIME__ " + thread_lineinfo +
|
||||||
MungeLine(rest));
|
MungeLine(rest));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void StringReplace(string* str, const string& oldsub,
|
static inline void StringReplace(string* str,
|
||||||
const string& newsub) {
|
const string& oldsub,
|
||||||
|
const string& newsub) {
|
||||||
size_t pos = str->find(oldsub);
|
size_t pos = str->find(oldsub);
|
||||||
if (pos != string::npos) {
|
if (pos != string::npos) {
|
||||||
str->replace(pos, oldsub.size(), newsub);
|
str->replace(pos, oldsub.size(), newsub);
|
||||||
@ -481,18 +478,17 @@ static inline void StringReplace(string* str, const string& oldsub,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline string Munge(const string& filename) {
|
static inline string Munge(const string& filename) {
|
||||||
std::unique_ptr<FILE> fp{fopen(filename.c_str(), "rb")};
|
FILE* fp = fopen(filename.c_str(), "rb");
|
||||||
CHECK(fp != nullptr) << filename << ": couldn't open";
|
CHECK(fp != NULL) << filename << ": couldn't open";
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
string result;
|
string result;
|
||||||
while (fgets(buf, 4095, fp.get())) {
|
while (fgets(buf, 4095, fp)) {
|
||||||
string line = MungeLine(buf);
|
string line = MungeLine(buf);
|
||||||
const size_t str_size = 256;
|
const size_t str_size = 256;
|
||||||
char null_str[str_size];
|
char null_str[str_size];
|
||||||
char ptr_str[str_size];
|
char ptr_str[str_size];
|
||||||
std::snprintf(null_str, str_size, "%p", static_cast<void*>(nullptr));
|
snprintf(null_str, str_size, "%p", static_cast<void*>(NULL));
|
||||||
std::snprintf(ptr_str, str_size, "%p",
|
snprintf(ptr_str, str_size, "%p", reinterpret_cast<void*>(PTR_TEST_VALUE));
|
||||||
reinterpret_cast<void*>(PTR_TEST_VALUE));
|
|
||||||
|
|
||||||
StringReplace(&line, "__NULLP__", null_str);
|
StringReplace(&line, "__NULLP__", null_str);
|
||||||
StringReplace(&line, "__PTRTEST__", ptr_str);
|
StringReplace(&line, "__PTRTEST__", ptr_str);
|
||||||
@ -504,19 +500,19 @@ static inline string Munge(const string& filename) {
|
|||||||
StringReplace(&line, "__ENOEXEC__", StrError(ENOEXEC));
|
StringReplace(&line, "__ENOEXEC__", StrError(ENOEXEC));
|
||||||
result += line + "\n";
|
result += line + "\n";
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void WriteToFile(const string& body, const string& file) {
|
static inline void WriteToFile(const string& body, const string& file) {
|
||||||
std::unique_ptr<FILE> fp{fopen(file.c_str(), "wb")};
|
FILE* fp = fopen(file.c_str(), "wb");
|
||||||
fwrite(body.data(), 1, body.size(), fp.get());
|
fwrite(body.data(), 1, body.size(), fp);
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool MungeAndDiffTest(const string& golden_filename,
|
static inline bool MungeAndDiffTest(const string& golden_filename,
|
||||||
CapturedStream* cap) {
|
CapturedStream* cap) {
|
||||||
auto pos = s_captured_streams.find(fileno(stdout));
|
if (cap == s_captured_streams[STDOUT_FILENO]) {
|
||||||
|
|
||||||
if (pos != s_captured_streams.end() && cap == pos->second.get()) {
|
|
||||||
CHECK(cap) << ": did you forget CaptureTestStdout()?";
|
CHECK(cap) << ": did you forget CaptureTestStdout()?";
|
||||||
} else {
|
} else {
|
||||||
CHECK(cap) << ": did you forget CaptureTestStderr()?";
|
CHECK(cap) << ": did you forget CaptureTestStderr()?";
|
||||||
@ -551,68 +547,126 @@ static inline bool MungeAndDiffTest(const string& golden_filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline bool MungeAndDiffTestStderr(const string& golden_filename) {
|
static inline bool MungeAndDiffTestStderr(const string& golden_filename) {
|
||||||
return MungeAndDiffTest(golden_filename,
|
return MungeAndDiffTest(golden_filename, s_captured_streams[STDERR_FILENO]);
|
||||||
s_captured_streams.at(fileno(stderr)).get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool MungeAndDiffTestStdout(const string& golden_filename) {
|
static inline bool MungeAndDiffTestStdout(const string& golden_filename) {
|
||||||
return MungeAndDiffTest(golden_filename,
|
return MungeAndDiffTest(golden_filename, s_captured_streams[STDOUT_FILENO]);
|
||||||
s_captured_streams.at(fileno(stdout)).get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save flags used from logging_unittest.cc.
|
// Save flags used from logging_unittest.cc.
|
||||||
#ifndef GLOG_USE_GFLAGS
|
#ifndef HAVE_LIB_GFLAGS
|
||||||
struct FlagSaver {
|
struct FlagSaver {
|
||||||
FlagSaver()
|
FlagSaver()
|
||||||
: v_(FLAGS_v),
|
: v_(FLAGS_v),
|
||||||
stderrthreshold_(FLAGS_stderrthreshold),
|
stderrthreshold_(FLAGS_stderrthreshold),
|
||||||
logtostderr_(FLAGS_logtostderr),
|
logtostderr_(FLAGS_logtostderr),
|
||||||
alsologtostderr_(FLAGS_alsologtostderr),
|
alsologtostderr_(FLAGS_alsologtostderr) {}
|
||||||
logmailer_(FLAGS_logmailer) {}
|
|
||||||
~FlagSaver() {
|
~FlagSaver() {
|
||||||
FLAGS_v = v_;
|
FLAGS_v = v_;
|
||||||
FLAGS_stderrthreshold = stderrthreshold_;
|
FLAGS_stderrthreshold = stderrthreshold_;
|
||||||
FLAGS_logtostderr = logtostderr_;
|
FLAGS_logtostderr = logtostderr_;
|
||||||
FLAGS_alsologtostderr = alsologtostderr_;
|
FLAGS_alsologtostderr = alsologtostderr_;
|
||||||
FLAGS_logmailer = logmailer_;
|
|
||||||
}
|
}
|
||||||
int v_;
|
int v_;
|
||||||
int stderrthreshold_;
|
int stderrthreshold_;
|
||||||
bool logtostderr_;
|
bool logtostderr_;
|
||||||
bool alsologtostderr_;
|
bool alsologtostderr_;
|
||||||
std::string logmailer_;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Add hook for operator new to ensure there are no memory allocation.
|
class Thread {
|
||||||
|
public:
|
||||||
|
virtual ~Thread() {}
|
||||||
|
|
||||||
void (*g_new_hook)() = nullptr;
|
void SetJoinable(bool) {}
|
||||||
|
#if defined(GLOG_OS_WINDOWS) && !defined(GLOG_OS_CYGWIN)
|
||||||
} // namespace google
|
void Start() {
|
||||||
|
handle_ = CreateThread(NULL,
|
||||||
void* operator new(size_t size, const std::nothrow_t&) noexcept {
|
0,
|
||||||
if (google::g_new_hook) {
|
&Thread::InvokeThreadW,
|
||||||
google::g_new_hook();
|
this,
|
||||||
|
0,
|
||||||
|
&th_);
|
||||||
|
CHECK(handle_) << "CreateThread";
|
||||||
}
|
}
|
||||||
return malloc(size);
|
void Join() {
|
||||||
|
WaitForSingleObject(handle_, INFINITE);
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_PTHREAD)
|
||||||
|
void Start() {
|
||||||
|
pthread_create(&th_, NULL, &Thread::InvokeThread, this);
|
||||||
|
}
|
||||||
|
void Join() {
|
||||||
|
pthread_join(th_, NULL);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# error No thread implementation.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void Run() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void* InvokeThread(void* self) {
|
||||||
|
(static_cast<Thread*>(self))->Run();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(GLOG_OS_WINDOWS) && !defined(GLOG_OS_CYGWIN)
|
||||||
|
static DWORD __stdcall InvokeThreadW(LPVOID self) {
|
||||||
|
InvokeThread(self);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
HANDLE handle_;
|
||||||
|
DWORD th_;
|
||||||
|
#else
|
||||||
|
pthread_t th_;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void SleepForMilliseconds(unsigned t) {
|
||||||
|
#ifndef GLOG_OS_WINDOWS
|
||||||
|
# if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L
|
||||||
|
const struct timespec req = {0, t * 1000 * 1000};
|
||||||
|
nanosleep(&req, NULL);
|
||||||
|
# else
|
||||||
|
usleep(t * 1000);
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
Sleep(t);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add hook for operator new to ensure there are no memory allocation.
|
||||||
|
|
||||||
|
void (*g_new_hook)() = NULL;
|
||||||
|
|
||||||
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
void* operator new(size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
|
void* operator new(size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
|
||||||
void* p = ::operator new(size, std::nothrow);
|
if (GOOGLE_NAMESPACE::g_new_hook) {
|
||||||
if (p == nullptr) {
|
GOOGLE_NAMESPACE::g_new_hook();
|
||||||
throw std::bad_alloc{};
|
|
||||||
}
|
}
|
||||||
return p;
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new[](size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
|
void* operator new[](size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
|
||||||
return ::operator new(size);
|
return ::operator new(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* p) noexcept { free(p); }
|
void operator delete(void* p) throw() {
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
void operator delete(void* p, size_t) noexcept { ::operator delete(p); }
|
void operator delete(void* p, size_t) throw() {
|
||||||
|
::operator delete(p);
|
||||||
|
}
|
||||||
|
|
||||||
void operator delete[](void* p) noexcept { ::operator delete(p); }
|
void operator delete[](void* p) throw() {
|
||||||
|
::operator delete(p);
|
||||||
|
}
|
||||||
|
|
||||||
void operator delete[](void* p, size_t) noexcept { ::operator delete(p); }
|
void operator delete[](void* p, size_t) throw() {
|
||||||
|
::operator delete(p);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
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)
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
// 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 <glog/logging.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
LOG(INFO) << "info";
|
|
||||||
LOG(WARNING) << "warning";
|
|
||||||
LOG(ERROR) << "error";
|
|
||||||
LOG(FATAL) << "fatal";
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
// 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 <glog/raw_logging.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
RAW_LOG(INFO, "info");
|
|
||||||
RAW_LOG(WARNING, "warning");
|
|
||||||
RAW_LOG(ERROR, "error");
|
|
||||||
RAW_LOG(FATAL, "fatal");
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
cmake_minimum_required (VERSION 3.16)
|
|
||||||
project (glog_log_severity LANGUAGES CXX)
|
|
||||||
|
|
||||||
find_package (glog REQUIRED NO_MODULE)
|
|
||||||
|
|
||||||
add_executable (glog_log_severity_constants glog_log_severity_constants.cc)
|
|
||||||
target_link_libraries (glog_log_severity_constants PRIVATE glog::glog)
|
|
||||||
|
|
||||||
add_executable (glog_log_severity_conversion glog_log_severity_conversion.cc)
|
|
||||||
target_link_libraries (glog_log_severity_conversion PRIVATE glog::glog)
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
// 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 <glog/logging.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// Must not compile
|
|
||||||
LOG(0) << "type unsafe info";
|
|
||||||
LOG(1) << "type unsafe info";
|
|
||||||
LOG(2) << "type unsafe info";
|
|
||||||
LOG(3) << "type unsafe info";
|
|
||||||
}
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
// 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 <glog/logging.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// Must not compile
|
|
||||||
google::LogMessage{__FILE__, __LINE__, -1};
|
|
||||||
// Cast to int to avoid implicit conversoin to nullptr
|
|
||||||
google::LogMessage{__FILE__, __LINE__, static_cast<int>(0)};
|
|
||||||
google::LogMessage{__FILE__, __LINE__, 1};
|
|
||||||
google::LogMessage{__FILE__, __LINE__, 2};
|
|
||||||
google::LogMessage{__FILE__, __LINE__, 3};
|
|
||||||
}
|
|
||||||
2064
src/logging.cc
2064
src/logging.cc
File diff suppressed because it is too large
Load Diff
1384
src/logging_custom_prefix_unittest.cc
Normal file
1384
src/logging_custom_prefix_unittest.cc
Normal file
File diff suppressed because it is too large
Load Diff
308
src/logging_custom_prefix_unittest.err
Normal file
308
src/logging_custom_prefix_unittest.err
Normal file
@ -0,0 +1,308 @@
|
|||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=2 logtostderr=0 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
WARNING: Logging before InitGoogleLogging() is written to STDERR
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=0 logtostderr=0 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] foo bar 10 3.4
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Plog every 2, iteration 1: __SUCCESS__ [0]
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 3, iteration 1
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 4, iteration 1
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 5, iteration 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 1
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if less than 3 every 2, iteration 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 2
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Plog every 2, iteration 3: __ENOENT__ [2]
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 3
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if less than 3 every 2, iteration 3
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 3, iteration 4
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 4
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Plog every 2, iteration 5: __EINTR__ [4]
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 4, iteration 5
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 5
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 5, iteration 6
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 6
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Plog every 2, iteration 7: __ENXIO__ [6]
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 3, iteration 7
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 7
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 8
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Plog every 2, iteration 9: __ENOEXEC__ [8]
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 4, iteration 9
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 9
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log every 3, iteration 10
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Log if every 1, iteration 10
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if this
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] array
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] const array
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] foo 1000 1000 3e8
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] foo 1
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] inner
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] outer
|
||||||
|
no prefix
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: foo bar 10 3.400000
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: array
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: const array
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: ptr __PTRTEST__
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: ptr __NULLP__
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: foo 1000 0000001000 3e8
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: foo 1000
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: foo 1000
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: RAW_LOG ERROR: The Message was too long!
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: RAW_LOG ERROR: The Message was too long!
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0 on
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 1 on
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 2 on
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=0 logtostderr=0 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=1 stderrthreshold=0 logtostderr=0 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=-1 stderrthreshold=0 logtostderr=0 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=1 logtostderr=0 alsologtostderr=0
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=2 logtostderr=0 alsologtostderr=0
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=3 logtostderr=0 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=3 logtostderr=1 alsologtostderr=0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=0 stderrthreshold=3 logtostderr=0 alsologtostderr=1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=1 stderrthreshold=1 logtostderr=0 alsologtostderr=0
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Test: v=1 stderrthreshold=3 logtostderr=0 alsologtostderr=1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: vlog 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if -1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if info every 1 expr
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] log_if error every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] vlog_if 0 every 1 expr
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_STRING: reported info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_STRING: reported warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_STRING: reported error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_STRING: LOG_STRING: collected info
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_STRING: LOG_STRING: collected warning
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_STRING: LOG_STRING: collected error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: collected info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: collected warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: collected error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: reported info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: reported warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: reported error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_TO_SINK:
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: collected info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: collected warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK: collected error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK_BUT_NOT_TO_LOGFILE: collected info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK_BUT_NOT_TO_LOGFILE: collected warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_SINK_BUT_NOT_TO_LOGFILE: collected error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_STRING: collected info
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_TO_STRING: LOG_TO_STRING: collected info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_STRING: collected warning
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_TO_STRING: LOG_TO_STRING: collected warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_STRING: collected error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Captured by LOG_TO_STRING: LOG_TO_STRING: collected error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_STRING: reported info
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_STRING: reported warning
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] LOG_TO_STRING: reported error
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Buffering
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Buffered
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Waiting
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Sink got a messages
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Waited
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Sink is sending out a message: IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Have 0 left
|
||||||
|
EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 2
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Buffering
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Buffered
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Waiting
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Sink got a messages
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Waited
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Sink is sending out a message: EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 2
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Have 0 left
|
||||||
|
WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 3
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Buffering
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Buffered
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Waiting
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Sink got a messages
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] RAW: Waited
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Sink is sending out a message: WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 3
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Have 0 left
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Sink capture: IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 1
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Sink capture: EYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 2
|
||||||
|
IYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Sink capture: WYEARDATE TIME__ THREADID logging_custom_prefix_unittest.cc:LINE] Message 3
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
#
|
#
|
||||||
# Copyright (c) 2023, Google Inc.
|
# Copyright (c) 2007, Google Inc.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -32,8 +32,8 @@
|
|||||||
# Author: Sergey Ioffe
|
# Author: Sergey Ioffe
|
||||||
|
|
||||||
get_strings () {
|
get_strings () {
|
||||||
if test -e "$1"; then
|
if test -e ".libs/$1"; then
|
||||||
binary="$1"
|
binary=".libs/$1"
|
||||||
elif test -e "$1.exe"; then
|
elif test -e "$1.exe"; then
|
||||||
binary="$1.exe"
|
binary="$1.exe"
|
||||||
else
|
else
|
||||||
@ -60,21 +60,20 @@ die () {
|
|||||||
# Check that the string literals are appropriately stripped. This will
|
# Check that the string literals are appropriately stripped. This will
|
||||||
# not be the case in debug mode.
|
# not be the case in debug mode.
|
||||||
|
|
||||||
mode=`GLOG_check_mode=1 ./striplog0_unittest 2> /dev/null`
|
mode=`GLOG_check_mode=1 ./logging_striptest0 2> /dev/null`
|
||||||
echo $mode
|
|
||||||
if [ "$mode" = "opt" ];
|
if [ "$mode" = "opt" ];
|
||||||
then
|
then
|
||||||
echo "In OPT mode"
|
echo "In OPT mode"
|
||||||
check_eq "`get_strings striplog0_unittest`" "COND ERROR FATAL INFO WARNING "
|
check_eq "`get_strings logging_striptest0`" "COND ERROR FATAL INFO USAGE WARNING "
|
||||||
check_eq "`get_strings striplog2_unittest`" "COND ERROR FATAL "
|
check_eq "`get_strings logging_striptest2`" "COND ERROR FATAL USAGE "
|
||||||
check_eq "`get_strings striplog10_unittest`" ""
|
check_eq "`get_strings logging_striptest10`" ""
|
||||||
else
|
else
|
||||||
echo "In DBG mode; not checking strings"
|
echo "In DBG mode; not checking strings"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check that LOG(FATAL) aborts even for large STRIP_LOG
|
# Check that LOG(FATAL) aborts even for large STRIP_LOG
|
||||||
|
|
||||||
./striplog2_unittest 2>/dev/null && die "Did not abort for STRIP_LOG=2"
|
./logging_striptest2 2>/dev/null && die "Did not abort for STRIP_LOG=2"
|
||||||
./striplog10_unittest 2>/dev/null && die "Did not abort for STRIP_LOG=10"
|
./logging_striptest10 2>/dev/null && die "Did not abort for STRIP_LOG=10"
|
||||||
|
|
||||||
echo "PASS"
|
echo "PASS"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2007, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -27,8 +27,9 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
//
|
||||||
// Author: Sergiu Deitsch
|
// Author: Sergey Ioffe
|
||||||
|
|
||||||
#include <glog/vlog_is_on.h>
|
#define GOOGLE_STRIP_LOG 10
|
||||||
|
|
||||||
int main() { VLOG_IS_ON(0); }
|
// Include the actual test.
|
||||||
|
#include "logging_striptest_main.cc"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2007, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -27,8 +27,9 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
//
|
||||||
// Author: Sergiu Deitsch
|
// Author: Sergey Ioffe
|
||||||
|
|
||||||
#include <glog/stl_logging.h>
|
#define GOOGLE_STRIP_LOG 2
|
||||||
|
|
||||||
int main() {}
|
// Include the actual test.
|
||||||
|
#include "logging_striptest_main.cc"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2023, Google Inc.
|
// Copyright (c) 2007, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -31,46 +31,32 @@
|
|||||||
|
|
||||||
// The common part of the striplog tests.
|
// The common part of the striplog tests.
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
|
||||||
#include <iosfwd>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <glog/logging.h>
|
||||||
#include "base/commandlineflags.h"
|
#include "base/commandlineflags.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "glog/logging.h"
|
|
||||||
|
|
||||||
|
DECLARE_bool(logtostderr);
|
||||||
GLOG_DEFINE_bool(check_mode, false, "Prints 'opt' or 'dbg'");
|
GLOG_DEFINE_bool(check_mode, false, "Prints 'opt' or 'dbg'");
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace google;
|
using namespace GOOGLE_NAMESPACE;
|
||||||
|
|
||||||
int CheckNoReturn(bool b) {
|
int CheckNoReturn(bool b) {
|
||||||
string s;
|
string s;
|
||||||
if (b) {
|
if (b) {
|
||||||
LOG(FATAL) << "Fatal";
|
LOG(FATAL) << "Fatal";
|
||||||
return 0; // Workaround for MSVC warning C4715
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct A {};
|
struct A { };
|
||||||
std::ostream& operator<<(std::ostream& str, const A&) { return str; }
|
std::ostream &operator<<(std::ostream &str, const A&) {return str;}
|
||||||
|
|
||||||
namespace {
|
|
||||||
void handle_abort(int /*code*/) { std::exit(EXIT_FAILURE); }
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
int main(int, char* argv[]) {
|
int main(int, char* argv[]) {
|
||||||
#if defined(_MSC_VER)
|
|
||||||
// Avoid presenting an interactive dialog that will cause the test to time
|
|
||||||
// out.
|
|
||||||
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
|
||||||
#endif // defined(_MSC_VER)
|
|
||||||
std::signal(SIGABRT, handle_abort);
|
|
||||||
|
|
||||||
FLAGS_logtostderr = true;
|
FLAGS_logtostderr = true;
|
||||||
InitGoogleLogging(argv[0]);
|
InitGoogleLogging(argv[0]);
|
||||||
if (FLAGS_check_mode) {
|
if (FLAGS_check_mode) {
|
||||||
@ -78,8 +64,8 @@ int main(int, char* argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG(INFO) << "TESTMESSAGE INFO";
|
LOG(INFO) << "TESTMESSAGE INFO";
|
||||||
LOG(WARNING) << 2 << "something"
|
LOG(WARNING) << 2 << "something" << "TESTMESSAGE WARNING"
|
||||||
<< "TESTMESSAGE WARNING" << 1 << 'c' << A() << std::endl;
|
<< 1 << 'c' << A() << std::endl;
|
||||||
LOG(ERROR) << "TESTMESSAGE ERROR";
|
LOG(ERROR) << "TESTMESSAGE ERROR";
|
||||||
bool flag = true;
|
bool flag = true;
|
||||||
(flag ? LOG(INFO) : LOG(ERROR)) << "TESTMESSAGE COND";
|
(flag ? LOG(INFO) : LOG(ERROR)) << "TESTMESSAGE COND";
|
||||||
File diff suppressed because it is too large
Load Diff
@ -35,15 +35,16 @@
|
|||||||
#ifndef GLOG_SRC_MOCK_LOG_H_
|
#ifndef GLOG_SRC_MOCK_LOG_H_
|
||||||
#define GLOG_SRC_MOCK_LOG_H_
|
#define GLOG_SRC_MOCK_LOG_H_
|
||||||
|
|
||||||
// For google. This must go first so we get _XOPEN_SOURCE.
|
// For GOOGLE_NAMESPACE. This must go first so we get _XOPEN_SOURCE.
|
||||||
#include <gmock/gmock.h>
|
#include "utilities.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include <gmock/gmock.h>
|
||||||
#include "utilities.h"
|
|
||||||
|
|
||||||
namespace google {
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
_START_GOOGLE_NAMESPACE_
|
||||||
namespace glog_testing {
|
namespace glog_testing {
|
||||||
|
|
||||||
// A ScopedMockLog object intercepts LOG() messages issued during its
|
// A ScopedMockLog object intercepts LOG() messages issued during its
|
||||||
@ -64,14 +65,14 @@ namespace glog_testing {
|
|||||||
//
|
//
|
||||||
// Foo(); // Exercises the code under test.
|
// Foo(); // Exercises the code under test.
|
||||||
// }
|
// }
|
||||||
class ScopedMockLog : public google::LogSink {
|
class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
|
||||||
public:
|
public:
|
||||||
// When a ScopedMockLog object is constructed, it starts to
|
// When a ScopedMockLog object is constructed, it starts to
|
||||||
// intercept logs.
|
// intercept logs.
|
||||||
ScopedMockLog() { AddLogSink(this); }
|
ScopedMockLog() { AddLogSink(this); }
|
||||||
|
|
||||||
// When the object is destructed, it stops intercepting logs.
|
// When the object is destructed, it stops intercepting logs.
|
||||||
~ScopedMockLog() override { RemoveLogSink(this); }
|
~ScopedMockLog() { RemoveLogSink(this); }
|
||||||
|
|
||||||
// Implements the mock method:
|
// Implements the mock method:
|
||||||
//
|
//
|
||||||
@ -86,9 +87,9 @@ class ScopedMockLog : public google::LogSink {
|
|||||||
// for messages from different threads. In fact, if the same or multiple
|
// for messages from different threads. In fact, if the same or multiple
|
||||||
// expectations are matched on two threads concurrently, their actions will
|
// expectations are matched on two threads concurrently, their actions will
|
||||||
// be executed concurrently as well and may interleave.
|
// be executed concurrently as well and may interleave.
|
||||||
MOCK_METHOD3(Log,
|
MOCK_METHOD3(Log, void(GOOGLE_NAMESPACE::LogSeverity severity,
|
||||||
void(google::LogSeverity severity, const std::string& file_path,
|
const std::string& file_path,
|
||||||
const std::string& message));
|
const std::string& message));
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Implements the send() virtual function in class LogSink.
|
// Implements the send() virtual function in class LogSink.
|
||||||
@ -112,10 +113,11 @@ class ScopedMockLog : public google::LogSink {
|
|||||||
// be running simultaneously, we ensure thread-safety of the exchange between
|
// be running simultaneously, we ensure thread-safety of the exchange between
|
||||||
// send() and WaitTillSent(), and that for each message, LOG(), send(),
|
// send() and WaitTillSent(), and that for each message, LOG(), send(),
|
||||||
// WaitTillSent() and Log() are executed in the same thread.
|
// WaitTillSent() and Log() are executed in the same thread.
|
||||||
void send(google::LogSeverity severity, const char* full_filename,
|
virtual void send(GOOGLE_NAMESPACE::LogSeverity severity,
|
||||||
const char* /*base_filename*/, int /*line*/,
|
const char* full_filename,
|
||||||
const LogMessageTime& /*logmsgtime*/, const char* message,
|
const char* /*base_filename*/, int /*line*/,
|
||||||
size_t message_len) override {
|
const LogMessageTime & /*logmsgtime*/,
|
||||||
|
const char* message, size_t message_len) {
|
||||||
// We are only interested in the log severity, full file name, and
|
// We are only interested in the log severity, full file name, and
|
||||||
// log message.
|
// log message.
|
||||||
message_info_.severity = severity;
|
message_info_.severity = severity;
|
||||||
@ -130,7 +132,7 @@ class ScopedMockLog : public google::LogSink {
|
|||||||
//
|
//
|
||||||
// LOG(), send(), WaitTillSent() and Log() will occur in the same thread for
|
// LOG(), send(), WaitTillSent() and Log() will occur in the same thread for
|
||||||
// a given log message.
|
// a given log message.
|
||||||
void WaitTillSent() override {
|
virtual void WaitTillSent() {
|
||||||
// First, and very importantly, we save a copy of the message being
|
// First, and very importantly, we save a copy of the message being
|
||||||
// processed before calling Log(), since Log() may indirectly call send()
|
// processed before calling Log(), since Log() may indirectly call send()
|
||||||
// and WaitTillSent() in the same thread again.
|
// and WaitTillSent() in the same thread again.
|
||||||
@ -141,7 +143,7 @@ class ScopedMockLog : public google::LogSink {
|
|||||||
// All relevant information about a logged message that needs to be passed
|
// All relevant information about a logged message that needs to be passed
|
||||||
// from send() to WaitTillSent().
|
// from send() to WaitTillSent().
|
||||||
struct MessageInfo {
|
struct MessageInfo {
|
||||||
google::LogSeverity severity;
|
GOOGLE_NAMESPACE::LogSeverity severity;
|
||||||
std::string file_path;
|
std::string file_path;
|
||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
@ -149,6 +151,6 @@ class ScopedMockLog : public google::LogSink {
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace glog_testing
|
} // namespace glog_testing
|
||||||
} // namespace google
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
#endif // GLOG_SRC_MOCK_LOG_H_
|
#endif // GLOG_SRC_MOCK_LOG_H_
|
||||||
|
|||||||
@ -33,17 +33,17 @@
|
|||||||
|
|
||||||
#include "mock-log.h"
|
#include "mock-log.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using google::GLOG_ERROR;
|
using GOOGLE_NAMESPACE::GLOG_ERROR;
|
||||||
using google::GLOG_INFO;
|
using GOOGLE_NAMESPACE::GLOG_INFO;
|
||||||
using google::GLOG_WARNING;
|
using GOOGLE_NAMESPACE::GLOG_WARNING;
|
||||||
using google::glog_testing::ScopedMockLog;
|
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
|
||||||
using std::string;
|
using std::string;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
using testing::EndsWith;
|
using testing::EndsWith;
|
||||||
@ -57,7 +57,8 @@ TEST(ScopedMockLogTest, InterceptsLog) {
|
|||||||
InSequence s;
|
InSequence s;
|
||||||
EXPECT_CALL(log,
|
EXPECT_CALL(log,
|
||||||
Log(GLOG_WARNING, EndsWith("mock-log_unittest.cc"), "Fishy."));
|
Log(GLOG_WARNING, EndsWith("mock-log_unittest.cc"), "Fishy."));
|
||||||
EXPECT_CALL(log, Log(GLOG_INFO, _, "Working...")).Times(2);
|
EXPECT_CALL(log, Log(GLOG_INFO, _, "Working..."))
|
||||||
|
.Times(2);
|
||||||
EXPECT_CALL(log, Log(GLOG_ERROR, _, "Bad!!"));
|
EXPECT_CALL(log, Log(GLOG_ERROR, _, "Bad!!"));
|
||||||
|
|
||||||
LOG(WARNING) << "Fishy.";
|
LOG(WARNING) << "Fishy.";
|
||||||
@ -66,9 +67,13 @@ TEST(ScopedMockLogTest, InterceptsLog) {
|
|||||||
LOG(ERROR) << "Bad!!";
|
LOG(ERROR) << "Bad!!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogBranch() { LOG(INFO) << "Logging a branch..."; }
|
void LogBranch() {
|
||||||
|
LOG(INFO) << "Logging a branch...";
|
||||||
|
}
|
||||||
|
|
||||||
void LogTree() { LOG(INFO) << "Logging the whole tree..."; }
|
void LogTree() {
|
||||||
|
LOG(INFO) << "Logging the whole tree...";
|
||||||
|
}
|
||||||
|
|
||||||
void LogForest() {
|
void LogForest() {
|
||||||
LOG(INFO) << "Logging the entire forest.";
|
LOG(INFO) << "Logging the entire forest.";
|
||||||
@ -94,8 +99,8 @@ TEST(ScopedMockLogTest, LogDuringIntercept) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv) {
|
||||||
google::InitGoogleLogging(argv[0]);
|
GOOGLE_NAMESPACE::InitGoogleLogging(argv[0]);
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
testing::InitGoogleMock(&argc, argv);
|
testing::InitGoogleMock(&argc, argv);
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
#include "glog/logging.h"
|
#include <glog/logging.h>
|
||||||
|
|
||||||
int main(int /*argc*/, char** argv) { google::InitGoogleLogging(argv[0]); }
|
int main(int /*argc*/, char** argv)
|
||||||
|
{
|
||||||
|
google::InitGoogleLogging(argv[0]);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2006, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -31,60 +31,57 @@
|
|||||||
//
|
//
|
||||||
// logging_unittest.cc covers the functionality herein
|
// logging_unittest.cc covers the functionality herein
|
||||||
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <mutex>
|
|
||||||
#include <ostream>
|
|
||||||
#include <streambuf>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
# include <unistd.h> // for close() and write()
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_SYSCALL_H)
|
|
||||||
# include <syscall.h> // for syscall()
|
|
||||||
#elif defined(HAVE_SYS_SYSCALL_H)
|
|
||||||
# include <sys/syscall.h> // for syscall()
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <fcntl.h> // for open()
|
|
||||||
|
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "glog/raw_logging.h"
|
|
||||||
#include "stacktrace.h"
|
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && \
|
#include <stdarg.h>
|
||||||
(!(defined(GLOG_OS_MACOSX)) && !(defined(GLOG_OS_OPENBSD))) && \
|
#include <cstdio>
|
||||||
!defined(GLOG_OS_EMSCRIPTEN)
|
#include <cerrno>
|
||||||
# define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
|
#ifdef HAVE_UNISTD_H
|
||||||
#else
|
# include <unistd.h> // for close() and write()
|
||||||
// Not so safe, but what can you do?
|
#endif
|
||||||
# define safe_write(fd, s, len) write(fd, s, len)
|
#include <fcntl.h> // for open()
|
||||||
|
#include <ctime>
|
||||||
|
#include "config.h"
|
||||||
|
#include <glog/logging.h> // To pick up flag settings etc.
|
||||||
|
#include <glog/raw_logging.h>
|
||||||
|
#include "base/commandlineflags.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_STACKTRACE
|
||||||
|
# include "stacktrace.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace google {
|
#if defined(HAVE_SYSCALL_H)
|
||||||
|
#include <syscall.h> // for syscall()
|
||||||
|
#elif defined(HAVE_SYS_SYSCALL_H)
|
||||||
|
#include <sys/syscall.h> // for syscall()
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && (!(defined(GLOG_OS_MACOSX)))
|
||||||
|
# define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
|
||||||
|
#else
|
||||||
|
// Not so safe, but what can you do?
|
||||||
|
# define safe_write(fd, s, len) write(fd, s, len)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_START_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
# define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck) \
|
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck) \
|
||||||
__attribute__((format(archetype, stringIndex, firstToCheck)))
|
__attribute__((format(archetype, stringIndex, firstToCheck)))
|
||||||
# define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex) \
|
#define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex) \
|
||||||
__attribute__((format_arg(stringIndex)))
|
__attribute__((format_arg(stringIndex)))
|
||||||
#else
|
#else
|
||||||
# define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck)
|
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck)
|
||||||
# define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex)
|
#define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// CAVEAT: std::vsnprintf called from *DoRawLog below has some (exotic) code
|
// CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths
|
||||||
// paths that invoke malloc() and getenv() that might acquire some locks. If
|
// that invoke malloc() and getenv() that might acquire some locks.
|
||||||
// this becomes a problem we should reimplement a subset of std::vsnprintf that
|
// If this becomes a problem we should reimplement a subset of vsnprintf
|
||||||
// does not need locks and malloc.
|
// that does not need locks and malloc.
|
||||||
|
|
||||||
// Helper for RawLog__ below.
|
// Helper for RawLog__ below.
|
||||||
// *DoRawLog writes to *buf of *size and move them past the written portion.
|
// *DoRawLog writes to *buf of *size and move them past the written portion.
|
||||||
@ -93,7 +90,7 @@ GLOG_ATTRIBUTE_FORMAT(printf, 3, 4)
|
|||||||
static bool DoRawLog(char** buf, size_t* size, const char* format, ...) {
|
static bool DoRawLog(char** buf, size_t* size, const char* format, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
int n = std::vsnprintf(*buf, *size, format, ap);
|
int n = vsnprintf(*buf, *size, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (n < 0 || static_cast<size_t>(n) > *size) return false;
|
if (n < 0 || static_cast<size_t>(n) > *size) return false;
|
||||||
*size -= static_cast<size_t>(n);
|
*size -= static_cast<size_t>(n);
|
||||||
@ -102,15 +99,15 @@ static bool DoRawLog(char** buf, size_t* size, const char* format, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper for RawLog__ below.
|
// Helper for RawLog__ below.
|
||||||
inline static bool VADoRawLog(char** buf, size_t* size, const char* format,
|
inline static bool VADoRawLog(char** buf, size_t* size,
|
||||||
va_list ap) {
|
const char* format, va_list ap) {
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
# pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
# pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||||
#endif
|
#endif
|
||||||
int n = std::vsnprintf(*buf, *size, format, ap);
|
int n = vsnprintf(*buf, *size, format, ap);
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
# pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
if (n < 0 || static_cast<size_t>(n) > *size) return false;
|
if (n < 0 || static_cast<size_t>(n) > *size) return false;
|
||||||
*size -= static_cast<size_t>(n);
|
*size -= static_cast<size_t>(n);
|
||||||
@ -119,29 +116,9 @@ inline static bool VADoRawLog(char** buf, size_t* size, const char* format,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const int kLogBufSize = 3000;
|
static const int kLogBufSize = 3000;
|
||||||
static std::once_flag crashed;
|
static bool crashed = false;
|
||||||
static logging::internal::CrashReason crash_reason;
|
static CrashReason crash_reason;
|
||||||
static char crash_buf[kLogBufSize + 1] = {0}; // Will end in '\0'
|
static char crash_buf[kLogBufSize + 1] = { 0 }; // Will end in '\0'
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <std::size_t N>
|
|
||||||
class StaticStringBuf : public std::streambuf {
|
|
||||||
public:
|
|
||||||
StaticStringBuf() {
|
|
||||||
setp(std::begin(data_), std::end(data_));
|
|
||||||
setg(std::begin(data_), std::begin(data_), std::end(data_));
|
|
||||||
}
|
|
||||||
const char* data() noexcept {
|
|
||||||
if (pptr() != pbase() && pptr() != epptr() && *(pptr() - 1) != '\0') {
|
|
||||||
sputc('\0');
|
|
||||||
}
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
char data_[N];
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
GLOG_ATTRIBUTE_FORMAT(printf, 4, 5)
|
GLOG_ATTRIBUTE_FORMAT(printf, 4, 5)
|
||||||
void RawLog__(LogSeverity severity, const char* file, int line,
|
void RawLog__(LogSeverity severity, const char* file, int line,
|
||||||
@ -151,25 +128,16 @@ void RawLog__(LogSeverity severity, const char* file, int line,
|
|||||||
!IsGoogleLoggingInitialized())) {
|
!IsGoogleLoggingInitialized())) {
|
||||||
return; // this stderr log message is suppressed
|
return; // this stderr log message is suppressed
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not have any any option other that string streams to obtain the
|
|
||||||
// thread identifier as the corresponding value is not convertible to an
|
|
||||||
// integer. Use a statically allocated buffer to avoid dynamic memory
|
|
||||||
// allocations.
|
|
||||||
StaticStringBuf<kLogBufSize> sbuf;
|
|
||||||
std::ostream oss(&sbuf);
|
|
||||||
|
|
||||||
oss << std::setw(5) << std::this_thread::get_id();
|
|
||||||
|
|
||||||
// can't call localtime_r here: it can allocate
|
// can't call localtime_r here: it can allocate
|
||||||
char buffer[kLogBufSize];
|
char buffer[kLogBufSize];
|
||||||
char* buf = buffer;
|
char* buf = buffer;
|
||||||
size_t size = sizeof(buffer);
|
size_t size = sizeof(buffer);
|
||||||
|
|
||||||
// NOTE: this format should match the specification in base/logging.h
|
// NOTE: this format should match the specification in base/logging.h
|
||||||
DoRawLog(&buf, &size, "%c00000000 00:00:00.000000 %s %s:%d] RAW: ",
|
DoRawLog(&buf, &size, "%c00000000 00:00:00.000000 %5u %s:%d] RAW: ",
|
||||||
GetLogSeverityName(severity)[0], sbuf.data(),
|
LogSeverityNames[severity][0],
|
||||||
const_basename(const_cast<char*>(file)), line);
|
static_cast<unsigned int>(GetTID()),
|
||||||
|
const_basename(const_cast<char *>(file)), line);
|
||||||
|
|
||||||
// Record the position and size of the buffer after the prefix
|
// Record the position and size of the buffer after the prefix
|
||||||
const char* msg_start = buf;
|
const char* msg_start = buf;
|
||||||
@ -188,9 +156,9 @@ void RawLog__(LogSeverity severity, const char* file, int line,
|
|||||||
// avoiding FILE buffering (to avoid invoking malloc()), and bypassing
|
// avoiding FILE buffering (to avoid invoking malloc()), and bypassing
|
||||||
// libc (to side-step any libc interception).
|
// libc (to side-step any libc interception).
|
||||||
// We write just once to avoid races with other invocations of RawLog__.
|
// We write just once to avoid races with other invocations of RawLog__.
|
||||||
safe_write(fileno(stderr), buffer, strlen(buffer));
|
safe_write(STDERR_FILENO, buffer, strlen(buffer));
|
||||||
if (severity == GLOG_FATAL) {
|
if (severity == GLOG_FATAL) {
|
||||||
std::call_once(crashed, [file, line, msg_start, msg_size] {
|
if (!sync_val_compare_and_swap(&crashed, false, true)) {
|
||||||
crash_reason.filename = file;
|
crash_reason.filename = file;
|
||||||
crash_reason.line_number = line;
|
crash_reason.line_number = line;
|
||||||
memcpy(crash_buf, msg_start, msg_size); // Don't include prefix
|
memcpy(crash_buf, msg_start, msg_size); // Don't include prefix
|
||||||
@ -202,9 +170,9 @@ void RawLog__(LogSeverity severity, const char* file, int line,
|
|||||||
crash_reason.depth = 0;
|
crash_reason.depth = 0;
|
||||||
#endif
|
#endif
|
||||||
SetCrashReason(&crash_reason);
|
SetCrashReason(&crash_reason);
|
||||||
});
|
}
|
||||||
LogMessage::Fail(); // abort()
|
LogMessage::Fail(); // abort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace google
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2008, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -31,36 +31,22 @@
|
|||||||
//
|
//
|
||||||
// Implementation of InstallFailureSignalHandler().
|
// Implementation of InstallFailureSignalHandler().
|
||||||
|
|
||||||
#include <algorithm>
|
#include "utilities.h"
|
||||||
#include <csignal>
|
|
||||||
#include <cstring>
|
|
||||||
#include <ctime>
|
|
||||||
#include <mutex>
|
|
||||||
#include <sstream>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "glog/platform.h"
|
|
||||||
#include "stacktrace.h"
|
#include "stacktrace.h"
|
||||||
#include "symbolize.h"
|
#include "symbolize.h"
|
||||||
#include "utilities.h"
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
#include <ctime>
|
||||||
#ifdef HAVE_UCONTEXT_H
|
#ifdef HAVE_UCONTEXT_H
|
||||||
# include <ucontext.h>
|
# include <ucontext.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_UCONTEXT_H
|
#ifdef HAVE_SYS_UCONTEXT_H
|
||||||
# include <sys/ucontext.h>
|
# include <sys/ucontext.h>
|
||||||
#endif
|
|
||||||
#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
|
#endif
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -71,31 +57,32 @@ namespace {
|
|||||||
// The list should be synced with the comment in signalhandler.h.
|
// The list should be synced with the comment in signalhandler.h.
|
||||||
const struct {
|
const struct {
|
||||||
int number;
|
int number;
|
||||||
const char* name;
|
const char *name;
|
||||||
} kFailureSignals[] = {
|
} kFailureSignals[] = {
|
||||||
{SIGSEGV, "SIGSEGV"}, {SIGILL, "SIGILL"},
|
{ SIGSEGV, "SIGSEGV" },
|
||||||
{SIGFPE, "SIGFPE"}, {SIGABRT, "SIGABRT"},
|
{ SIGILL, "SIGILL" },
|
||||||
|
{ SIGFPE, "SIGFPE" },
|
||||||
|
{ SIGABRT, "SIGABRT" },
|
||||||
#if !defined(GLOG_OS_WINDOWS)
|
#if !defined(GLOG_OS_WINDOWS)
|
||||||
{SIGBUS, "SIGBUS"},
|
{ SIGBUS, "SIGBUS" },
|
||||||
#endif
|
#endif
|
||||||
{SIGTERM, "SIGTERM"},
|
{ SIGTERM, "SIGTERM" },
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool kFailureSignalHandlerInstalled = false;
|
static bool kFailureSignalHandlerInstalled = false;
|
||||||
|
|
||||||
#if !defined(GLOG_OS_WINDOWS)
|
#if !defined(GLOG_OS_WINDOWS)
|
||||||
// Returns the program counter from signal context, nullptr if unknown.
|
// Returns the program counter from signal context, NULL if unknown.
|
||||||
void* GetPC(void* ucontext_in_void) {
|
void* GetPC(void* ucontext_in_void) {
|
||||||
# if (defined(HAVE_UCONTEXT_H) || defined(HAVE_SYS_UCONTEXT_H)) && \
|
#if (defined(HAVE_UCONTEXT_H) || defined(HAVE_SYS_UCONTEXT_H)) && defined(PC_FROM_UCONTEXT)
|
||||||
defined(PC_FROM_UCONTEXT)
|
if (ucontext_in_void != NULL) {
|
||||||
if (ucontext_in_void != nullptr) {
|
ucontext_t *context = reinterpret_cast<ucontext_t *>(ucontext_in_void);
|
||||||
ucontext_t* context = reinterpret_cast<ucontext_t*>(ucontext_in_void);
|
|
||||||
return (void*)context->PC_FROM_UCONTEXT;
|
return (void*)context->PC_FROM_UCONTEXT;
|
||||||
}
|
}
|
||||||
# else
|
#else
|
||||||
(void)ucontext_in_void;
|
(void)ucontext_in_void;
|
||||||
# endif
|
#endif
|
||||||
return nullptr;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -103,13 +90,14 @@ void* GetPC(void* ucontext_in_void) {
|
|||||||
// as it's not async signal safe.
|
// as it's not async signal safe.
|
||||||
class MinimalFormatter {
|
class MinimalFormatter {
|
||||||
public:
|
public:
|
||||||
MinimalFormatter(char* buffer, size_t size)
|
MinimalFormatter(char *buffer, size_t size)
|
||||||
: buffer_(buffer), cursor_(buffer), end_(buffer + size) {}
|
: buffer_(buffer),
|
||||||
|
cursor_(buffer),
|
||||||
|
end_(buffer + size) {
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the number of bytes written in the buffer.
|
// Returns the number of bytes written in the buffer.
|
||||||
std::size_t num_bytes_written() const {
|
std::size_t num_bytes_written() const { return static_cast<std::size_t>(cursor_ - buffer_); }
|
||||||
return static_cast<std::size_t>(cursor_ - buffer_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Appends string from "str" and updates the internal cursor.
|
// Appends string from "str" and updates the internal cursor.
|
||||||
void AppendString(const char* str) {
|
void AppendString(const char* str) {
|
||||||
@ -155,14 +143,14 @@ class MinimalFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* buffer_;
|
char *buffer_;
|
||||||
char* cursor_;
|
char *cursor_;
|
||||||
const char* const end_;
|
const char * const end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Writes the given data with the size to the standard error.
|
// Writes the given data with the size to the standard error.
|
||||||
void WriteToStderr(const char* data, size_t size) {
|
void WriteToStderr(const char* data, size_t size) {
|
||||||
if (write(fileno(stderr), data, size) < 0) {
|
if (write(STDERR_FILENO, data, size) < 0) {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +161,7 @@ void (*g_failure_writer)(const char* data, size_t size) = WriteToStderr;
|
|||||||
// Dumps time information. We don't dump human-readable time information
|
// Dumps time information. We don't dump human-readable time information
|
||||||
// as localtime() is not guaranteed to be async signal safe.
|
// as localtime() is not guaranteed to be async signal safe.
|
||||||
void DumpTimeInfo() {
|
void DumpTimeInfo() {
|
||||||
time_t time_in_sec = time(nullptr);
|
time_t time_in_sec = time(NULL);
|
||||||
char buf[256]; // Big enough for time info.
|
char buf[256]; // Big enough for time info.
|
||||||
MinimalFormatter formatter(buf, sizeof(buf));
|
MinimalFormatter formatter(buf, sizeof(buf));
|
||||||
formatter.AppendString("*** Aborted at ");
|
formatter.AppendString("*** Aborted at ");
|
||||||
@ -186,15 +174,15 @@ void DumpTimeInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(hamaji): Use signal instead of sigaction?
|
// TODO(hamaji): Use signal instead of sigaction?
|
||||||
#if defined(HAVE_STACKTRACE) && defined(HAVE_SIGACTION)
|
#ifdef HAVE_SIGACTION
|
||||||
|
|
||||||
// Dumps information about the signal to STDERR.
|
// Dumps information about the signal to STDERR.
|
||||||
void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
|
void DumpSignalInfo(int signal_number, siginfo_t *siginfo) {
|
||||||
// Get the signal name.
|
// Get the signal name.
|
||||||
const char* signal_name = nullptr;
|
const char* signal_name = NULL;
|
||||||
for (auto kFailureSignal : kFailureSignals) {
|
for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
|
||||||
if (signal_number == kFailureSignal.number) {
|
if (signal_number == kFailureSignals[i].number) {
|
||||||
signal_name = kFailureSignal.name;
|
signal_name = kFailureSignals[i].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,25 +203,21 @@ void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
|
|||||||
formatter.AppendString(")");
|
formatter.AppendString(")");
|
||||||
formatter.AppendString(" received by PID ");
|
formatter.AppendString(" received by PID ");
|
||||||
formatter.AppendUint64(static_cast<uint64>(getpid()), 10);
|
formatter.AppendUint64(static_cast<uint64>(getpid()), 10);
|
||||||
formatter.AppendString(" (TID ");
|
formatter.AppendString(" (TID 0x");
|
||||||
|
// We assume pthread_t is an integral number or a pointer, rather
|
||||||
std::ostringstream oss;
|
// than a complex struct. In some environments, pthread_self()
|
||||||
oss << std::showbase << std::hex << std::this_thread::get_id();
|
// returns an uint64 but in some other environments pthread_self()
|
||||||
formatter.AppendString(oss.str().c_str());
|
// returns a pointer.
|
||||||
# if defined(GLOG_OS_LINUX) && defined(HAVE_SYS_SYSCALL_H) && \
|
pthread_t id = pthread_self();
|
||||||
defined(HAVE_SYS_TYPES_H)
|
formatter.AppendUint64(
|
||||||
pid_t tid = syscall(SYS_gettid);
|
reinterpret_cast<uint64>(reinterpret_cast<const char*>(id)), 16);
|
||||||
formatter.AppendString(" LWP ");
|
|
||||||
formatter.AppendUint64(static_cast<uint64>(tid), 10);
|
|
||||||
# endif
|
|
||||||
formatter.AppendString(") ");
|
formatter.AppendString(") ");
|
||||||
|
|
||||||
// Only linux has the PID of the signal sender in si_pid.
|
// Only linux has the PID of the signal sender in si_pid.
|
||||||
# ifdef GLOG_OS_LINUX
|
#ifdef GLOG_OS_LINUX
|
||||||
formatter.AppendString("from PID ");
|
formatter.AppendString("from PID ");
|
||||||
formatter.AppendUint64(static_cast<uint64>(siginfo->si_pid), 10);
|
formatter.AppendUint64(static_cast<uint64>(siginfo->si_pid), 10);
|
||||||
formatter.AppendString("; ");
|
formatter.AppendString("; ");
|
||||||
# endif
|
#endif
|
||||||
formatter.AppendString("stack trace: ***\n");
|
formatter.AppendString("stack trace: ***\n");
|
||||||
g_failure_writer(buf, formatter.num_bytes_written());
|
g_failure_writer(buf, formatter.num_bytes_written());
|
||||||
}
|
}
|
||||||
@ -243,19 +227,14 @@ void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
|
|||||||
// Dumps information about the stack frame to STDERR.
|
// Dumps information about the stack frame to STDERR.
|
||||||
void DumpStackFrameInfo(const char* prefix, void* pc) {
|
void DumpStackFrameInfo(const char* prefix, void* pc) {
|
||||||
// Get the symbol name.
|
// Get the symbol name.
|
||||||
const char* symbol = "(unknown)";
|
const char *symbol = "(unknown)";
|
||||||
#if defined(HAVE_SYMBOLIZE)
|
|
||||||
char symbolized[1024]; // Big enough for a sane symbol.
|
char symbolized[1024]; // Big enough for a sane symbol.
|
||||||
// Symbolizes the previous address of pc because pc may be in the
|
// Symbolizes the previous address of pc because pc may be in the
|
||||||
// next function.
|
// next function.
|
||||||
if (Symbolize(reinterpret_cast<char*>(pc) - 1, symbolized,
|
if (Symbolize(reinterpret_cast<char *>(pc) - 1,
|
||||||
sizeof(symbolized))) {
|
symbolized, sizeof(symbolized))) {
|
||||||
symbol = symbolized;
|
symbol = symbolized;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
# pragma message( \
|
|
||||||
"Symbolize functionality is not available for target platform: stack dump will contain empty frames.")
|
|
||||||
#endif // defined(HAVE_SYMBOLIZE)
|
|
||||||
|
|
||||||
char buf[1024]; // Big enough for stack frame info.
|
char buf[1024]; // Big enough for stack frame info.
|
||||||
MinimalFormatter formatter(buf, sizeof(buf));
|
MinimalFormatter formatter(buf, sizeof(buf));
|
||||||
@ -277,7 +256,7 @@ void InvokeDefaultSignalHandler(int signal_number) {
|
|||||||
memset(&sig_action, 0, sizeof(sig_action));
|
memset(&sig_action, 0, sizeof(sig_action));
|
||||||
sigemptyset(&sig_action.sa_mask);
|
sigemptyset(&sig_action.sa_mask);
|
||||||
sig_action.sa_handler = SIG_DFL;
|
sig_action.sa_handler = SIG_DFL;
|
||||||
sigaction(signal_number, &sig_action, nullptr);
|
sigaction(signal_number, &sig_action, NULL);
|
||||||
kill(getpid(), signal_number);
|
kill(getpid(), signal_number);
|
||||||
#elif defined(GLOG_OS_WINDOWS)
|
#elif defined(GLOG_OS_WINDOWS)
|
||||||
signal(signal_number, SIG_DFL);
|
signal(signal_number, SIG_DFL);
|
||||||
@ -285,19 +264,53 @@ void InvokeDefaultSignalHandler(int signal_number) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// This variable is used for protecting FailureSignalHandler() from dumping
|
// This variable is used for protecting FailureSignalHandler() from
|
||||||
// stuff while another thread is doing it. Our policy is to let the first
|
// dumping stuff while another thread is doing it. Our policy is to let
|
||||||
// thread dump stuff and let other threads do nothing.
|
// the first thread dump stuff and let other threads wait.
|
||||||
// See also comments in FailureSignalHandler().
|
// See also comments in FailureSignalHandler().
|
||||||
static std::once_flag signaled;
|
static pthread_t* g_entered_thread_id_pointer = NULL;
|
||||||
|
|
||||||
static void HandleSignal(int signal_number
|
// Dumps signal and stack frame information, and invokes the default
|
||||||
#if !defined(GLOG_OS_WINDOWS)
|
// signal handler once our job is done.
|
||||||
,
|
#if defined(GLOG_OS_WINDOWS)
|
||||||
siginfo_t* signal_info, void* ucontext
|
void FailureSignalHandler(int signal_number)
|
||||||
|
#else
|
||||||
|
void FailureSignalHandler(int signal_number,
|
||||||
|
siginfo_t *signal_info,
|
||||||
|
void *ucontext)
|
||||||
#endif
|
#endif
|
||||||
) {
|
{
|
||||||
|
// First check if we've already entered the function. We use an atomic
|
||||||
|
// compare and swap operation for platforms that support it. For other
|
||||||
|
// platforms, we use a naive method that could lead to a subtle race.
|
||||||
|
|
||||||
|
// We assume pthread_self() is async signal safe, though it's not
|
||||||
|
// officially guaranteed.
|
||||||
|
pthread_t my_thread_id = pthread_self();
|
||||||
|
// NOTE: We could simply use pthread_t rather than pthread_t* for this,
|
||||||
|
// if pthread_self() is guaranteed to return non-zero value for thread
|
||||||
|
// ids, but there is no such guarantee. We need to distinguish if the
|
||||||
|
// old value (value returned from __sync_val_compare_and_swap) is
|
||||||
|
// different from the original value (in this case NULL).
|
||||||
|
pthread_t* old_thread_id_pointer =
|
||||||
|
glog_internal_namespace_::sync_val_compare_and_swap(
|
||||||
|
&g_entered_thread_id_pointer,
|
||||||
|
static_cast<pthread_t*>(NULL),
|
||||||
|
&my_thread_id);
|
||||||
|
if (old_thread_id_pointer != NULL) {
|
||||||
|
// We've already entered the signal handler. What should we do?
|
||||||
|
if (pthread_equal(my_thread_id, *g_entered_thread_id_pointer)) {
|
||||||
|
// It looks the current thread is reentering the signal handler.
|
||||||
|
// Something must be going wrong (maybe we are reentering by another
|
||||||
|
// type of signal?). Kill ourself by the default signal handler.
|
||||||
|
InvokeDefaultSignalHandler(signal_number);
|
||||||
|
}
|
||||||
|
// Another thread is dumping stuff. Let's wait until that thread
|
||||||
|
// finishes the job and kills the process.
|
||||||
|
while (true) {
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
// This is the first time we enter the signal handler. We are going to
|
// This is the first time we enter the signal handler. We are going to
|
||||||
// do some interesting stuff from here.
|
// do some interesting stuff from here.
|
||||||
// TODO(satorux): We might want to set timeout here using alarm(), but
|
// TODO(satorux): We might want to set timeout here using alarm(), but
|
||||||
@ -308,26 +321,22 @@ static void HandleSignal(int signal_number
|
|||||||
|
|
||||||
#if !defined(GLOG_OS_WINDOWS)
|
#if !defined(GLOG_OS_WINDOWS)
|
||||||
// Get the program counter from ucontext.
|
// Get the program counter from ucontext.
|
||||||
void* pc = GetPC(ucontext);
|
void *pc = GetPC(ucontext);
|
||||||
DumpStackFrameInfo("PC: ", pc);
|
DumpStackFrameInfo("PC: ", pc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STACKTRACE
|
#ifdef HAVE_STACKTRACE
|
||||||
// Get the stack traces.
|
// Get the stack traces.
|
||||||
void* stack[32];
|
void *stack[32];
|
||||||
// +1 to exclude this function.
|
// +1 to exclude this function.
|
||||||
const int depth = GetStackTrace(stack, ARRAYSIZE(stack), 1);
|
const int depth = GetStackTrace(stack, ARRAYSIZE(stack), 1);
|
||||||
# ifdef HAVE_SIGACTION
|
# ifdef HAVE_SIGACTION
|
||||||
DumpSignalInfo(signal_number, signal_info);
|
DumpSignalInfo(signal_number, signal_info);
|
||||||
# elif !defined(GLOG_OS_WINDOWS)
|
# endif
|
||||||
(void)signal_info;
|
|
||||||
# endif
|
|
||||||
// Dump the stack traces.
|
// Dump the stack traces.
|
||||||
for (int i = 0; i < depth; ++i) {
|
for (int i = 0; i < depth; ++i) {
|
||||||
DumpStackFrameInfo(" ", stack[i]);
|
DumpStackFrameInfo(" ", stack[i]);
|
||||||
}
|
}
|
||||||
#elif !defined(GLOG_OS_WINDOWS)
|
|
||||||
(void)signal_info;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// *** TRANSITION ***
|
// *** TRANSITION ***
|
||||||
@ -341,38 +350,23 @@ static void HandleSignal(int signal_number
|
|||||||
|
|
||||||
// Flush the logs before we do anything in case 'anything'
|
// Flush the logs before we do anything in case 'anything'
|
||||||
// causes problems.
|
// causes problems.
|
||||||
FlushLogFilesUnsafe(GLOG_INFO);
|
FlushLogFilesUnsafe(0);
|
||||||
|
|
||||||
// Kill ourself by the default signal handler.
|
// Kill ourself by the default signal handler.
|
||||||
InvokeDefaultSignalHandler(signal_number);
|
InvokeDefaultSignalHandler(signal_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dumps signal and stack frame information, and invokes the default
|
|
||||||
// signal handler once our job is done.
|
|
||||||
#if defined(GLOG_OS_WINDOWS)
|
|
||||||
void FailureSignalHandler(int signal_number)
|
|
||||||
#else
|
|
||||||
void FailureSignalHandler(int signal_number, siginfo_t* signal_info,
|
|
||||||
void* ucontext)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
std::call_once(signaled, &HandleSignal, signal_number
|
|
||||||
#if !defined(GLOG_OS_WINDOWS)
|
|
||||||
,
|
|
||||||
signal_info, ucontext
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace glog_internal_namespace_ {
|
||||||
|
|
||||||
bool IsFailureSignalHandlerInstalled() {
|
bool IsFailureSignalHandlerInstalled() {
|
||||||
#ifdef HAVE_SIGACTION
|
#ifdef HAVE_SIGACTION
|
||||||
// TODO(andschwa): Return kFailureSignalHandlerInstalled?
|
// TODO(andschwa): Return kFailureSignalHandlerInstalled?
|
||||||
struct sigaction sig_action;
|
struct sigaction sig_action;
|
||||||
memset(&sig_action, 0, sizeof(sig_action));
|
memset(&sig_action, 0, sizeof(sig_action));
|
||||||
sigemptyset(&sig_action.sa_mask);
|
sigemptyset(&sig_action.sa_mask);
|
||||||
sigaction(SIGABRT, nullptr, &sig_action);
|
sigaction(SIGABRT, NULL, &sig_action);
|
||||||
if (sig_action.sa_sigaction == &FailureSignalHandler) {
|
if (sig_action.sa_sigaction == &FailureSignalHandler) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -382,6 +376,8 @@ bool IsFailureSignalHandlerInstalled() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace glog_internal_namespace_
|
||||||
|
|
||||||
void InstallFailureSignalHandler() {
|
void InstallFailureSignalHandler() {
|
||||||
#ifdef HAVE_SIGACTION
|
#ifdef HAVE_SIGACTION
|
||||||
// Build the sigaction struct.
|
// Build the sigaction struct.
|
||||||
@ -391,13 +387,14 @@ void InstallFailureSignalHandler() {
|
|||||||
sig_action.sa_flags |= SA_SIGINFO;
|
sig_action.sa_flags |= SA_SIGINFO;
|
||||||
sig_action.sa_sigaction = &FailureSignalHandler;
|
sig_action.sa_sigaction = &FailureSignalHandler;
|
||||||
|
|
||||||
for (auto kFailureSignal : kFailureSignals) {
|
for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
|
||||||
CHECK_ERR(sigaction(kFailureSignal.number, &sig_action, nullptr));
|
CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL));
|
||||||
}
|
}
|
||||||
kFailureSignalHandlerInstalled = true;
|
kFailureSignalHandlerInstalled = true;
|
||||||
#elif defined(GLOG_OS_WINDOWS)
|
#elif defined(GLOG_OS_WINDOWS)
|
||||||
for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
|
for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
|
||||||
CHECK_NE(signal(kFailureSignals[i].number, &FailureSignalHandler), SIG_ERR);
|
CHECK_NE(signal(kFailureSignals[i].number, &FailureSignalHandler),
|
||||||
|
SIG_ERR);
|
||||||
}
|
}
|
||||||
kFailureSignalHandlerInstalled = true;
|
kFailureSignalHandlerInstalled = true;
|
||||||
#endif // HAVE_SIGACTION
|
#endif // HAVE_SIGACTION
|
||||||
@ -409,4 +406,4 @@ void InstallFailureWriter(void (*writer)(const char* data, size_t size)) {
|
|||||||
#endif // HAVE_SIGACTION
|
#endif // HAVE_SIGACTION
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace google
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2008, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -32,52 +32,51 @@
|
|||||||
// This is a helper binary for testing signalhandler.cc. The actual test
|
// This is a helper binary for testing signalhandler.cc. The actual test
|
||||||
// is done in signalhandler_unittest.sh.
|
// is done in signalhandler_unittest.sh.
|
||||||
|
|
||||||
|
#include "utilities.h"
|
||||||
|
|
||||||
|
#if defined(HAVE_PTHREAD)
|
||||||
|
# include <pthread.h>
|
||||||
|
#endif
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <glog/logging.h>
|
||||||
|
|
||||||
#include "config.h"
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
#include "glog/logging.h"
|
#include <gflags/gflags.h>
|
||||||
#include "stacktrace.h"
|
|
||||||
#include "symbolize.h"
|
|
||||||
|
|
||||||
#if defined(HAVE_UNISTD_H)
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
|
||||||
# include <gflags/gflags.h>
|
|
||||||
using namespace GFLAGS_NAMESPACE;
|
using namespace GFLAGS_NAMESPACE;
|
||||||
#endif
|
#endif
|
||||||
#if defined(_MSC_VER)
|
|
||||||
# include <io.h> // write
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace google;
|
using namespace GOOGLE_NAMESPACE;
|
||||||
|
|
||||||
static void DieInThread(int* a) {
|
static void* DieInThread(void*) {
|
||||||
std::ostringstream oss;
|
// We assume pthread_t is an integral number or a pointer, rather
|
||||||
oss << std::showbase << std::hex << std::this_thread::get_id();
|
// than a complex struct. In some environments, pthread_self()
|
||||||
|
// returns an uint64 but in some other environments pthread_self()
|
||||||
fprintf(stderr, "%s is dying\n", oss.str().c_str());
|
// returns a pointer.
|
||||||
int b = 1 / *a;
|
fprintf(
|
||||||
|
stderr, "0x%px is dying\n",
|
||||||
|
static_cast<const void*>(reinterpret_cast<const char*>(pthread_self())));
|
||||||
|
// Use volatile to prevent from these to be optimized away.
|
||||||
|
volatile int a = 0;
|
||||||
|
volatile int b = 1 / a;
|
||||||
fprintf(stderr, "We should have died: b=%d\n", b);
|
fprintf(stderr, "We should have died: b=%d\n", b);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteToStdout(const char* data, size_t size) {
|
static void WriteToStdout(const char* data, size_t size) {
|
||||||
if (write(fileno(stdout), data, size) < 0) {
|
if (write(STDOUT_FILENO, data, size) < 0) {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv) {
|
||||||
#if defined(HAVE_STACKTRACE) && defined(HAVE_SYMBOLIZE)
|
#if defined(HAVE_STACKTRACE) && defined(HAVE_SYMBOLIZE)
|
||||||
InitGoogleLogging(argv[0]);
|
InitGoogleLogging(argv[0]);
|
||||||
# ifdef GLOG_USE_GFLAGS
|
#ifdef HAVE_LIB_GFLAGS
|
||||||
ParseCommandLineFlags(&argc, &argv, true);
|
ParseCommandLineFlags(&argc, &argv, true);
|
||||||
# endif
|
#endif
|
||||||
InstallFailureSignalHandler();
|
InstallFailureSignalHandler();
|
||||||
const std::string command = argc > 1 ? argv[1] : "none";
|
const std::string command = argc > 1 ? argv[1] : "none";
|
||||||
if (command == "segv") {
|
if (command == "segv") {
|
||||||
@ -85,21 +84,26 @@ int main(int argc, char** argv) {
|
|||||||
LOG(INFO) << "create the log file";
|
LOG(INFO) << "create the log file";
|
||||||
LOG(INFO) << "a message before segv";
|
LOG(INFO) << "a message before segv";
|
||||||
// We assume 0xDEAD is not writable.
|
// We assume 0xDEAD is not writable.
|
||||||
int* a = (int*)0xDEAD;
|
int *a = (int*)0xDEAD;
|
||||||
*a = 0;
|
*a = 0;
|
||||||
} else if (command == "loop") {
|
} else if (command == "loop") {
|
||||||
fprintf(stderr, "looping\n");
|
fprintf(stderr, "looping\n");
|
||||||
while (true)
|
while (true);
|
||||||
;
|
|
||||||
} else if (command == "die_in_thread") {
|
} else if (command == "die_in_thread") {
|
||||||
std::thread t{&DieInThread, nullptr};
|
#if defined(HAVE_PTHREAD)
|
||||||
t.join();
|
pthread_t thread;
|
||||||
|
pthread_create(&thread, NULL, &DieInThread, NULL);
|
||||||
|
pthread_join(thread, NULL);
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "no pthread\n");
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
} else if (command == "dump_to_stdout") {
|
} else if (command == "dump_to_stdout") {
|
||||||
InstallFailureWriter(WriteToStdout);
|
InstallFailureWriter(WriteToStdout);
|
||||||
abort();
|
abort();
|
||||||
} else if (command == "installed") {
|
} else if (command == "installed") {
|
||||||
fprintf(stderr, "signal handler installed: %s\n",
|
fprintf(stderr, "signal handler installed: %s\n",
|
||||||
IsFailureSignalHandlerInstalled() ? "true" : "false");
|
IsFailureSignalHandlerInstalled() ? "true" : "false");
|
||||||
} else {
|
} else {
|
||||||
// Tell the shell script
|
// Tell the shell script
|
||||||
puts("OK");
|
puts("OK");
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
// 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.
|
|
||||||
//
|
|
||||||
// Routines to extract the current stack trace. These functions are
|
|
||||||
// thread-safe.
|
|
||||||
|
|
||||||
#include "stacktrace.h"
|
|
||||||
|
|
||||||
// Make an implementation of stacktrace compiled.
|
|
||||||
#if defined(STACKTRACE_H)
|
|
||||||
# include STACKTRACE_H
|
|
||||||
#endif
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024, Google Inc.
|
// Copyright (c) 2000 - 2007, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -30,46 +30,13 @@
|
|||||||
// Routines to extract the current stack trace. These functions are
|
// Routines to extract the current stack trace. These functions are
|
||||||
// thread-safe.
|
// thread-safe.
|
||||||
|
|
||||||
#ifndef GLOG_INTERNAL_STACKTRACE_H
|
#ifndef BASE_STACKTRACE_H_
|
||||||
#define GLOG_INTERNAL_STACKTRACE_H
|
#define BASE_STACKTRACE_H_
|
||||||
|
|
||||||
#include "glog/platform.h"
|
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
|
||||||
# include "glog/export.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(GLOG_NO_EXPORT)
|
|
||||||
# error "stacktrace.h" was not included correctly.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#if defined(HAVE_LIBUNWIND)
|
#include <glog/logging.h>
|
||||||
# define STACKTRACE_H "stacktrace_libunwind-inl.h"
|
|
||||||
#elif defined(HAVE_UNWIND)
|
|
||||||
# define STACKTRACE_H "stacktrace_unwind-inl.h"
|
|
||||||
#elif !defined(NO_FRAME_POINTER)
|
|
||||||
# if defined(__i386__) && __GNUC__ >= 2
|
|
||||||
# define STACKTRACE_H "stacktrace_x86-inl.h"
|
|
||||||
# elif (defined(__ppc__) || defined(__PPC__)) && __GNUC__ >= 2
|
|
||||||
# define STACKTRACE_H "stacktrace_powerpc-inl.h"
|
|
||||||
# elif defined(GLOG_OS_WINDOWS)
|
|
||||||
# define STACKTRACE_H "stacktrace_windows-inl.h"
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(STACKTRACE_H) && defined(HAVE_EXECINFO_BACKTRACE)
|
_START_GOOGLE_NAMESPACE_
|
||||||
# define STACKTRACE_H "stacktrace_generic-inl.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(STACKTRACE_H)
|
|
||||||
# define HAVE_STACKTRACE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace google {
|
|
||||||
inline namespace glog_internal_namespace_ {
|
|
||||||
|
|
||||||
#if defined(HAVE_STACKTRACE)
|
|
||||||
|
|
||||||
// This is similar to the GetStackFrames routine, except that it returns
|
// This is similar to the GetStackFrames routine, except that it returns
|
||||||
// the stack trace only, and not the stack frame sizes as well.
|
// the stack trace only, and not the stack frame sizes as well.
|
||||||
@ -86,12 +53,9 @@ inline namespace glog_internal_namespace_ {
|
|||||||
// result[1] main
|
// result[1] main
|
||||||
// .... ...
|
// .... ...
|
||||||
//
|
//
|
||||||
// "result" must not be nullptr.
|
// "result" must not be NULL.
|
||||||
GLOG_NO_EXPORT int GetStackTrace(void** result, int max_depth, int skip_count);
|
GLOG_EXPORT int GetStackTrace(void** result, int max_depth, int skip_count);
|
||||||
|
|
||||||
#endif // defined(HAVE_STACKTRACE)
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|
||||||
} // namespace glog_internal_namespace_
|
#endif // BASE_STACKTRACE_H_
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
#endif // GLOG_INTERNAL_STACKTRACE_H
|
|
||||||
|
|||||||
@ -32,18 +32,15 @@
|
|||||||
// Note: The glibc implementation may cause a call to malloc.
|
// Note: The glibc implementation may cause a call to malloc.
|
||||||
// This can cause a deadlock in HeapProfiler.
|
// This can cause a deadlock in HeapProfiler.
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
#include <string.h>
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include "stacktrace.h"
|
#include "stacktrace.h"
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
inline namespace glog_internal_namespace_ {
|
|
||||||
|
|
||||||
// If you change this function, also change GetStackFrames below.
|
// If you change this function, also change GetStackFrames below.
|
||||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||||
static const int kStackLength = 64;
|
static const int kStackLength = 64;
|
||||||
void* stack[kStackLength];
|
void * stack[kStackLength];
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
size = backtrace(stack, kStackLength);
|
size = backtrace(stack, kStackLength);
|
||||||
@ -62,5 +59,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
|
|||||||
return result_count;
|
return result_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace glog_internal_namespace_
|
_END_GOOGLE_NAMESPACE_
|
||||||
} // namespace google
|
|
||||||
|
|||||||
@ -37,11 +37,10 @@ extern "C" {
|
|||||||
#define UNW_LOCAL_ONLY
|
#define UNW_LOCAL_ONLY
|
||||||
#include <libunwind.h>
|
#include <libunwind.h>
|
||||||
}
|
}
|
||||||
#include "glog/raw_logging.h"
|
#include <glog/raw_logging.h>
|
||||||
#include "stacktrace.h"
|
#include "stacktrace.h"
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
inline namespace glog_internal_namespace_ {
|
|
||||||
|
|
||||||
// Sometimes, we can try to get a stack trace from within a stack
|
// Sometimes, we can try to get a stack trace from within a stack
|
||||||
// trace, because libunwind can call mmap (maybe indirectly via an
|
// trace, because libunwind can call mmap (maybe indirectly via an
|
||||||
@ -52,11 +51,11 @@ inline namespace glog_internal_namespace_ {
|
|||||||
// cases, we return 0 to indicate the situation.
|
// cases, we return 0 to indicate the situation.
|
||||||
// We can use the GCC __thread syntax here since libunwind is not supported on
|
// We can use the GCC __thread syntax here since libunwind is not supported on
|
||||||
// Windows.
|
// Windows.
|
||||||
static __thread bool g_tl_entered; // Initialized to false.
|
static __thread bool g_tl_entered; // Initialized to false.
|
||||||
|
|
||||||
// If you change this function, also change GetStackFrames below.
|
// If you change this function, also change GetStackFrames below.
|
||||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||||
void* ip;
|
void *ip;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
unw_cursor_t cursor;
|
unw_cursor_t cursor;
|
||||||
unw_context_t uc;
|
unw_context_t uc;
|
||||||
@ -68,11 +67,11 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
|
|||||||
|
|
||||||
unw_getcontext(&uc);
|
unw_getcontext(&uc);
|
||||||
RAW_CHECK(unw_init_local(&cursor, &uc) >= 0, "unw_init_local failed");
|
RAW_CHECK(unw_init_local(&cursor, &uc) >= 0, "unw_init_local failed");
|
||||||
skip_count++; // Do not include the "GetStackTrace" frame
|
skip_count++; // Do not include the "GetStackTrace" frame
|
||||||
|
|
||||||
while (n < max_depth) {
|
while (n < max_depth) {
|
||||||
int ret =
|
int ret =
|
||||||
unw_get_reg(&cursor, UNW_REG_IP, reinterpret_cast<unw_word_t*>(&ip));
|
unw_get_reg(&cursor, UNW_REG_IP, reinterpret_cast<unw_word_t *>(&ip));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -91,5 +90,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace glog_internal_namespace_
|
_END_GOOGLE_NAMESPACE_
|
||||||
} // namespace google
|
|
||||||
|
|||||||
@ -35,41 +35,37 @@
|
|||||||
// http://www.linux-foundation.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#STACK
|
// http://www.linux-foundation.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#STACK
|
||||||
// Linux has similar code: http://patchwork.ozlabs.org/linuxppc/patch?id=8882
|
// Linux has similar code: http://patchwork.ozlabs.org/linuxppc/patch?id=8882
|
||||||
|
|
||||||
#include <cstdint> // for uintptr_t
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <stdint.h> // for uintptr_t
|
||||||
#include "stacktrace.h"
|
#include "stacktrace.h"
|
||||||
|
|
||||||
namespace google {
|
_START_GOOGLE_NAMESPACE_
|
||||||
inline namespace glog_internal_namespace_ {
|
|
||||||
|
|
||||||
// Given a pointer to a stack frame, locate and return the calling
|
// Given a pointer to a stack frame, locate and return the calling
|
||||||
// stackframe, or return nullptr if no stackframe can be found. Perform sanity
|
// stackframe, or return NULL if no stackframe can be found. Perform sanity
|
||||||
// checks (the strictness of which is controlled by the boolean parameter
|
// checks (the strictness of which is controlled by the boolean parameter
|
||||||
// "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned.
|
// "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned.
|
||||||
template <bool STRICT_UNWINDING>
|
template<bool STRICT_UNWINDING>
|
||||||
static void** NextStackFrame(void** old_sp) {
|
static void **NextStackFrame(void **old_sp) {
|
||||||
void** new_sp = static_cast<void**>(*old_sp);
|
void **new_sp = static_cast<void **>(*old_sp);
|
||||||
|
|
||||||
// Check that the transition from frame pointer old_sp to frame
|
// Check that the transition from frame pointer old_sp to frame
|
||||||
// pointer new_sp isn't clearly bogus
|
// pointer new_sp isn't clearly bogus
|
||||||
if (STRICT_UNWINDING) {
|
if (STRICT_UNWINDING) {
|
||||||
// With the stack growing downwards, older stack frame must be
|
// With the stack growing downwards, older stack frame must be
|
||||||
// at a greater address that the current one.
|
// at a greater address that the current one.
|
||||||
if (new_sp <= old_sp) return nullptr;
|
if (new_sp <= old_sp) return NULL;
|
||||||
// Assume stack frames larger than 100,000 bytes are bogus.
|
// Assume stack frames larger than 100,000 bytes are bogus.
|
||||||
if ((uintptr_t)new_sp - (uintptr_t)old_sp > 100000) return nullptr;
|
if ((uintptr_t)new_sp - (uintptr_t)old_sp > 100000) return NULL;
|
||||||
} else {
|
} else {
|
||||||
// In the non-strict mode, allow discontiguous stack frames.
|
// In the non-strict mode, allow discontiguous stack frames.
|
||||||
// (alternate-signal-stacks for example).
|
// (alternate-signal-stacks for example).
|
||||||
if (new_sp == old_sp) return nullptr;
|
if (new_sp == old_sp) return NULL;
|
||||||
// And allow frames upto about 1MB.
|
// And allow frames upto about 1MB.
|
||||||
if ((new_sp > old_sp) &&
|
if ((new_sp > old_sp)
|
||||||
((uintptr_t)new_sp - (uintptr_t)old_sp > 1000000)) {
|
&& ((uintptr_t)new_sp - (uintptr_t)old_sp > 1000000)) return NULL;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ((uintptr_t)new_sp & (sizeof(void*) - 1)) return nullptr;
|
if ((uintptr_t)new_sp & (sizeof(void *) - 1)) return NULL;
|
||||||
return new_sp;
|
return new_sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,15 +75,15 @@ void StacktracePowerPCDummyFunction() { __asm__ volatile(""); }
|
|||||||
|
|
||||||
// If you change this function, also change GetStackFrames below.
|
// If you change this function, also change GetStackFrames below.
|
||||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||||
void** sp;
|
void **sp;
|
||||||
// Apple OS X uses an old version of gnu as -- both Darwin 7.9.0 (Panther)
|
// Apple OS X uses an old version of gnu as -- both Darwin 7.9.0 (Panther)
|
||||||
// and Darwin 8.8.1 (Tiger) use as 1.38. This means we have to use a
|
// and Darwin 8.8.1 (Tiger) use as 1.38. This means we have to use a
|
||||||
// different asm syntax. I don't know quite the best way to discriminate
|
// different asm syntax. I don't know quite the best way to discriminate
|
||||||
// systems using the old as from the new one; I've gone with __APPLE__.
|
// systems using the old as from the new one; I've gone with __APPLE__.
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
__asm__ volatile("mr %0,r1" : "=r"(sp));
|
__asm__ volatile ("mr %0,r1" : "=r" (sp));
|
||||||
#else
|
#else
|
||||||
__asm__ volatile("mr %0,1" : "=r"(sp));
|
__asm__ volatile ("mr %0,1" : "=r" (sp));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On PowerPC, the "Link Register" or "Link Record" (LR), is a stack
|
// On PowerPC, the "Link Register" or "Link Record" (LR), is a stack
|
||||||
@ -112,18 +108,17 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
|
|||||||
// linux ppc64), it's in sp[2]. For SYSV (used by linux ppc),
|
// linux ppc64), it's in sp[2]. For SYSV (used by linux ppc),
|
||||||
// it's in sp[1].
|
// it's in sp[1].
|
||||||
#if defined(_CALL_AIX) || defined(_CALL_DARWIN)
|
#if defined(_CALL_AIX) || defined(_CALL_DARWIN)
|
||||||
result[n++] = *(sp + 2);
|
result[n++] = *(sp+2);
|
||||||
#elif defined(_CALL_SYSV)
|
#elif defined(_CALL_SYSV)
|
||||||
result[n++] = *(sp + 1);
|
result[n++] = *(sp+1);
|
||||||
#elif defined(__APPLE__) || \
|
#elif defined(__APPLE__) || ((defined(__linux) || defined(__linux__)) && defined(__PPC64__))
|
||||||
((defined(__linux) || defined(__linux__)) && defined(__PPC64__))
|
|
||||||
// This check is in case the compiler doesn't define _CALL_AIX/etc.
|
// This check is in case the compiler doesn't define _CALL_AIX/etc.
|
||||||
result[n++] = *(sp + 2);
|
result[n++] = *(sp+2);
|
||||||
#elif defined(__linux) || defined(__OpenBSD__)
|
#elif defined(__linux) || defined(__OpenBSD__)
|
||||||
// This check is in case the compiler doesn't define _CALL_SYSV.
|
// This check is in case the compiler doesn't define _CALL_SYSV.
|
||||||
result[n++] = *(sp + 1);
|
result[n++] = *(sp+1);
|
||||||
#else
|
#else
|
||||||
# error Need to specify the PPC ABI for your architecture.
|
#error Need to specify the PPC ABI for your archiecture.
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// Use strict unwinding rules.
|
// Use strict unwinding rules.
|
||||||
@ -132,5 +127,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace glog_internal_namespace_
|
_END_GOOGLE_NAMESPACE_
|
||||||
} // namespace google
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user