| 382 | |
| 383 | |
| 384 | void initialize( |
| 385 | const string& _argv0, |
| 386 | bool installFailureSignalHandler, |
| 387 | const Option<Flags>& _flags) |
| 388 | { |
| 389 | static Once* initialized = new Once(); |
| 390 | |
| 391 | if (initialized->once()) { |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | argv0 = _argv0; |
| 396 | |
| 397 | // Use the default flags if not specified. |
| 398 | Flags flags; |
| 399 | if (_flags.isSome()) { |
| 400 | flags = _flags.get(); |
| 401 | |
| 402 | FLAGS_minloglevel = getLogSeverity(flags.logging_level); |
| 403 | FLAGS_logbufsecs = flags.logbufsecs; |
| 404 | } |
| 405 | |
| 406 | if (flags.logging_level != "INFO" && |
| 407 | flags.logging_level != "WARNING" && |
| 408 | flags.logging_level != "ERROR") { |
| 409 | cerr << "'" << flags.logging_level << "' is not a valid logging level." |
| 410 | << " Possible values for 'logging_level' flag are:" |
| 411 | << " 'INFO', 'WARNING', 'ERROR'." << endl; |
| 412 | exit(EXIT_FAILURE); |
| 413 | } |
| 414 | |
| 415 | if (flags.log_dir.isSome()) { |
| 416 | Try<Nothing> mkdir = os::mkdir(flags.log_dir.get()); |
| 417 | if (mkdir.isError()) { |
| 418 | cerr << "Could not initialize logging: Failed to create directory " |
| 419 | << flags.log_dir.get() << ": " << mkdir.error() << endl; |
| 420 | exit(EXIT_FAILURE); |
| 421 | } |
| 422 | FLAGS_log_dir = flags.log_dir.get(); |
| 423 | // Do not log to stderr instead of log files. |
| 424 | FLAGS_logtostderr = false; |
| 425 | } else { |
| 426 | // Log to stderr instead of log files. |
| 427 | FLAGS_logtostderr = true; |
| 428 | } |
| 429 | |
| 430 | // Log everything to stderr IN ADDITION to log files unless |
| 431 | // otherwise specified. |
| 432 | if (flags.quiet) { |
| 433 | FLAGS_stderrthreshold = 3; // FATAL. |
| 434 | |
| 435 | // FLAGS_stderrthreshold is ignored when logging to stderr instead |
| 436 | // of log files. Setting the minimum log level gets around this issue. |
| 437 | if (FLAGS_logtostderr) { |
| 438 | FLAGS_minloglevel = 3; // FATAL. |
| 439 | } |
| 440 | } else { |
| 441 | FLAGS_stderrthreshold = FLAGS_minloglevel; |
no test coverage detected