Code Monkey home page Code Monkey logo

glog's Issues

Bazel Build

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

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

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)

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> &)”: 尝试引用已删除的函数

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.

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.

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


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

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.

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

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

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.

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

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.

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

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.

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?

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

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

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

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.

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

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?

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;

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

"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

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.

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?

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.

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)

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.

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.

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,

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

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

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

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

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

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

./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);
                           ^

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.