Code Monkey home page Code Monkey logo

glog's Introduction

Google Logging Library

Linux Github actions Windows Github actions macOS Github actions Codecov

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.

Getting Started

You can log a message by simply streaming things to LOG(<a particular severity level>), e.g.,

#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";
}

The library can be installed using various package managers or compiled from source. For a detailed overview of glog features and their usage, please refer to the user guide.

The above example requires further Bazel or CMake setup for use in own projects.

Table of Contents

Usage in Projects

Assuming that glog was previously built using CMake or installed using a package manager, you can use the CMake command find_package to build against glog in your CMake project as follows:

cmake_minimum_required (VERSION 3.16)
project (myproj VERSION 1.0)

find_package (glog 0.7.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 add_subdirectory to include glog directly from a subdirectory of your project by replacing the find_package call from the previous snippet by add_subdirectory. The glog::glog target is in this case an ALIAS library target for the glog library target.

Building from Source

Bazel

To use glog within a project which uses the Bazel build tool, add the following lines to your WORKSPACE file:

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 = "122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022",
    strip_prefix = "glog-0.6.0",
    urls = ["https://github.com/google/glog/archive/v0.6.0.zip"],
)

You can then add @com_github_google_glog//:glog to the deps section of a cc_binary or cc_library rule, and #include <glog/logging.h> to include it in your source code. Here’s a simple example:

cc_binary(
    name = "main",
    srcs = ["main.cc"],
    deps = ["@com_github_google_glog//:glog"],
)

CMake

glog can be compiled using CMake 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.
git clone https://github.com/google/glog.git
cd glog
  1. Run CMake to configure the build tree.
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 cmake . -G <generator-name>, and see 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.

  1. Afterwards, generated files can be used to compile the project.
cmake --build build
  1. Test the build software (optional).
cmake --build build --target test
  1. Install the built files (optional).
cmake --build build --target install

Once successfully built, glog can be integrated into own projects.

conan

You can download and install glog using the conan package manager:

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 repository.

vcpkg

You can download and install glog using the vcpkg dependency manager:

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 directory.

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

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 (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 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 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:

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

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.

Customizing the Log Line Prefix

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.

For example, 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 nullptr.

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() << "]";
}

To enable the use of a prefix formatter, use the

google::InstallPrefixFormatter(&MyPrefixFormatter);

function to pass a pointer to the corresponding MyPrefixFormatter callback during initialization. InstallPrefixFormatter takes a second optional argument of type void* that allows supplying user data to the callback.

Setting Flags

Several flags influence glog’s output behavior. If the Google gflags library 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 activate --logtostderr, you can start your application with the following command line:

./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.,

GLOG_logtostderr=1 ./your_application

The following flags are most commonly used:

logtostderr (bool, default=false)

Log messages to stderr instead of logfiles.

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.

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 --vmodule. Refer to 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 for more details.

Additional flags are defined in flags.cc. Please see the source for their complete list.

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 google::InitGoogleLogging . Here is an example:

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:

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.

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.

The placeholder google::COUNTER identifies the recurring repetition.

You can combine conditional and occasional logging with the following macro.

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:

LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";

Outputs log messages for the first 20 times it is executed. The 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:

LOG_EVERY_T(INFO, 0.01) << "Got a cookie";

Or every 2.35s:

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.

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

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:

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 operator<<(ostream, ...) defined.

You may append to the error message like so:

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:

CHECK_EQ(string("abc")[1], ’b’);

The compiler reports an error if one of the arguments is a pointer and the other is nullptr. To work around this, simply static_cast nullptr to the type of the desired pointer.

CHECK_EQ(some_ptr, static_cast<SomeType*>(nullptr));

Better yet, use the CHECK_NOTNULL macro:

CHECK_NOTNULL(some_ptr);
some_ptr->DoSomething();

Since this macro returns the given pointer, this is very useful in constructor initializer lists.

struct S {
    S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
    Something* ptr_;
};

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 (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 nullptr pointers to this macro. They treat nullptr and any non-nullptr string as not equal. Two nullptrs are equal.

Both arguments may be temporary objects which are destructed at the end of the current "full expression", such as

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.

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 --v command line option controls which verbose messages are logged:

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 --v==1, VLOG(1) will log, but VLOG(2) will not log.

The VLOG behavior is opposite of the severity level logging, where INFO, ERROR, etc. are defined in increasing order and thus --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 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:

--vmodule=mapreduce=2,file=1,gfs*=3 --v=0

Specifying these options will specficially:

  1. Print VLOG(2) and lower messages from mapreduce.{h,cc}
  2. Print VLOG(1) and lower messages from file.{h,cc}
  3. Print VLOG(3) and lower messages from files prefixed with "gfs"
  4. Print 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 for more information.

There’s also VLOG_IS_ON(n) "verbose level" condition macro. This macro returns true when the --v is equal to or greater than n. The macro can be used as follows:

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, LOG_IF_EVERY_N, but accept a numeric verbosity level as opposed to a severity level.

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;

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 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 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.

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 InstallFailureFunction.

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 std::abort. The stacktrace is generated only when running the application on a system supported by glog. Currently, glog supports x86, x86_64, PowerPC architectures, libunwind, and the Debug Help Library (dbghelp) on Windows for extracting the stack trace.

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 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.

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.

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:

#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 VLOGs as well as INFO log statements.

Automatically Remove Old Logs

To enable the log cleaner:

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:

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)

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:

#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 .

#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 #include <windows.h>.
  • #undef ERROR after #include <windows.h>.

See this issue 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 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 InstallFailureSignalHandler(), we strongly recommend you install libunwind before trying to configure or install google glog. libunwind can be found here.

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 -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.

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.

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.
  • If you work for a company that wants to allow you to contribute your work, then you’ll need to sign a corporate CLA.

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 and CONTRIBUTORS files. This commit can be part of your first 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 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 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.

glog's People

Contributors

aesophor avatar andyleejordan avatar anpol avatar artemdinaburg avatar bsilver8192 avatar dariuszostolski avatar dependabot[bot] avatar drigz avatar durswd avatar ffontaine avatar hlsyounes avatar huangqinjin avatar jray272 avatar kon72 avatar mai93 avatar meteorcloudy avatar mizux avatar neroburner avatar pcc avatar philwo avatar pwnall avatar qzmfranklin avatar romange avatar sergeyvfx avatar sergiud avatar shinh avatar skeptic-monkey avatar ukai avatar yoshisatoyanagisawa avatar zhenhuaw-me avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glog's Issues

ppc64le support for glog

Glog is used in various projects those are used by projects that run on IBM power machine. Mesos is one example of such type of machine. As patching glog for power everytime whenever we update glog included in mesos is quite cumbersome. So, bringing power support on upstreamed glog is very necessary. I almost have my patch ready to contribute to glog for this.

Bazel Build

It would be really nice if you could add support for building with Bazel.

make error

I am getting the following error, while running make:

/usr/bin/ld: /usr/local//lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

How to fix it?

"make install" failure

environment:
uname -a
Linux localhost.localdomain 3.10.0-229.11.1.el7.x86_64 #1 SMP Thu Aug 6 01:06:18 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

make && make install
src/demangle.h:80:27: error: expected initializer before 'Demangle'
bool GOOGLE_GLOG_DLL_DECL Demangle(const char *mangled, char *out, int out_size);

^
make: *** [src/libglog_la-demangle.lo] Error 1

Add support for deleting old logs

Hi,
Can we add a support for deleting old logs?
As of now, log just keeps accumulating until it takes entire disk space.
If we set the max log size to 10MB, glog keeps generating 10MB log files never deleting.
I'd like to keep only latest 4 logs (of 10MB or smaller).

