From 858a11d4e3da108d4c64e13ea511a56e93433d8d Mon Sep 17 00:00:00 2001 From: Date: Tue, 15 Jun 2010 06:28:38 +0000 Subject: [PATCH] Add ShutdownGoogleLogging to close syslog. This patch was contributed by DGunchev (thanks!) http://code.google.com/p/google-glog/issues/detail?id=28 git-svn-id: https://google-glog.googlecode.com/svn/trunk@88 eb4d4688-79bd-11dd-afb4-1d65580434c0 --- src/glog/logging.h.in | 3 +++ src/logging_unittest.cc | 2 ++ src/utilities.cc | 11 +++++++++++ src/windows/glog/logging.h | 3 +++ 4 files changed, 19 insertions(+) diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 16ba694..ff23f2e 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -482,6 +482,9 @@ DECLARE_bool(stop_logging_if_full_disk); // specified by argv0 in log outputs. GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0); +// Shutdown google's logging library. +GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging(); + // Install a function which will be called after LOG(FATAL). GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)()); diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index fb058e7..5fc34d4 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -227,6 +227,8 @@ int main(int argc, char **argv) { TestErrno(); TestTruncate(); + ShutdownGoogleLogging(); + fprintf(stdout, "PASS\n"); return 0; } diff --git a/src/utilities.cc b/src/utilities.cc index bd4e4ad..e97d4f2 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -44,6 +44,9 @@ #elif defined(HAVE_SYS_SYSCALL_H) #include // for syscall() #endif +#ifdef HAVE_SYSLOG_H +# include +#endif #include "base/googleinit.h" @@ -316,6 +319,14 @@ void InitGoogleLogging(const char* argv0) { #endif } +void ShutdownGoogleLogging() { + CHECK(IsGoogleLoggingInitialized()) + << "You called ShutdownGoogleLogging() without InitGoogleLogging() first!"; +#ifdef HAVE_SYSLOG_H + closelog(); +#endif +} + _END_GOOGLE_NAMESPACE_ // Make an implementation of stacktrace compiled. diff --git a/src/windows/glog/logging.h b/src/windows/glog/logging.h index a63246d..7a6df74 100755 --- a/src/windows/glog/logging.h +++ b/src/windows/glog/logging.h @@ -486,6 +486,9 @@ namespace google { // specified by argv0 in log outputs. GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0); +// Shutdown google's logging library. +GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging(); + // Install a function which will be called after LOG(FATAL). GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)()); -- 2.7.4