Use GLOG_* environment variables even when gflags is installed.
Define GLOG_DEFINE_*, which checks if the GLOG_* environment variable is defined. If defined, GLOG_DEFINE_* passes the value and otherwise, it passes the original default value. In this way, GLOG_DEFINE_* macro uses the value specified by gflags first, then GLOG_* environment variables, and finally it uses the default value if neither of them are specified. git-svn-id: https://google-glog.googlecode.com/svn/trunk@76 eb4d4688-79bd-11dd-afb4-1d65580434c0
This commit is contained in:
parent
327359662c
commit
cb35010215
@ -116,6 +116,13 @@ environment variables, prefixing the flag name with "GLOG_", e.g.
|
||||
GLOG_logtostderr=1 ./your_application
|
||||
</pre>
|
||||
|
||||
<!-- TODO(hamaji): Fill the version number
|
||||
<p>By glog version 0.x.x, you can use GLOG_* environment variables
|
||||
even if you have gflags. If both an environment variable and a flag
|
||||
are specified, the value specified by a flag wins. E.g., if GLOG_v=0
|
||||
and --v=1, the verbosity will be 1, not 0.
|
||||
-->
|
||||
|
||||
<p>The following flags are most commonly used:
|
||||
|
||||
<dl>
|
||||
|
||||
@ -77,14 +77,13 @@
|
||||
#define DECLARE_bool(name) \
|
||||
DECLARE_VARIABLE(bool, name, bool)
|
||||
#define DEFINE_bool(name, value, meaning) \
|
||||
DEFINE_VARIABLE(bool, name, EnvToBool("GLOG_" #name, value), meaning, bool)
|
||||
DEFINE_VARIABLE(bool, name, value, meaning, bool)
|
||||
|
||||
// int32 specialization
|
||||
#define DECLARE_int32(name) \
|
||||
DECLARE_VARIABLE(GOOGLE_NAMESPACE::int32, name, int32)
|
||||
#define DEFINE_int32(name, value, meaning) \
|
||||
DEFINE_VARIABLE(GOOGLE_NAMESPACE::int32, name, \
|
||||
EnvToInt("GLOG_" #name, value), meaning, int32)
|
||||
DEFINE_VARIABLE(GOOGLE_NAMESPACE::int32, name, value, meaning, int32)
|
||||
|
||||
// Special case for string, because we have to specify the namespace
|
||||
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
|
||||
@ -93,14 +92,31 @@
|
||||
extern GOOGLE_GLOG_DLL_DECL std::string FLAGS_##name; \
|
||||
} \
|
||||
using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name
|
||||
#define DEFINE_string(name, value, meaning) \
|
||||
#define DEFINE_string(name, value, meaning) \
|
||||
namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \
|
||||
GOOGLE_GLOG_DLL_DECL std::string \
|
||||
FLAGS_##name(EnvToString("GLOG_" #name, value)); \
|
||||
GOOGLE_GLOG_DLL_DECL std::string FLAGS_##name(value); \
|
||||
char FLAGS_no##name; \
|
||||
} \
|
||||
using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name
|
||||
|
||||
#endif // HAVE_LIB_GFLAGS
|
||||
|
||||
// Define GLOG_DEFINE_* using DEFINE_* . By using these macros, we
|
||||
// have GLOG_* environ variables even if we have gflags installed.
|
||||
//
|
||||
// If both an environment variable and a flag are specified, the value
|
||||
// specified by a flag wins. E.g., if GLOG_v=0 and --v=1, the
|
||||
// verbosity will be 1, not 0.
|
||||
|
||||
#define GLOG_DEFINE_bool(name, value, meaning) \
|
||||
DEFINE_bool(name, EnvToBool("GLOG_" #name, value), meaning)
|
||||
|
||||
#define GLOG_DEFINE_int32(name, value, meaning) \
|
||||
DEFINE_int32(name, EnvToInt("GLOG_" #name, value), meaning)
|
||||
|
||||
#define GLOG_DEFINE_string(name, value, meaning) \
|
||||
DEFINE_string(name, EnvToString("GLOG_" #name, value), meaning)
|
||||
|
||||
// These macros (could be functions, but I don't want to bother with a .cc
|
||||
// file), make it easier to initialize flags from the environment.
|
||||
|
||||
@ -113,6 +129,4 @@
|
||||
#define EnvToInt(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : strtol(getenv(envname), NULL, 10))
|
||||
|
||||
#endif // HAVE_LIB_GFLAGS
|
||||
|
||||
#endif // BASE_COMMANDLINEFLAGS_H__
|
||||
|
||||
@ -41,7 +41,8 @@
|
||||
#include "googletest.h"
|
||||
#include "config.h"
|
||||
|
||||
DEFINE_bool(demangle_filter, false, "Run demangle_unittest in filter mode");
|
||||
GLOG_DEFINE_bool(demangle_filter, false,
|
||||
"Run demangle_unittest in filter mode");
|
||||
|
||||
using namespace std;
|
||||
using namespace GOOGLE_NAMESPACE;
|
||||
|
||||
@ -89,15 +89,15 @@ static bool BoolFromEnv(const char *varname, bool defval) {
|
||||
return memchr("tTyY1\0", valstr[0], 6) != NULL;
|
||||
}
|
||||
|
||||
DEFINE_bool(logtostderr, BoolFromEnv("GOOGLE_LOGTOSTDERR", false),
|
||||
"log messages go to stderr instead of logfiles");
|
||||
DEFINE_bool(alsologtostderr, BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false),
|
||||
"log messages go to stderr in addition to logfiles");
|
||||
GLOG_DEFINE_bool(logtostderr, BoolFromEnv("GOOGLE_LOGTOSTDERR", false),
|
||||
"log messages go to stderr instead of logfiles");
|
||||
GLOG_DEFINE_bool(alsologtostderr, BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false),
|
||||
"log messages go to stderr in addition to logfiles");
|
||||
#ifdef OS_LINUX
|
||||
DEFINE_bool(drop_log_memory, true, "Drop in-memory buffers of log contents. "
|
||||
"Logs can grow very quickly and they are rarely read before they "
|
||||
"need to be evicted from memory. Instead, drop them from memory "
|
||||
"as soon as they are flushed to disk.");
|
||||
GLOG_DEFINE_bool(drop_log_memory, true, "Drop in-memory buffers of log contents. "
|
||||
"Logs can grow very quickly and they are rarely read before they "
|
||||
"need to be evicted from memory. Instead, drop them from memory "
|
||||
"as soon as they are flushed to disk.");
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
namespace logging {
|
||||
static const int64 kPageSize = getpagesize();
|
||||
@ -115,25 +115,25 @@ DEFINE_int32(stderrthreshold,
|
||||
"log messages at or above this level are copied to stderr in "
|
||||
"addition to logfiles. This flag obsoletes --alsologtostderr.");
|
||||
|
||||
DEFINE_string(alsologtoemail, "",
|
||||
"log messages go to these email addresses "
|
||||
"in addition to logfiles");
|
||||
DEFINE_bool(log_prefix, true,
|
||||
"Prepend the log prefix to the start of each log line");
|
||||
DEFINE_int32(minloglevel, 0, "Messages logged at a lower level than this don't "
|
||||
"actually get logged anywhere");
|
||||
DEFINE_int32(logbuflevel, 0,
|
||||
"Buffer log messages logged at this level or lower"
|
||||
" (-1 means don't buffer; 0 means buffer INFO only;"
|
||||
" ...)");
|
||||
DEFINE_int32(logbufsecs, 30,
|
||||
"Buffer log messages for at most this many seconds");
|
||||
DEFINE_int32(logemaillevel, 999,
|
||||
"Email log messages logged at this level or higher"
|
||||
" (0 means email all; 3 means email FATAL only;"
|
||||
" ...)");
|
||||
DEFINE_string(logmailer, "/bin/mail",
|
||||
"Mailer used to send logging email");
|
||||
GLOG_DEFINE_string(alsologtoemail, "",
|
||||
"log messages go to these email addresses "
|
||||
"in addition to logfiles");
|
||||
GLOG_DEFINE_bool(log_prefix, true,
|
||||
"Prepend the log prefix to the start of each log line");
|
||||
GLOG_DEFINE_int32(minloglevel, 0, "Messages logged at a lower level than this don't "
|
||||
"actually get logged anywhere");
|
||||
GLOG_DEFINE_int32(logbuflevel, 0,
|
||||
"Buffer log messages logged at this level or lower"
|
||||
" (-1 means don't buffer; 0 means buffer INFO only;"
|
||||
" ...)");
|
||||
GLOG_DEFINE_int32(logbufsecs, 30,
|
||||
"Buffer log messages for at most this many seconds");
|
||||
GLOG_DEFINE_int32(logemaillevel, 999,
|
||||
"Email log messages logged at this level or higher"
|
||||
" (0 means email all; 3 means email FATAL only;"
|
||||
" ...)");
|
||||
GLOG_DEFINE_string(logmailer, "/bin/mail",
|
||||
"Mailer used to send logging email");
|
||||
|
||||
// Compute the default value for --log_dir
|
||||
static const char* DefaultLogDir() {
|
||||
@ -149,21 +149,21 @@ static const char* DefaultLogDir() {
|
||||
return "";
|
||||
}
|
||||
|
||||
DEFINE_string(log_dir, DefaultLogDir(),
|
||||
"If specified, logfiles are written into this directory instead "
|
||||
"of the default logging directory.");
|
||||
DEFINE_string(log_link, "", "Put additional links to the log "
|
||||
"files in this directory");
|
||||
GLOG_DEFINE_string(log_dir, DefaultLogDir(),
|
||||
"If specified, logfiles are written into this directory instead "
|
||||
"of the default logging directory.");
|
||||
GLOG_DEFINE_string(log_link, "", "Put additional links to the log "
|
||||
"files in this directory");
|
||||
|
||||
DEFINE_int32(max_log_size, 1800,
|
||||
"approx. maximum log file size (in MB). A value of 0 will "
|
||||
"be silently overridden to 1.");
|
||||
GLOG_DEFINE_int32(max_log_size, 1800,
|
||||
"approx. maximum log file size (in MB). A value of 0 will "
|
||||
"be silently overridden to 1.");
|
||||
|
||||
DEFINE_bool(stop_logging_if_full_disk, false,
|
||||
"Stop attempting to log to disk if the disk is full.");
|
||||
GLOG_DEFINE_bool(stop_logging_if_full_disk, false,
|
||||
"Stop attempting to log to disk if the disk is full.");
|
||||
|
||||
DEFINE_string(log_backtrace_at, "",
|
||||
"Emit a backtrace when logging at file:linenum.");
|
||||
GLOG_DEFINE_string(log_backtrace_at, "",
|
||||
"Emit a backtrace when logging at file:linenum.");
|
||||
|
||||
// TODO(hamaji): consider windows
|
||||
#define PATH_SEPARATOR '/'
|
||||
|
||||
@ -63,8 +63,8 @@ _END_GOOGLE_NAMESPACE_
|
||||
#include "symbolize.h"
|
||||
#include "base/commandlineflags.h"
|
||||
|
||||
DEFINE_bool(symbolize_stacktrace, true,
|
||||
"Symbolize the stack trace in the tombstone");
|
||||
GLOG_DEFINE_bool(symbolize_stacktrace, true,
|
||||
"Symbolize the stack trace in the tombstone");
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
|
||||
@ -49,10 +49,10 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
DEFINE_int32(v, 0, "Show all VLOG(m) messages for m <= this."
|
||||
GLOG_DEFINE_int32(v, 0, "Show all VLOG(m) messages for m <= this."
|
||||
" Overridable by --vmodule.");
|
||||
|
||||
DEFINE_string(vmodule, "", "per-module verbose level."
|
||||
GLOG_DEFINE_string(vmodule, "", "per-module verbose level."
|
||||
" Argument is a comma-separated list of <module name>=<log level>."
|
||||
" <module name> is a glob pattern, matched against the filename base"
|
||||
" (that is, name ignoring .cc/.h./-inl.h)."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user