I know there are tools which can be run to do the cleanup such as logrotate.
We make Windows DLL which runs on embedded machine made by another company. We don't have control on this embedded machine, so we cannot run any program to rotate the log.

I've added RotateLogFile function which checks for number of log files and deletes old logs.
RotateLogFile is run in LogFileObject::Write as it log is rolled over and new log file is created (when max_log_size is reached).

so if we have following 4 logs,

log_20150617-141944.8600
log_20150618-166949.8600
log_20150619-119953.8600
log_20150620-107957.8600

And if a new one is created, the oldest one is deleted leaving 4 logs
log_20150617-141944.8600 <-Deleted
log_20150618-163949.8600
log_20150619-112953.8600
log_20150620-101957.8600
log_20150621-103957.8600 <-- Created

Has this feature been considered before? Can you add this?

Thanks,

Isao

cmake linking error against pthread

This linking error happens on some platforms (e.g., Ubuntu 14.04 LTS, and RHEL Server 6.7), but both Mac OS X 10.11.1 and CentOS 7 works.

The main reason for such linking error is that CMakeLists.txt missed the link statement target_link_libraries(some_unittest ${CMAKE_THREAD_LIBS_INIT}), and I'll submit a pull request for this later.

But I don't know why some platforms fails; see the error logs below. I have checked $LD_LIBRARY_PATH, though.

On Ubuntu 14.04 LTS, logging_unittest linking fails.

CMakeFiles/logging_unittest.dir/src/logging_unittest.cc.o: In function `google::Thread::Start()':
logging_unittest.cc:(.text._ZN6google6Thread5StartEv[_ZN6google6Thread5StartEv]+0x26): undefined reference to `pthread_create'
CMakeFiles/logging_unittest.dir/src/logging_unittest.cc.o: In function `google::Thread::Join()':
logging_unittest.cc:(.text._ZN6google6Thread4JoinEv[_ZN6google6Thread4JoinEv]+0x1d): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[2]: *** [logging_unittest] Error 1
make[1]: *** [CMakeFiles/logging_unittest.dir/all] Error 2
make: *** [all] Error 2

On RHEL Server 6.7, two unit tests (signalhandler_unittest and logging_unittest) have linking issues, but the rest 5 unit tests works.

[ 72%] Linking CXX executable signalhandler_unittest
[ 77%] Linking CXX executable stacktrace_unittest
CMakeFiles/signalhandler_unittest.dir/src/signalhandler_unittest.cc.o: In function `main':
signalhandler_unittest.cc:(.text+0x262): undefined reference to `pthread_create'
signalhandler_unittest.cc:(.text+0x273): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make[2]: *** [signalhandler_unittest] Error 1
make[1]: *** [CMakeFiles/signalhandler_unittest.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 77%] Built target stacktrace_unittest
[ 81%] Linking CXX executable demangle_unittest
[ 86%] Linking CXX executable symbolize_unittest
[ 90%] Linking CXX executable utilities_unittest
[ 90%] Built target demangle_unittest
[ 90%] Built target symbolize_unittest
[ 90%] Built target utilities_unittest
[ 95%] Linking CXX executable stl_logging_unittest
[ 95%] Built target stl_logging_unittest
[100%] Linking CXX executable logging_unittest
CMakeFiles/logging_unittest.dir/src/logging_unittest.cc.o: In function `google::Thread::Start()':
logging_unittest.cc:(.text._ZN6google6Thread5StartEv[google::Thread::Start()]+0x2a): undefined reference to `pthread_create'
CMakeFiles/logging_unittest.dir/src/logging_unittest.cc.o: In function `google::Thread::Join()':
logging_unittest.cc:(.text._ZN6google6Thread4JoinEv[google::Thread::Join()]+0x1d): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make[2]: *** [logging_unittest] Error 1
make[1]: *** [CMakeFiles/logging_unittest.dir/all] Error 2
make: *** [all] Error 2

Mark LOG(FATAL) with [[noreturn]]

Example:

int Find(const std::vector<int>& x) {
  // proper code with return statement for all correct input values
  LOG(FATAL) << "x is bad";
}

The above code during compilation shows a warning:

warning: control may reach end of non-void function [-Wreturn-type]

The warning in general is useful, what about marking a subclass responsible for fatal messages with [[noreturn]]?

Sources:
[1] http://stackoverflow.com/questions/12146772/can-i-tell-the-compiler-to-consider-a-control-path-closed-with-regards-to-return
[2] http://en.cppreference.com/w/cpp/language/attributes

glog should use ThreadSanitizer (TSAN) dynamic annotations

Trying to build glog with TSAN ends up causing a bunch of false positives due to probably-benign races. For example, RawLog_SetLastTime operates unprotected on global variables. This is questionable (since 'struct tm' is relatively large) and generates a TSAN warning. Fixing this to use a seqlock, or at least annotating it as benign, would be helpful for those trying to run glog in TSAN builds.

Another example is the thread-unsafe counters for LOG_EVERY_N and similar macros. These need to be annotated as benign.

Logging From Shared Libraries on Windows

I have a cross-platform (Linux & Windows) Qt Application that uses glog for logging (commit: 4d391fe). The project has a main application with several shared libraries that we wrote. On Linux (Ubuntu 14.04) glog works as expected. On Windows (built using mingw-w64 and gcc) any log statement that comes from within a DLL gets written to stdout instead of to the log. Any log statement from within the main application correctly gets written to the log. Furthermore, I see WARNING: Logging before InitGoogleLogging() is written to STDERR in the standard output for each time a log statement is created from a DLL for the first time (i.e. if I have 5 DLLs, I see that warning 5 times immediately prior to the first log statement from each DLL).

It seems like Glog is not being shared across the DLLs. I have tried to call InitGoogleLogging from within each DLL to test this theory, but then I get a run time crash with the following error message in stdout: Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!. So it appears that Glog is not being shared however, I can't initialize it in each DLL.

Full disclosure: I had to tweak port.h in order to get glog to build in mingw-w64 by handling pthreads correctly and not redefining localtime_r, but I don't feel this is related.

 #endif  // _MSC_VER

 // ----------------------------------- THREADS
+#ifndef PTHREAD_ONCE_INIT
 typedef DWORD pthread_t;
 typedef DWORD pthread_key_t;
 typedef LONG pthread_once_t;
 enum { PTHREAD_ONCE_INIT = 0 };   // important that this be 0! for SpinLock
 #define pthread_self  GetCurrentThreadId
 #define pthread_equal(pthread_t_1, pthread_t_2)  ((pthread_t_1)==(pthread_t_2))
+#endif

-inline struct tm* localtime_r(const time_t* timep, struct tm* result) {
-  localtime_s(result, timep);
-  return result;
-}
+//inline struct tm* localtime_r(const time_t* timep, struct tm* result) {
+//  localtime_s(result, timep);
+//  return result;
+//}

module based minloglevel

I am using glog in my project for progress and error logging. But I am flooded by ERROR messages from an included library (ceres solver) that I would like to suppress (I get the info of an error as return value anyways) without suppressing messages of my own modules.

So what I am looking for is something like the minloglevel flag on a per module basis (similar to vmodule, which is designed for VLOG messages only).

AFAIK something like this is not yet possible / implemented.

Crash in visual studio 2013 due to fdopen

LogFileObject::CreateLogfile in logging.cc calls fdopen() to get a FILE* from previously opened fd. This crashes in VS 2013. It can be fixed by using _fdopen()

Patch to fix the issue:
src/logging.cc | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/src/logging.cc b/src/logging.cc
index b7c2f4c..d5a0430 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -88,6 +88,10 @@ using std::perror;
using std::fdopen;
#endif

