Compare commits
3 Commits
revert-115
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f007d9621 | ||
|
|
7fcf58afa6 | ||
|
|
ca390c4718 |
21
README.rst
21
README.rst
@ -1,18 +1,23 @@
|
|||||||
Google Logging Library
|
Google Logging Library
|
||||||
======================
|
======================
|
||||||
|
|
||||||
**Deprecation notice**: This project is no longer maintained and will be archived on 2025-06-31.
|
|Linux Github actions| |Windows Github actions| |macOS Github actions| |Codecov|
|
||||||
Consider using
|
|
||||||
`ng-log <https://github.com/ng-log/ng-log>`_ (API-compatible,
|
|
||||||
community-maintained) or
|
|
||||||
`Abseil Logging <https://abseil.io/docs/cpp/guides/logging>`_
|
|
||||||
(Google-maintained) instead. Thank you for all the contributions!
|
|
||||||
|
|
||||||
Google Logging (glog) was a C++14 library that implements application-level
|
Google Logging (glog) is a C++14 library that implements application-level
|
||||||
logging. The library provided 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.
|
||||||
|
|
||||||
Getting Started
|
Getting Started
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Please refer to project's `documentation <https://google.github.io/glog/>`_.
|
Please refer to project's `documentation <https://google.github.io/glog/>`_.
|
||||||
|
|
||||||
|
|
||||||
|
.. |Linux Github actions| image:: https://github.com/google/glog/actions/workflows/linux.yml/badge.svg
|
||||||
|
:target: https://github.com/google/glog/actions
|
||||||
|
.. |Windows Github actions| image:: https://github.com/google/glog/actions/workflows/windows.yml/badge.svg
|
||||||
|
:target: https://github.com/google/glog/actions
|
||||||
|
.. |macOS Github actions| image:: https://github.com/google/glog/actions/workflows/macos.yml/badge.svg
|
||||||
|
:target: https://github.com/google/glog/actions
|
||||||
|
.. |Codecov| image:: https://codecov.io/gh/google/glog/branch/master/graph/badge.svg?token=8an420vNju
|
||||||
|
:target: https://codecov.io/gh/google/glog
|
||||||
|
|||||||
@ -995,7 +995,22 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) {
|
|||||||
if (FLAGS_timestamp_in_logfile_name) {
|
if (FLAGS_timestamp_in_logfile_name) {
|
||||||
// demand that the file is unique for our timestamp (fail if it exists).
|
// demand that the file is unique for our timestamp (fail if it exists).
|
||||||
flags = flags | O_EXCL;
|
flags = flags | O_EXCL;
|
||||||
|
} else {
|
||||||
|
// logs are written to a single file, where: a log file is created for the
|
||||||
|
// the first time or a file is being recreated due to exceeding max size
|
||||||
|
|
||||||
|
struct stat statbuf;
|
||||||
|
if (stat(filename, &statbuf) == 0) {
|
||||||
|
// truncate the file if it exceeds the max size
|
||||||
|
if ((static_cast<uint32>(statbuf.st_size) >> 20U) >= MaxLogSize()) {
|
||||||
|
flags |= O_TRUNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update file length to sync file size
|
||||||
|
file_length_ = static_cast<uint32>(statbuf.st_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor fd{
|
FileDescriptor fd{
|
||||||
open(filename, flags, static_cast<mode_t>(FLAGS_logfile_mode))};
|
open(filename, flags, static_cast<mode_t>(FLAGS_logfile_mode))};
|
||||||
if (!fd) return false;
|
if (!fd) return false;
|
||||||
|
|||||||
@ -110,6 +110,7 @@ static void TestLogSinkWaitTillSent();
|
|||||||
static void TestCHECK();
|
static void TestCHECK();
|
||||||
static void TestDCHECK();
|
static void TestDCHECK();
|
||||||
static void TestSTREQ();
|
static void TestSTREQ();
|
||||||
|
static void TestMaxLogSizeWhenNoTimestamp();
|
||||||
static void TestBasename();
|
static void TestBasename();
|
||||||
static void TestBasenameAppendWhenNoTimestamp();
|
static void TestBasenameAppendWhenNoTimestamp();
|
||||||
static void TestTwoProcessesWrite();
|
static void TestTwoProcessesWrite();
|
||||||
@ -288,6 +289,7 @@ int main(int argc, char** argv) {
|
|||||||
MungeAndDiffTestStdout(FLAGS_test_srcdir + "/src/logging_unittest.out"));
|
MungeAndDiffTestStdout(FLAGS_test_srcdir + "/src/logging_unittest.out"));
|
||||||
FLAGS_logtostdout = false;
|
FLAGS_logtostdout = false;
|
||||||
|
|
||||||
|
TestMaxLogSizeWhenNoTimestamp();
|
||||||
TestBasename();
|
TestBasename();
|
||||||
TestBasenameAppendWhenNoTimestamp();
|
TestBasenameAppendWhenNoTimestamp();
|
||||||
TestTwoProcessesWrite();
|
TestTwoProcessesWrite();
|
||||||
@ -806,6 +808,47 @@ static void CheckFile(const string& name, const string& expected_string,
|
|||||||
<< expected_string << " in " << files[0];
|
<< expected_string << " in " << files[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void TestMaxLogSizeWhenNoTimestamp() {
|
||||||
|
fprintf(stderr, "==== Test setting max log size without timestamp\n");
|
||||||
|
const string dest = FLAGS_test_tmpdir + "/logging_test_max_log_size";
|
||||||
|
DeleteFiles(dest + "*");
|
||||||
|
|
||||||
|
auto original_max_log_size = FLAGS_max_log_size;
|
||||||
|
auto original_timestamp_in_logfile_name = FLAGS_timestamp_in_logfile_name;
|
||||||
|
|
||||||
|
FLAGS_max_log_size = 1; // Set max log size to 1MB
|
||||||
|
FLAGS_timestamp_in_logfile_name = false;
|
||||||
|
|
||||||
|
// Set log destination
|
||||||
|
SetLogDestination(GLOG_INFO, dest.c_str());
|
||||||
|
|
||||||
|
// 1e4 info logs -> is about 772 KB in size
|
||||||
|
// 2e4 info logs -> is around 1500 KB in size -> 1.5MB
|
||||||
|
// If our max_log_size constraint is respected, it will truncate earlier logs
|
||||||
|
// and the file size will be lesser than 1MB (around 0.5MB)
|
||||||
|
const int num_logs = 2e4;
|
||||||
|
for (int i = 0; i < num_logs; i++) {
|
||||||
|
LOG(INFO) << "Hello world";
|
||||||
|
}
|
||||||
|
FlushLogFiles(GLOG_INFO);
|
||||||
|
|
||||||
|
// Check log file size
|
||||||
|
struct stat statbuf;
|
||||||
|
stat(dest.c_str(), &statbuf);
|
||||||
|
|
||||||
|
// Verify file size is less than the max log size limit
|
||||||
|
CHECK_LT(static_cast<unsigned int>(statbuf.st_size),
|
||||||
|
FLAGS_max_log_size << 20U);
|
||||||
|
|
||||||
|
// Reset flag values to their original values
|
||||||
|
FLAGS_max_log_size = original_max_log_size;
|
||||||
|
FLAGS_timestamp_in_logfile_name = original_timestamp_in_logfile_name;
|
||||||
|
|
||||||
|
// Release file handle for the destination file to unlock the file in Windows.
|
||||||
|
LogToStderr();
|
||||||
|
DeleteFiles(dest + "*");
|
||||||
|
}
|
||||||
|
|
||||||
static void TestBasename() {
|
static void TestBasename() {
|
||||||
fprintf(stderr, "==== Test setting log file basename\n");
|
fprintf(stderr, "==== Test setting log file basename\n");
|
||||||
const string dest = FLAGS_test_tmpdir + "/logging_test_basename";
|
const string dest = FLAGS_test_tmpdir + "/logging_test_basename";
|
||||||
|
|||||||
@ -55,6 +55,10 @@
|
|||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_SYS_TYPES_H)
|
||||||
|
# include <sys/syscall.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace google {
|
namespace google {
|
||||||
|
|
||||||
@ -216,8 +220,14 @@ void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
|
|||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << std::showbase << std::hex << std::this_thread::get_id();
|
oss << std::showbase << std::hex << std::this_thread::get_id();
|
||||||
formatter.AppendString(oss.str().c_str());
|
formatter.AppendString(oss.str().c_str());
|
||||||
|
# if defined(GLOG_OS_LINUX) && defined(HAVE_SYS_SYSCALL_H) && \
|
||||||
|
defined(HAVE_SYS_TYPES_H)
|
||||||
|
pid_t tid = syscall(SYS_gettid);
|
||||||
|
formatter.AppendString(" LWP ");
|
||||||
|
formatter.AppendUint64(static_cast<uint64>(tid), 10);
|
||||||
|
# endif
|
||||||
formatter.AppendString(") ");
|
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 ");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user