+#ifdef _WIN32
+#define fdopen _fdopen
+#endif
+
// There is no thread annotation support.
#define EXCLUSIVE_LOCKS_REQUIRED(mu)

signalhandler should avoid calling new/malloc.

I've seen the following problem with 0.3.4. The problem is that FlushLogFilesUnsafe() calls new LogDestination(), which may hang because the signal may have happened inside malloc. The following patch will fix this particular issue, but I notice that the system uses FILE* to write to log files, and FILE* isn't signal safe as far as I can tell.

I haven't reproduced the problem with the head version, but logging.cc hasn't changed since 0.3.4, so I suspect the problem is stil there.

diff --git a/src/logging.cc b/src/logging.cc
index b7c2f4c..982a308 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -572,7 +572,7 @@ inline void LogDestination::FlushLogFilesUnsafe(int min_seve
   // assume we have the log_mutex or we simply don't care
   // about it
   for (int i = min_severity; i < NUM_SEVERITIES; i++) {
-    LogDestination* log = log_destination(i);
+    LogDestination* log = log_destinations_[i];
     if (log != NULL) {
       // Flush the base fileobject_ logger directly instead of going
       // through any wrappers to reduce chance of deadlock.


#0  0x000000000086a783 in sys_futex (t=0x7fffbb6cc9a0, v=2, o=128, 
    a=0x117f538 <heap_checker_lock>) at ./src/base/linux_syscall_support.h:2097
#1  base::internal::SpinLockDelay (w=w@entry=0x117f538 <heap_checker_lock>, 
    value=2, loop=loop@entry=51302) at ./src/base/spinlock_linux-inl.h:88
#2  0x000000000086a66d in SpinLock::SlowLock (
    this=this@entry=0x117f538 <heap_checker_lock>) at src/base/spinlock.cc:133
#3  0x000000000086ccd2 in Lock (this=0x117f538 <heap_checker_lock>)
    at src/base/spinlock.h:71
#4  SpinLockHolder (l=0x117f538 <heap_checker_lock>, this=<synthetic pointer>)
    at src/base/spinlock.h:136
#5  NewHook (ptr=0x3330c60, size=144) at src/heap-checker.cc:578
#6  0x0000000000866709 in MallocHook::InvokeNewHookSlow (p=p@entry=0x3330c60, 
    s=s@entry=144) at src/malloc_hook.cc:514
#7  0x000000000088648b in InvokeNewHook (s=144, p=0x3330c60)
    at src/malloc_hook-inl.h:154
#8  tc_new (size=size@entry=144) at src/tcmalloc.cc:1622
#9  0x0000000000818152 in log_destination (severity=2) at src/logging.cc:771
#10 FlushLogFilesUnsafe (min_severity=min_severity@entry=0)
    at src/logging.cc:534
#11 google::FlushLogFilesUnsafe (min_severity=min_severity@entry=0)
    at src/logging.cc:1578
#12 0x0000000000821a00 in google::(anonymous namespace)::FailureSignalHandler (
    signal_number=4, signal_info=0x7fffbb6ccff0, ucontext=<optimized out>)
    at src/signalhandler.cc:325
#13 <signal handler called>
#14 _dl_x86_64_restore_sse () at ../sysdeps/x86_64/dl-trampoline.S:242

Make error Ubuntu 14.04 LTS

Error on default ./configure && make && make install

g++ -DHAVE_CONFIG_H -I. -I./src -I./src -pthread -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -DNO_FRAME_POINTER -g -O2 -MT src/logging_unittest-logging_unittest.o -MD -MP -MF src/.deps/logging_unittest-logging_unittest.Tpo -c -o src/logging_unittest-logging_unittest.o test -f 'src/logging_unittest.cc' || echo './'src/logging_unittest.cc
src/logging_unittest.cc:64:17: error: ‘GFLAGS_NAMESPACE’ is not a namespace-name
using namespace GFLAGS_NAMESPACE;
^
src/logging_unittest.cc:64:33: error: expected namespace-name before ‘;’ token
using namespace GFLAGS_NAMESPACE;

Link error with ThreadSanitizer

glog 0.3.4 doesn't compile using clang's thread-sanitizer:

$ uname -a
Linux vagrant-ubuntu-vivid-64 3.19.0-26-generic #28-Ubuntu SMP Tue Aug 11 14:16:32 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ ./configure CC=clang CXX=clang++ CFLAGS="-fsanitize=thread" CXXFLAGS="-fsanitize=thread" LDFLAGS=-fsanitize=thread
[...]
$ make
[...]
/bin/bash ./libtool  --tag=CXX   --mode=link clang++      -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare  -DNO_FRAME_POINTER  -fsanitize=thread  -fsanitize=thread -o logging_unittest  src/logging_unittest-logging_unittest.o  libglog.la       -lpthread
libtool: link: clang++ -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -DNO_FRAME_POINTER -fsanitize=thread -fsanitize=thread -o .libs/logging_unittest src/logging_unittest-logging_unittest.o  ./.libs/libglog.so -lpthread
src/logging_unittest-logging_unittest.o: In function `operator delete[](void*)':
src/logging_unittest.cc:(.text+0x370): multiple definition of `operator delete[](void*)'
/usr/lib/llvm-3.6/bin/../lib/clang/3.6.0/lib/linux/libclang_rt.tsan-x86_64.a(tsan_interceptors.o):(.text+0x2870): first defined here
src/logging_unittest-logging_unittest.o: In function `operator delete(void*)':
src/logging_unittest.cc:(.text+0x320): multiple definition of `operator delete(void*)'
/usr/lib/llvm-3.6/bin/../lib/clang/3.6.0/lib/linux/libclang_rt.tsan-x86_64.a(tsan_interceptors.o):(.text+0x26f0): first defined here
src/logging_unittest-logging_unittest.o: In function `operator new[](unsigned long)':
src/logging_unittest.cc:(.text+0x240): multiple definition of `operator new[](unsigned long)'
/usr/lib/llvm-3.6/bin/../lib/clang/3.6.0/lib/linux/libclang_rt.tsan-x86_64.a(tsan_interceptors.o):(.text+0x22a0): first defined here
src/logging_unittest-logging_unittest.o: In function `operator new(unsigned long)':
src/logging_unittest.cc:(.text+0x120): multiple definition of `operator new(unsigned long)'
/usr/lib/llvm-3.6/bin/../lib/clang/3.6.0/lib/linux/libclang_rt.tsan-x86_64.a(tsan_interceptors.o):(.text+0x2130): first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:1079: recipe for target 'logging_unittest' failed
make: *** [logging_unittest] Error 1

i.e., tsan and glog both want to define their own replacements for operator new. Admittedly, this is unfortunate behavior on tsan's part (see https://llvm.org/bugs/show_bug.cgi?id=19660 for griping about asan, which does the same thing).

Since glog only seems to replace operator new for testing purposes, I wonder whether it would be possible to either:

  • Make it so that the unit test code is not compiled as part of a normal build (make building the unit tests a dependency of the "check" target, for example)
  • Provide a configure option or #ifdef to avoid replacing operator new.

demangle_unittest.sh fails with GCC 5 (configured --with-default-libstdcxx-abi=new, which is the default)

./src/demangle_unittest.sh
Mangled symbols (21 out of 796) found in demangle.dm:
_ZN3fLS13FLAGS_log_dirB5cxx11E
_ZN3fLS13FLAGS_vmoduleB5cxx11E
_ZN3fLS14FLAGS_log_linkB5cxx11E
_ZN3fLS15FLAGS_logmailerB5cxx11E
_ZN3fLS20FLAGS_alsologtoemailB5cxx11E
_ZN3fLS22FLAGS_log_backtrace_atB5cxx11E
_ZN3fLS25dont_pass0toDEFINE_stringB5cxx11EPcPKc
_ZN6google12Check_GEImplB5cxx11EiiPKc
_ZN6google12Check_LTImplB5cxx11EiiPKc
_ZN6google14LogDestination10addresses_B5cxx11E
_ZN6google14LogDestination8hostnameB5cxx11Ev
_ZN6google14LogDestination9hostname_B5cxx11E
ZN6google19CheckstrcmptrueImplB5cxx11EPKcS1_S1
ZN6google20CheckstrcmpfalseImplB5cxx11EPKcS1_S1
_ZN6google21GetLoggingDirectoriesB5cxx11Ev
ZN6google23CheckstrcasecmptrueImplB5cxx11EPKcS1_S1
ZN6google24CheckstrcasecmpfalseImplB5cxx11EPKcS1_S1
_ZN6google24glog_internal_namespace_10MyUserNameB5cxx11Ev
_ZN6google4base21CheckOpMessageBuilder9NewStringB5cxx11Ev
_ZN6google7LogSink8ToStringB5cxx11EiPKciPK2tmS2_m
_ZN6google8StrErrorB5cxx11Ei
Mangled symbols (21 out of 796) found in demangle.dm
Makefile:2060: recipe for target 'demangle_unittest_sh' failed
make[3]: *** [demangle_unittest_sh] Error 1
make[3]: Leaving directory '/scratch/packages/tmp/google-glog-0.3.4'
Makefile:1906: recipe for target 'check-am' failed
make[2]: *** [check-am] Error 2

gcc 4.7.2, 4.8.3, 4.9.2 unit test failures on C++11

Hi, I've encountered some issues with the demangle unit tests using glog-0.3.4 on the gcc family of compilers. This is being run on fedora 20, with the compilers as seen in the title, and with C++11.

What follows is the last 30ish lines from the make/make check output.

gcc 4.7.2

./src/logging_striplog_test.sh
In DBG mode; not checking strings
PASS
./demangle_unittest  # force to create lt-demangle_unittest
./src/demangle_unittest.sh
Mangled symbols (14 out of 801) found in demangle.dm:
_ZN9__gnu_cxx13new_allocatorIPN6google7LogSinkEE9constructIS3_JRKS3_EEEvPT_DpOT0_
_ZN9__gnu_cxx13new_allocatorISsE9constructISsJRKSsEEEvPT_DpOT0_
_ZN9__gnu_cxx13new_allocatorISsE9constructISsJSsEEEvPT_DpOT0_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE12_S_constructIS2_JRKS2_EEENSt9enable_ifIXsrNS4_18__construct_helperIT_JDpT0_EEE5valueEvE4typeERS3_PSA_DpOSB_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE9constructIS2_JRKS2_EEEvRS3_PT_DpOT0_
_ZNSt16allocator_traitsISaISsEE12_S_constructISsJRKSsEEENSt9enable_ifIXsrNS1_18__construct_helperIT_JDpT0_EEE5valueEvE4typeERS0_PS7_DpOS8_
_ZNSt16allocator_traitsISaISsEE12_S_constructISsJSsEEENSt9enable_ifIXsrNS1_18__construct_helperIT_JDpT0_EEE5valueEvE4typeERS0_PS5_DpOS6_
_ZNSt16allocator_traitsISaISsEE9constructISsJRKSsEEEvRS0_PT_DpOT0_
_ZNSt16allocator_traitsISaISsEE9constructISsJSsEEEvRS0_PT_DpOT0_
_ZNSt6vectorIPN6google7LogSinkESaIS2_EE19_M_emplace_back_auxIJRKS2_EEEvDpOT_
_ZNSt6vectorISsSaISsEE12emplace_backIJSsEEEvDpOT_
_ZNSt6vectorISsSaISsEE19_M_emplace_back_auxIJRKSsEEEvDpOT_
_ZNSt6vectorISsSaISsEE19_M_emplace_back_auxIJSsEEEvDpOT_
_ZSt10_ConstructISsJSsEEvPT_DpOT0_
Mangled symbols (14 out of 801) found in demangle.dm

gcc 4.8.3

./src/demangle_unittest.sh
Mangled symbols (17 out of 800) found in demangle.dm:
_ZN9__gnu_cxx13new_allocatorIPN6google7LogSinkEE9constructIS3_JRKS3_EEEvPT_DpOT0_
_ZN9__gnu_cxx13new_allocatorISsE9constructISsJRKSsEEEvPT_DpOT0_
_ZN9__gnu_cxx13new_allocatorISsE9constructISsJSsEEEvPT_DpOT0_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE12_S_constructIS2_JRKS2_EEENSt9enable_ifIXsrNS4_18__construct_helperIT_JDpT0_EEE5valueEvE4typeERS3_PSA_DpOSB_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE9constructIS2_IRKS2_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS3_PT_DpOS8_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE9constructIS2_JRKS2_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS3_PT_DpOS8_
_ZNSt16allocator_traitsISaISsEE12_S_constructISsJRKSsEEENSt9enable_ifIXsrNS1_18__construct_helperIT_JDpT0_EEE5valueEvE4typeERS0_PS7_DpOS8_
_ZNSt16allocator_traitsISaISsEE12_S_constructISsJSsEEENSt9enable_ifIXsrNS1_18__construct_helperIT_JDpT0_EEE5valueEvE4typeERS0_PS5_DpOS6_
_ZNSt16allocator_traitsISaISsEE9constructISsIRKSsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS5_
_ZNSt16allocator_traitsISaISsEE9constructISsISsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS3_
_ZNSt16allocator_traitsISaISsEE9constructISsJRKSsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS5_
_ZNSt16allocator_traitsISaISsEE9constructISsJSsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS3_
_ZNSt6vectorIPN6google7LogSinkESaIS2_EE19_M_emplace_back_auxIJRKS2_EEEvDpOT_
_ZNSt6vectorISsSaISsEE12emplace_backIJSsEEEvDpOT_
_ZNSt6vectorISsSaISsEE19_M_emplace_back_auxIJRKSsEEEvDpOT_
_ZNSt6vectorISsSaISsEE19_M_emplace_back_auxIJSsEEEvDpOT_
_ZSt10_ConstructISsJSsEEvPT_DpOT0_
Mangled symbols (17 out of 800) found in demangle.dm

gcc 4.9.2

./src/demangle_unittest.sh
Mangled symbols (20 out of 799) found in demangle.dm:
_ZN9__gnu_cxx13new_allocatorIPN6google7LogSinkEE9constructIS3_JRKS3_EEEvPT_DpOT0_
_ZN9__gnu_cxx13new_allocatorISsE9constructISsJRKSsEEEvPT_DpOT0_
_ZN9__gnu_cxx13new_allocatorISsE9constructISsJSsEEEvPT_DpOT0_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE10_S_destroyIS2_EENSt9enable_ifIXsrSt6__and_IJNS4_16__destroy_helperIT_E4typeEEE5valueEvE4typeERS3_PS9_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE12_S_constructIS2_JRKS2_EEENSt9enable_ifIXsrSt6__and_IJNS4_18__construct_helperIT_JDpT0_EE4typeEEE5valueEvE4typeERS3_PSB_DpOSC_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE9constructIS2_IRKS2_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS3_PT_DpOS8_
_ZNSt16allocator_traitsISaIPN6google7LogSinkEEE9constructIS2_JRKS2_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS3_PT_DpOS8_
_ZNSt16allocator_traitsISaISsEE10_S_destroyISsEENSt9enable_ifIXsrSt6__and_IJNS1_16__destroy_helperIT_E4typeEEE5valueEvE4typeERS0_PS6_
_ZNSt16allocator_traitsISaISsEE12_S_constructISsJRKSsEEENSt9enable_ifIXsrSt6__and_IJNS1_18__construct_helperIT_JDpT0_EE4typeEEE5valueEvE4typeERS0_PS8_DpOS9_
_ZNSt16allocator_traitsISaISsEE12_S_constructISsJSsEEENSt9enable_ifIXsrSt6__and_IJNS1_18__construct_helperIT_JDpT0_EE4typeEEE5valueEvE4typeERS0_PS6_DpOS7_
_ZNSt16allocator_traitsISaISsEE9constructISsIRKSsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS5_
_ZNSt16allocator_traitsISaISsEE9constructISsISsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS3_
_ZNSt16allocator_traitsISaISsEE9constructISsJRKSsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS5_
_ZNSt16allocator_traitsISaISsEE9constructISsJSsEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS0_PT_DpOS3_
_ZNSt6vectorIPN6google7LogSinkESaIS2_EE19_M_emplace_back_auxIJRKS2_EEEvDpOT_
_ZNSt6vectorISsSaISsEE12emplace_backIJSsEEEvDpOT_
_ZNSt6vectorISsSaISsEE19_M_emplace_back_auxIJRKSsEEEvDpOT_
_ZNSt6vectorISsSaISsEE19_M_emplace_back_auxIJSsEEEvDpOT_
_ZSt10_ConstructIPN6google7LogSinkEJS2_EEvPT_DpOT0_
_ZSt10_ConstructISsJSsEEvPT_DpOT0_
Mangled symbols (20 out of 799) found in demangle.dm

configure: Hardcoded `am__api_version='1.14'` breaks build on systems with autoconf 1.15

… which should be fairly common these days, considering 1.15 is from 2014.

I suspect

am__api_version=`aclocal --version|head -n1|grep -oE '[0-9]+.[0-9]+$'`

would fix the issue, but I'm not sure glog wouldn't want to check the version to be "high" enough.

Reason of problem:

the configure script appends the am__api_version to the aclocal executable name, and of course, on a system with aclocal-1.15, there's no aclocal-1.14.

visual studio 2015 error

error C2084: 函数“int snprintf(char *const ,const size_t,const char *const ,...)”已有主体
error C2280: “std::basic_ios<char,std::char_traits>::basic_ios(const std::basic_ios<char,std::char_traits> &)”: 尝试引用已删除的函数

Memory leak detected with valgrind memcheck

got this output running valgrind memcheck:

228 ==9178== 22 bytes in 1 blocks are possibly lost in loss record 69 of 174
229 ==9178== at 0x402A6BC: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
230 ==9178== by 0x43A6FD5: std::string::_Rep::S_create(unsigned int, unsigned int, std::allocator const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.20)
231 ==9178== by 0x4245E45: char* std::string::S_construct<char const*>(char const, char const
, std::allocator const&, std::forward_iterator_tag) (in /usr/lib/i386-linux-gnu/libboost_regex.so.1.55.0)
232 ==9178== by 0x43A95D7: std::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.20)
233 ==9178== by 0x40672D3: dont_pass0toDEFINE_string (gflags.h:533)
234 ==9178== by 0x40672D3: __static_initialization_and_destruction_0 (logging.cc:147)
235 ==9178== by 0x40672D3: _GLOBAL__sub_I_logging.cc (logging.cc:2079)
236 ==9178== by 0x400ED26: call_init.part.0 (dl-init.c:78)
237 ==9178== by 0x400EE13: call_init (dl-init.c:36)
238 ==9178== by 0x400EE13: _dl_init (dl-init.c:126)
239 ==9178== by 0x400104E: ??? (in /lib/i386-linux-gnu/ld-2.19.so)

Android build is broken

I've got next error while trying to build glog for Android (API 19):

/.../glog/src/logging.cc: In member function 'virtual void google::{anonymous}::LogFileObject::Write(bool, time_t, const char*, int)':
/.../glog/src/logging.cc:1118:46: error: 'POSIX_FADV_DONTNEED' was not declared in this scope
         posix_fadvise(fileno(file_), 0, len, POSIX_FADV_DONTNEED);

Compiler options:

/.../android-ndk/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ \
    -DANDROID \
    -DGOOGLE_GLOG_DLL_DECL="" \
    -fexceptions \
    -frtti \
    -Wno-psabi \
    --sysroot=/.../android-ndk/android-ndk-r10e/platforms/android-19/arch-arm \
    -funwind-tables \
    -finline-limit=64 \
    -fsigned-char \
    -no-canonical-prefixes \
    -march=armv7-a \
    -mfloat-abi=softfp \
    -mfpu=neon \
    -fdata-sections \
    -ffunction-sections \
    -Wa,--noexecstack \
    -std=c++11 \
    -marm \
    -fno-omit-frame-pointer \
    -fno-strict-aliasing \
    -O0 \
    -g \
    -DDEBUG \
    -D_DEBUG \
    -fPIC \
    -I/.../glog/src \
    -I/.../glog/_builds/android-ndk-r10e-api-19-armeabi-v7a-neon-Debug \
    -isystem /.../android-ndk/android-ndk-r10e/platforms/android-19/arch-arm/usr/include \
    -isystem /.../android-ndk/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include \
    -isystem /.../android-ndk/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include \
    -isystem /.../android-ndk/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/backward \
    -Wno-unnamed-type-template-args \
    -o CMakeFiles/glog.dir/src/logging.cc.o \
    -c /.../glog/src/logging.cc

make error

```src/logging_unittest.cc' || echo './'`src/logging_unittest.cc
src/logging_unittest.cc: In function ‘int main(int, char*)’:
src/logging_unittest.cc:179: error: ‘ParseCommandLineFlags’ was not declared in this scope
src/logging_unittest.cc: In static member function ‘static void Test_DeathNoAllocNewHook_logging::Run()’:
src/logging_unittest.cc:296: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:296: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In function ‘void TestRawLogging()’:
src/logging_unittest.cc:308: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:308: error: expected ‘;’ before ‘saver’
src/logging_unittest.cc: In function ‘void LogWithLevels(int, int, bool, bool)’:
src/logging_unittest.cc:363: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:363: error: expected ‘;’ before ‘saver’
src/logging_unittest.cc: In static member function ‘static void Test_DeathRawCHECK_logging::Run()’:
src/logging_unittest.cc:436: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:436: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In static member function ‘static void Test_DeathSTREQ_logging::Run()’:
src/logging_unittest.cc:586: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:586: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In static member function ‘static void Test_CheckNOTNULL_Simple::Run()’:
src/logging_unittest.cc:596: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:596: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In static member function ‘static void Test_DeathCheckNN_Simple::Run()’:
src/logging_unittest.cc:607: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:607: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In static member function ‘static void Test_SafeFNMatch_logging::Run()’:
src/logging_unittest.cc:866: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:866: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In static member function ‘static void Test_Strerror_logging::Run()’:
src/logging_unittest.cc:1041: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:1041: error: expected ‘;’ before ‘fs’
src/logging_unittest.cc: In static member function ‘static void Test_UserDefinedClass_logging::Run()’:
src/logging_unittest.cc:1207: error: ‘FlagSaver’ was not declared in this scope
src/logging_unittest.cc:1207: error: expected ‘;’ before ‘fs’
make: *
* [src/logging_unittest-logging_unittest.o] Error 1

please remove generated autotools from the git repo

any developer working on live git and not a release tarball should be able to run autoreconf -fi. keeping the files in the tree causes headaches for people.

case in point: i got the tree and ran configure, and then the system wanted to rebuild autotools for me. after doing so, i'm left with 20 modified files.

also, the test-driver script committed to the repo now is incorrectly a symlink. it should be a real file.

libglog_la-utilities Error on cygwin

src/utilities.cc:268:29: error: 'GetCurrentThreadId' was not declared in this scope
return GetCurrentThreadId();
^
src/utilities.cc:273:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Makefile:1191: recipe for target 'src/libglog_la-utilities.lo' failed
make: *** [src/libglog_la-utilities.lo] Error 1

I am installing glog on cygwin configuration. Not sure what went wrong. Could anyone give a clue/solution?

Thanks,

clang34, 35, 36 fails to pass unit tests with C++03

Hi, I'm getting an error with the signalhandler_unittest with glog 0.3.4 and C++03 with the recent llvm family of compilers.

This is being run on fedora 20, on clang 34, 35, and 36. The following output is from clang35 and 36.

./demangle_unittest  # force to create lt-demangle_unittest
Passed 3 tests

PASS
./src/demangle_unittest.sh
PASS
./signalhandler_unittest  # force to create lt-signalhandler_unittest
OK
./src/signalhandler_unittest.sh
./src/signalhandler_unittest.sh: line 76: 24503 Segmentation fault      GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1
./src/signalhandler_unittest.sh: line 99: 24510 Terminated              $BINARY loop 2> signalhandler.out2
'SIGFPE' should appear in the output
make[1]: *** [signalhandler_unittest_sh] Error 1

The following output is from clang34 on the same system.

./src/signalhandler_unittest.sh
./src/signalhandler_unittest.sh: line 76: 30842 Segmentation fault      GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1
./src/signalhandler_unittest.sh: line 99: 30849 Terminated              $BINARY loop 2> signalhandler.out2
./src/signalhandler_unittest.sh: line 113: 30858 Floating point exception$BINARY die_in_thread 2> signalhandler.out3
./src/signalhandler_unittest.sh: line 124: 30865 Aborted                 $BINARY dump_to_stdout > signalhandler.out4
PASS
make[1]: Leaving directory `/my/dir/here/glog/src/glog-0.3.4'
make  check-TESTS
make[1]: Entering directory `/my/dir/here/glog/src/glog-0.3.4'
make[2]: Entering directory `/my/dir/here/glog/src/glog-0.3.4'
PASS: logging_unittest
PASS: demangle_unittest
PASS: stacktrace_unittest
FAIL: symbolize_unittest
PASS: stl_logging_unittest
PASS: utilities_unittest
make[3]: Entering directory `/my/dir/here/glog/src/glog-0.3.4'
make[3]: Leaving directory `/my/dir/here/glog/src/glog-0.3.4'
============================================================================
Testsuite summary for glog 0.3.4
============================================================================
# TOTAL: 6
# PASS:  5
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See ./test-suite.log
Please report to [email protected]
============================================================================
make[2]: *** [test-suite.log] Error 1

Unfortunately I couldn't find test-suite.log to get any error messages out of it. It didn't appear to be created in any of the subdirs from glog-0.3.4.

Logging in a static function causes segfault

Previously, logging from a static function used to work fine. It would just log to the console because InitGoogleLogging() hadn't been called yet.

Now, logging from a static function causes the program to segfault.

Here's a short test program that demonstrates the problem. The static bool b = f("..."); line triggers the crash. If that line is commented out, the program runs fine.

#include <glog/logging.h>
#include <string>

bool f(const std::string& message)
{
    LOG(INFO) << message;
    return true;
}

// Uncommenting the following line will trigger the crash
//static bool b = f("Logging before main() crashes.");

int main(int argc, char* argv[])
{
    f("Logging after main() but before InitGoogleLogging() is fine.");
    google::InitGoogleLogging(argv[0]);
    f("Logging after InitGoogleLogging() is obviously fine.");

    return 0;
}

Example stack trace from gdb:

#0  0x00007ffff796eae0 in std::string::empty() const () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x0000000000408366 in google::LogMessage::Init (this=0x7fffffffd458, file=0x42d484 "static_log.cpp", line=6, severity=0, 
    send_method=(void (google::LogMessage::*)(google::LogMessage * const)) 0x4087f0 <google::LogMessage::SendToLog()>)
    at /home/godbyk/git/glog/src/logging.cc:1251
#2  0x0000000000407b79 in google::LogMessage::LogMessage (this=0x7fffffffd458, file=0x42d484 "static_log.cpp", line=6)
    at /home/godbyk/git/glog/src/logging.cc:1160
#3  0x0000000000405925 in f (message="Logging before main() crashes.") at static_log.cpp:6
#4  0x000000000040516f in __cxx_global_var_init () at static_log.cpp:11
#5  0x00000000004051fe in _GLOBAL__sub_I_static_log.cpp ()
#6  0x000000000042d3ed in __libc_csu_init ()
#7  0x00007ffff6fe49cf in __libc_start_main (main=0x4059a0 <main(int, char**)>, argc=1, argv=0x7fffffffd5e8, 
    init=0x42d3a0 <__libc_csu_init>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd5d8) at libc-start.c:245
#8  0x00000000004057d9 in _start ()

Mingw32 5.2.0-3 and winpthreads 5.0 compilation errors on Windows

Compilation fails due to src/windows/port.h redefinition of

typedef DWORD pthread_t;
C:/msys64/mingw32/i686-w64-mingw32/include/pthread.h:196:19: note: previous declaration as 'typedef uintptr_t pthread_t'

typedef DWORD pthread_key_t;
C:/msys64/mingw32/i686-w64-mingw32/include/pthread.h:182:18: note: previous declaration as 'typedef unsigned int pthread_key_t'

enum { PTHREAD_ONCE_INIT = 0 };   // important that this be 0! for SpinLock
error: expected identifier before numeric constant C:/msys64/mingw32/include/c++/5.2.0/i686-w64-mingw32/bits/gthr-default.h:35:0
also defined in C:/msys64/mingw32/i686-w64-mingw32/include/pthread.h:134

src/windows/port.h:147:19: error: redefinition of 'tm* localtime_r(const time_t*, tm*)'
C:/msys64/mingw32/i686-w64-mingw32/include/time.h:269:34: note: 'tm* localtime_r(const time_t*, tm*)' previously defined here

I fixed the enum by checking previous definition of PTHREAD_ONCE_INIT but for the typedef's and localtime_r I commented them out for now in order to proceed with the compilation.

Add CMake support for glog

Hi

would it be possible to add cmake support for Glog ? Gflags already support cmake, it would be consistent to have glog supporting it also.
It seems that there have been attempts to do that in the past.

Thanks you very much in advance

Asynchronous/double-buffering support?

This has come up a few times in the past, but figured I'd re-raise it after the transition from google code to github:

I'm seeing a case in my application where doing LOG() calls from an event loop thread is causing the entire event loop to stall for hundreds of milliseconds. Eventually I captured stacks showing that it's blocking trying to acquire log_mutex while another thread is in the middle of a disk flush. The disk flush can be very slow in the case that the logging disk is in the middle of an ext4 checkpoint (the buffered IO calls file_update_time to update the inode mtime, but the inode is locked for writeback)

A partial solution here would be to add double-buffering within the glog process (instead of relying on fwrite/fflush buffering). Writes would be appended into a buffer, and at "flush" time, we swap the buffer and do a non-buffered write of the old buffer to the file, while not holding the lock. Meanwhile other threads can continue to append to the new buffer without blocking.

A fuller solution would involve deferring the actual logging work to a background thread (eg by a MPSC queue). Either a bounded implementation (which drops messages or blocks when the queue is full) or an unbounded one (which uses a lot of RAM if you can't keep up) could be reasonable choices depending on the workload.

Does anyone have a fork of glog that does this? Would the glog maintainers be willing to accept a pull request if we decided to implement it ourselves?

[OS_WINDOWS] logging_unittest.cc

Compiling glog on Windows (using mingw64), i got the following error:

glog\src\logging_unittest.cc:631:7: error: cast from 'HANDLE {aka void*}' to 'HRESULT {aka long int}' loses precision [-fpermissive]
   if (FAILED(handle)) {
       ^

This error can be solved this way:

Replace:
if (FAILED(handle)) {
by
if (INVALID_HANDLE_VALUE == handle) {

Regards,
Philippe.

Calling glog module bugs before entering main function

Hi, thank you for your great product, glog. This time, I've found an abnormal bug in glog.

glog code can be called before entring main function on condition that

  1. There is a class that contains a constructor, and in this constructor, glog module is called.
  2. There is a global object of the class.

In this case, an application terminates unexpectedly when executed. Here is a sample code(based on glog v0.3.3).
https://gist.github.com/snoopspy/642195da3f91cca811bc

Thank you in advance.

./configure && make && make install fails with error: expected initializer before 'Demangle'

The error is below. I see the same problem referenced in #7, though it's not clear to me from the discussion whether this issue is fixed, and the instructions still direct users to use ./configure && make && make install.

libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I./src -I./src -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -DNO_FRAME_POINTER -DNDEBUG -g -O2 -MT src/libglog_la-demangle.lo -MD -MP -MF src/.deps/libglog_la-demangle.Tpo -c src/demangle.cc  -fPIC -DPIC -o src/.libs/libglog_la-demangle.o
In file included from src/demangle.cc:38:0:
src/demangle.h:80:27: error: expected initializer before 'Demangle'
 bool GOOGLE_GLOG_DLL_DECL Demangle(const char *mangled, char *out, int out_size);
                           ^

Issues running cmake on Windows 7 Visual studio 2010

after downloading the file, uncompressing it and running the command: cmake.exe -G "Visual Studio 10 2010 Win64" -DBUILD_SHARED_LIBS:BOOL=OFF

I get the following errors:

-- The C compiler identification is MSVC 16.0.40219.1
-- The CXX compiler identification is MSVC 16.0.40219.1
-- Check for working C compiler using: Visual Studio 10 2010 Win64
-- Check for working C compiler using: Visual Studio 10 2010 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10 2010 Win64
-- Check for working CXX compiler using: Visual Studio 10 2010 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for gflags namespace
-- Looking for gflags namespace - gflags
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
-- Found Threads: TRUE
-- Looking for dlfcn.h
-- Looking for dlfcn.h - not found
-- Looking for execinfo.h
-- Looking for execinfo.h - not found
-- Looking for glob.h
-- Looking for glob.h - not found
-- Looking for inttypes.h
-- Looking for inttypes.h - not found
-- Looking for libunwind.h
-- Looking for libunwind.h - not found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for pwd.h
-- Looking for pwd.h - not found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for strings.h
-- Looking for strings.h - not found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for sys/syscall.h
-- Looking for sys/syscall.h - not found
-- Looking for sys/time.h
-- Looking for sys/time.h - not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sys/utsname.h
-- Looking for sys/utsname.h - not found
-- Looking for syscall.h
-- Looking for syscall.h - not found
-- Looking for syslog.h
-- Looking for syslog.h - not found
-- Looking for ucontext.h
-- Looking for ucontext.h - not found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Looking for unwind.h
-- Looking for unwind.h - not found
-- Looking for C++ include ext/hash_map
-- Looking for C++ include ext/hash_map - not found
-- Looking for C++ include ext/hash_set
-- Looking for C++ include ext/hash_set - not found
-- Looking for C++ include ext/slist
-- Looking for C++ include ext/slist - not found
-- Looking for C++ include tr1/unordered_map
-- Looking for C++ include tr1/unordered_map - not found
-- Looking for C++ include tr1/unordered_set
-- Looking for C++ include tr1/unordered_set - not found
-- Looking for C++ include unordered_map
-- Looking for C++ include unordered_map - found
-- Looking for C++ include unordered_set
-- Looking for C++ include unordered_set - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned int16
-- Check size of unsigned __int16 - done
-- Check size of u_int16_t
-- Check size of u_int16_t - failed
-- Check size of uint16_t
-- Check size of uint16_t - done
-- Looking for dladdr
-- Looking for dladdr - not found
-- Looking for fcntl
-- Looking for fcntl - not found
-- Looking for pread
-- Looking for pread - not found
-- Looking for pwrite
-- Looking for pwrite - not found
-- Looking for sigaction
-- Looking for sigaction - not found
-- Looking for sigaltstack
-- Looking for sigaltstack - not found
-- Performing Test HAVE_NO_DEPRECATED
-- Performing Test HAVE_NO_DEPRECATED - Failed
-- Performing Test HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS
-- Performing Test HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
-- Looking for snprintf
-- Looking for snprintf - not found
-- Looking for get_static_proc_name in unwind
-- Looking for get_static_proc_name in unwind - not found
-- Performing Test HAVE___ATTRIBUTE

-- Performing Test HAVE___ATTRIBUTE__ - Failed
-- Performing Test HAVE___ATTRIBUTE__VISIBILITY_DEFAULT
-- Performing Test HAVE___ATTRIBUTE__VISIBILITY_DEFAULT - Failed
-- Performing Test HAVE___ATTRIBUTE__VISIBILITY_HIDDEN
-- Performing Test HAVE___ATTRIBUTE__VISIBILITY_HIDDEN - Failed
-- Performing Test HAVE___BUILTIN_EXPECT
-- Performing Test HAVE___BUILTIN_EXPECT - Failed
-- Performing Test HAVE___SYNC_VAL_COMPARE_AND_SWAP
-- Performing Test HAVE___SYNC_VAL_COMPARE_AND_SWAP - Failed
-- Performing Test HAVE_RWLOCK
-- Performing Test HAVE_RWLOCK - Failed
-- Performing Test HAVE___DECLSPEC
-- Performing Test HAVE___DECLSPEC - Success
-- Performing Test STL_NO_NAMESPACE
-- Performing Test STL_NO_NAMESPACE - Failed
-- Performing Test STL_STD_NAMESPACE
-- Performing Test STL_STD_NAMESPACE - Success
-- Performing Test HAVE_USING_OPERATOR
-- Performing Test HAVE_USING_OPERATOR - Success
-- Performing Test HAVE_NAMESPACES
-- Performing Test HAVE_NAMESPACES - Success
-- Configuring done
-- Generating done

LogMessage inheritance

Hi,

I'm implementing a class which inherits from LogMessage, modifies some behavior from it and adds some other. The problem is that a lot of important attributes of LogMessage, such as data_, the Init function and the send functions are private and cannot be accessed from the class I'm trying to implement.

Is it possible to change these attributes from private to protected?

Thanks

glog print wchar_t?

I write this code to print wchar_t using glog:

std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) {
    std::mbstate_t state = std::mbstate_t();
    int len = 1 + std::wcsrtombs(nullptr, &wstr, 0, &state);
    std::vector<char> mbstr(len);
    std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state);

    out << &mbstr[0];
    return out;
}

std::ostream& operator<<(std::ostream& out, const std::wstring& str) {
   return operator<<(out, str.c_str());
}

but it does not work, why??

deadlock in SetVLOGLevel

SetVLOGLevel locks vmodule_lock however RAW_VLOG at the end also implicitly locks it via InitVLOG3__. This causes deadlock/segfault.

See #20 to fix it

Make error: failed to link with libgflags.a

/bin/bash ./libtool  --tag=CXX   --mode=link g++    -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare  -DNO_FRAME_POINTER  -DNDEBUG -g -O2    -o libglog.la -rpath /usr/local/lib  src/libglog_la-logging.lo src/libglog_la-raw_logging.lo src/libglog_la-vlog_is_on.lo src/libglog_la-utilities.lo src/libglog_la-demangle.lo src/libglog_la-symbolize.lo src/libglog_la-signalhandler.lo   -lgflags  -lpthread 
libtool: link: g++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.9/crtbeginS.o  src/.libs/libglog_la-logging.o src/.libs/libglog_la-raw_logging.o src/.libs/libglog_la-vlog_is_on.o src/.libs/libglog_la-utilities.o src/.libs/libglog_la-demangle.o src/.libs/libglog_la-symbolize.o src/.libs/libglog_la-signalhandler.o   -lgflags -lpthread -L/usr/lib/gcc/x86_64-linux-gnu/4.9 -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crtn.o  -O2   -Wl,-soname -Wl,libglog.so.0 -o .libs/libglog.so.0.0.0
/usr/bin/ld: //usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libgflags.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:1041: recipe for target 'libglog.la' failed
make: *** [libglog.la] Error 1

note that it searches for the library at

//usr/local/lib/libgflags.a

logs could be dropped/truncated by glogs when injecting too many logs into LOG(INFO) streams, .flush() does works fine.

we use std::ostream &os to refer the LOG(INFO) instead, and inject lot of logs into std::stream &os, then logs will be dropped or stripped,

I think, the internal buffer size of glog could be set, or use flush() method to flush buffer when neccesory. however, when I try to place flush() in the logging path, the dropping still be found..

How to remove the dropping correctly with some API?

thanks a lot.

logbufsecs behavior

Hi,

I see that default value of logbufsecs is 30. What happens if program crashes ? Could the application lose 30 secs worth of logs if application crashes (e.g. through CHECK fail or SIGSEGV) ?

Thanks,
-Rakesh

AddLogSink memory leak

vld output:

---------- Block 1787 at 0x041E07B8: 20 bytes ----------
  Leak Hash: 0x8D2FA109, Count: 1, Total 20 bytes
  Call Stack (TID 5160):
    0x779711E0 (File and line number not available): ntdll.dll!RtlAllocateHeap
    f:\dd\vctools\crt_bld\self_x86\crt\src\new.cpp (59): Image Uploader.exe!operator new + 0x9 bytes
    d:\develop\imageuploader\contrib\source\glog\src\logging.cc (614): Image Uploader.exe!google::LogDestination::AddLogSink + 0x10 bytes
    d:\develop\imageuploader\contrib\source\glog\src\logging.cc (1645): Image Uploader.exe!google::AddLogSink + 0x9 bytes
    d:\develop\imageuploader\source\image uploader.cpp (166): Image Uploader.exe!wWinMain + 0x9 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (263): Image Uploader.exe!__tmainCRTStartup + 0x2C bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (182): Image Uploader.exe!wWinMainCRTStartup
    0x7525919F (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0xE bytes
    0x7798B54F (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x8F bytes
    0x7798B51A (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x5A bytes
  Data:
    00 00 00 00    CD CD CD CD    C0 FF 1D 04    C4 FF 1D 04     ........ ........
    C4 FF 1D 04                                                  ........ ........

the log "%s %v %q..." means what

when I read the k8s code,I always see the log like this:
glog.Warningf("Clear infra container failed for pod %q: %v", format.Pod(pod), delErr)
Somebody knows "%q %v %s ..." means what? and how to use them?

libglog.pc.in should include libunwind as private dep for static linking case

This was reported along with a patch by someone before (+CLA):
https://code.google.com/p/google-glog/issues/detail?id=207

I ran into this issue during compilation with errors similar to those reported in the issue:

/local/adp/unwind-compile-error/protobuf-util/vendor/src/glog-build/../glog/src/stacktrace_libunwind-inl.h:65: undefined reference to `_Ux86_64_getcontext'
/local/adp/unwind-compile-error/protobuf-util/vendor/src/glog-build/../glog/src/stacktrace_libunwind-inl.h:66: undefined reference to `_ULx86_64_init_local'
/local/adp/unwind-compile-error/protobuf-util/vendor/src/glog-build/../glog/src/stacktrace_libunwind-inl.h:78: undefined reference to `_ULx86_64_step'
/local/adp/unwind-compile-error/protobuf-util/vendor/src/glog-build/../glog/src/stacktrace_libunwind-inl.h:70: undefined reference to `_ULx86_64_get_reg'

Applying the patch worked for me. Please fix.

FATAL error with pthread_cancel in multi-thread program

while the main thread send cancel signal with pthread_cancel(child_pid), and the child thread set cancel state enable with pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); the program will aborted abnormally with core dumped.
glog version is glog-0.3.3

SOURCE CODE:


#include <glog/logging.h>
#include <glog/raw_logging.h>
#include <pthread.h>
using namespace std;

void * child(void*a);

int main(int argc, char**argv) {
    google::InitGoogleLogging(argv[0]);
    FLAGS_colorlogtostderr = true;
    FLAGS_log_dir = "glogpath";
   // FLAGS_stderrthreshold = google::FATAL;
   // FLAGS_logbufsecs = 0;
   // FLAGS_max_log_size = 100;
   // FLAGS_stop_logging_if_full_disk = true;
    google::SetStderrLogging(google::GLOG_INFO); 
    google::InstallFailureSignalHandler();

    //google::InstallFailureWriter(&GlogSignalHandle);

    // initialize the logger before it can receive LOG calls
    pthread_t pid;
    int error = pthread_create( &pid, NULL, child, NULL );
    if (error != 0 ) 
    {
        printf("failed to create thread: %d: %s\n", error, strerror(error));
        return 0;
    }


    //sleep(1);
   // printf("main pid:[%d] cancel send statue:[%d]\n", getpid(), pthread_cancel(pid));
   // cout << "main pthreadid: [" << pthread_self() << "] child pthreadid: [" << pid << "]" << endl;
//    cout << "main pid:[" << getpid() << "] cancel send statue: [" <<  pthread_cancel(pid) << "]" << endl;
    for(auto i =0; i < 300; i++)
    {
        if(290 == i)  
        {
    //        pthread_cancel(pid);
          //  sleep(1);
       printf("main pid:[%d] cancel send statue:[%d]\n", getpid(), pthread_cancel(pid));
        sleep(1);
        }
        LOG(INFO) << "["<< i << "]" << "gmain log LOG INFO";
    //  cout << "["<< i << "]" << "gmain log INFO" << endl;
           printf("[%d] gmain printf log\n", i);
   //   RAW_LOG(INFO, "[%d] gmain log INFO", i);
   //     LOG(WARNING) << "["<< i << "]" << "gmain log WARNING";
   //  RAW_LOG(WARNING, "[%d] gmain log WARNING", i);
   //   LOG(DEBUG) << "["<< i << "]" << "gmain log DEBUG";
   //   LOG(FATAL) << "["<< i << "]" << "gmain log FATAL";
   //     LOG(ERROR) << "["<< i << "]" <<"gmain log ERROR";
   //  RAW_LOG(ERROR, "[%d] gmain log ERROR", i);
    }

    void* res;
    pthread_join(pid, &res);

    google::ShutdownGoogleLogging();
}

void* child(void *a)
{
    int oldstate = 0;
    int oldtype = 0;
  //  pthread_detach(pthread_self());
   // pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
   // pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
   // pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
    for(auto i =0; i < 300; i++)
    {
        if( 200 == i )
        {
            pthread_testcancel();
        }
      //pthread_testcancel();
      //cout << "["<< i << "]" << "child log INFO" << endl;
        LOG(INFO) << "["<< i << "]" << "child log LOG INFO";
        printf("[%d] child printf log\n", i);
   //     LOG(WARNING) << "["<< i << "]" << "child log WARNING";
   //     LOG(ERROR) << "["<< i << "]" <<"child log ERROR";
    }
}


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.