Classes | Namespaces | Macros | Enumerations | Functions | Variables
logging.cc File Reference
#include "utilities.h"
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <string>
#include <climits>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctime>
#include <fcntl.h>
#include <cstdio>
#include <iostream>
#include <cstdarg>
#include <cstdlib>
#include <vector>
#include <cerrno>
#include <sstream>
#include <dirent.h>
#include "base/commandlineflags.h"
#include <glog/logging.h>
#include <glog/raw_logging.h>
#include "base/googleinit.h"
Include dependency graph for logging.cc:

Go to the source code of this file.

Classes

class  LogDestination
 
struct  LogMessage::LogMessageData
 

Namespaces

 base
 
 base::internal
 

Macros

#define _GNU_SOURCE   1
 
#define DEFINE_CHECK_STROP_IMPL(name, func, expected)
 
#define EXCLUSIVE_LOCKS_REQUIRED(mu)
 
#define PATH_SEPARATOR   '/'
 

Enumerations

enum  GLogColor { COLOR_DEFAULT, COLOR_RED, COLOR_GREEN, COLOR_YELLOW }
 

Functions

void AddLogSink (LogSink *destination)
 
static bool BoolFromEnv (const char *varname, bool defval)
 
static void ColoredWriteToStderr (LogSeverity severity, const char *message, size_t len)
 
static void ColoredWriteToStderrOrStdout (FILE *output, LogSeverity severity, const char *message, size_t len)
 
static void ColoredWriteToStdout (LogSeverity severity, const char *message, size_t len)
 
static const char * DefaultLogDir ()
 
 DEFINE_int32 (stderrthreshold, GOOGLE_NAMESPACE::GLOG_ERROR, "log messages at or above this level are copied to stderr in " "addition to logfiles. This flag obsoletes --alsologtostderr.")
 
void DisableLogCleaner ()
 
void EnableLogCleaner (unsigned int overdue_days)
 
void FlushLogFiles (LogSeverity min_severity)
 
void FlushLogFilesUnsafe (LogSeverity min_severity)
 
static const char * GetAnsiColorCode (GLogColor color)
 
void GetExistingTempDirectories (vector< string > *list)
 
bool base::internal::GetExitOnDFatal ()
 
static void GetHostName (string *hostname)
 
const vector< string > & GetLoggingDirectories ()
 
const char * GetLogSeverityName (LogSeverity severity)
 
static void GetTempDirectories (vector< string > *list)
 
 GLOG_DEFINE_bool (alsologtostderr, BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false), "log messages go to stderr in addition to logfiles")
 
 GLOG_DEFINE_bool (colorlogtostderr, false, "color messages logged to stderr (if supported by terminal)")
 
 GLOG_DEFINE_bool (colorlogtostdout, false, "color messages logged to stdout (if supported by terminal)")
 
 GLOG_DEFINE_bool (log_prefix, true, "Prepend the log prefix to the start of each log line")
 
 GLOG_DEFINE_bool (log_utc_time, false, "Use UTC time for logging.")
 
 GLOG_DEFINE_bool (log_year_in_prefix, true, "Include the year in the log prefix")
 
 GLOG_DEFINE_bool (logtostderr, BoolFromEnv("GOOGLE_LOGTOSTDERR", false), "log messages go to stderr instead of logfiles")
 
 GLOG_DEFINE_bool (logtostdout, BoolFromEnv("GOOGLE_LOGTOSTDOUT", false), "log messages go to stdout instead of logfiles")
 
 GLOG_DEFINE_bool (stop_logging_if_full_disk, false, "Stop attempting to log to disk if the disk is full.")
 
 GLOG_DEFINE_bool (timestamp_in_logfile_name, BoolFromEnv("GOOGLE_TIMESTAMP_IN_LOGFILE_NAME", true), "put a timestamp at the end of the log file name")
 
 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 (logcleansecs, 60 *5, "Clean overdue logs every 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_int32 (logfile_mode, 0664, "Log file mode/permissions.")
 
 GLOG_DEFINE_int32 (minloglevel, 0, "Messages logged at a lower level than this don't " "actually get logged anywhere")
 
 GLOG_DEFINE_string (alsologtoemail, "", "log messages go to these email addresses " "in addition to logfiles")
 
 GLOG_DEFINE_string (log_backtrace_at, "", "Emit a backtrace when logging at file:linenum.")
 
 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")
 
 GLOG_DEFINE_string (logmailer, "", "Mailer used to send logging email")
 
 GLOG_DEFINE_uint32 (max_log_size, 1800, "approx. maximum log file size (in MB). A value of 0 will " "be silently overridden to 1.")
 
void InitGoogleLogging (const char *argv0)
 
void InstallFailureFunction (logging_fail_func_t fail_func)
 
void LogToStderr ()
 
template<>
void MakeCheckOpValueString (std::ostream *os, const char &v)
 
template<>
void MakeCheckOpValueString (std::ostream *os, const signed char &v)
 
template<>
void MakeCheckOpValueString (std::ostream *os, const unsigned char &v)
 
static uint32 MaxLogSize ()
 
ostream & operator<< (ostream &os, const PRIVATE_Counter &)
 
int posix_strerror_r (int err, char *buf, size_t len)
 
static ssize_t pread (int fd, void *buf, size_t count, off_t offset)
 
static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset)
 
void RemoveLogSink (LogSink *destination)
 
void ReprintFatalMessage ()
 
bool SendEmail (const char *dest, const char *subject, const char *body)
 
static bool SendEmailInternal (const char *dest, const char *subject, const char *body, bool use_logging)
 
void SetApplicationFingerprint (const std::string &fingerprint)
 
void SetEmailLogging (LogSeverity min_severity, const char *addresses)
 
void base::internal::SetExitOnDFatal (bool value)
 
void SetLogDestination (LogSeverity severity, const char *base_filename)
 
void SetLogFilenameExtension (const char *ext)
 
void SetLogSymlink (LogSeverity severity, const char *symlink_basename)
 
void SetStderrLogging (LogSeverity min_severity)
 
static GLogColor SeverityToColor (LogSeverity severity)
 
static string ShellEscape (const string &src)
 
void ShutdownGoogleLogging ()
 
string StrError (int err)
 
static bool TerminalSupportsColor ()
 
void TestOnly_ClearLoggingDirectoriesList ()
 
void TruncateLogFile (const char *path, uint64 limit, uint64 keep)
 
void TruncateStdoutStderr ()
 
static void WriteToStderr (const char *message, size_t len)
 

Variables

static CrashReason crash_reason
 
static bool exit_on_dfatal = true
 
static char fatal_message [256]
 
static LogMessage::LogMessageData fatal_msg_data_exclusive
 
static LogMessage::LogMessageData fatal_msg_data_shared
 
static bool fatal_msg_exclusive = true
 
static Mutex fatal_msg_lock
 
static time_t fatal_time
 
GLOG_EXPORT logging_fail_func_t g_logging_fail_func
 
static const char kDontNeedShellEscapeChars []
 
static Mutex log_mutex
 
static vector< string > * logging_directories_list
 
const char *const LogSeverityNames [NUM_SEVERITIES]
 
static bool stop_writing = false
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   1

Definition at line 30 of file logging.cc.

◆ DEFINE_CHECK_STROP_IMPL

#define DEFINE_CHECK_STROP_IMPL (   name,
  func,
  expected 
)
Value:
string* Check##func##expected##Impl(const char* s1, const char* s2, \
const char* names) { \
bool equal = s1 == s2 || (s1 && s2 && !func(s1, s2)); \
if (equal == expected) return NULL; \
else { \
ostringstream ss; \
if (!s1) s1 = ""; \
if (!s2) s2 = ""; \
ss << #name " failed: " << names << " (" << s1 << " vs. " << s2 << ")"; \
return new string(ss.str()); \
} \
}

Definition at line 2471 of file logging.cc.

◆ EXCLUSIVE_LOCKS_REQUIRED

#define EXCLUSIVE_LOCKS_REQUIRED (   mu)

Definition at line 106 of file logging.cc.

◆ PATH_SEPARATOR

#define PATH_SEPARATOR   '/'

Definition at line 208 of file logging.cc.

Enumeration Type Documentation

◆ GLogColor

enum GLogColor
Enumerator
COLOR_DEFAULT 
COLOR_RED 
COLOR_GREEN 
COLOR_YELLOW 

Definition at line 297 of file logging.cc.

Function Documentation

◆ AddLogSink()

void AddLogSink ( LogSink *  destination)

Definition at line 2138 of file logging.cc.

◆ BoolFromEnv()

static bool BoolFromEnv ( const char *  varname,
bool  defval 
)
static

Definition at line 108 of file logging.cc.

◆ ColoredWriteToStderr()

static void ColoredWriteToStderr ( LogSeverity  severity,
const char *  message,
size_t  len 
)
static

Definition at line 798 of file logging.cc.

◆ ColoredWriteToStderrOrStdout()

static void ColoredWriteToStderrOrStdout ( FILE *  output,
LogSeverity  severity,
const char *  message,
size_t  len 
)
static

Definition at line 746 of file logging.cc.

◆ ColoredWriteToStdout()

static void ColoredWriteToStdout ( LogSeverity  severity,
const char *  message,
size_t  len 
)
static

Definition at line 787 of file logging.cc.

◆ DefaultLogDir()

static const char* DefaultLogDir ( )
static

Definition at line 173 of file logging.cc.

◆ DEFINE_int32()

DEFINE_int32 ( stderrthreshold  ,
GOOGLE_NAMESPACE::GLOG_ERROR  ,
"log messages at or above this level are copied to stderr in " "addition to logfiles. This flag obsoletes --alsologtostderr."   
)

◆ DisableLogCleaner()

void DisableLogCleaner ( )

Definition at line 2643 of file logging.cc.

◆ EnableLogCleaner()

void EnableLogCleaner ( unsigned int  overdue_days)

Definition at line 2639 of file logging.cc.

◆ FlushLogFiles()

void FlushLogFiles ( LogSeverity  min_severity)

Definition at line 2059 of file logging.cc.

◆ FlushLogFilesUnsafe()

void FlushLogFilesUnsafe ( LogSeverity  min_severity)

Definition at line 2063 of file logging.cc.

◆ GetAnsiColorCode()

static const char* GetAnsiColorCode ( GLogColor  color)
static

Definition at line 340 of file logging.cc.

◆ GetExistingTempDirectories()

void GetExistingTempDirectories ( vector< string > *  list)

Definition at line 2366 of file logging.cc.

◆ GetHostName()

static void GetHostName ( string hostname)
static

Definition at line 246 of file logging.cc.

◆ GetLoggingDirectories()

const vector<string>& GetLoggingDirectories ( )

Definition at line 2336 of file logging.cc.

◆ GetLogSeverityName()

const char* GetLogSeverityName ( LogSeverity  severity)

Definition at line 411 of file logging.cc.

◆ GetTempDirectories()

static void GetTempDirectories ( vector< string > *  list)
static

Definition at line 2285 of file logging.cc.

◆ GLOG_DEFINE_bool() [1/10]

GLOG_DEFINE_bool ( alsologtostderr  ,
BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false)  ,
"log messages go to stderr in addition to logfiles"   
)

◆ GLOG_DEFINE_bool() [2/10]

GLOG_DEFINE_bool ( colorlogtostderr  ,
false  ,
"color messages logged to stderr (if supported by terminal)"   
)

◆ GLOG_DEFINE_bool() [3/10]

GLOG_DEFINE_bool ( colorlogtostdout  ,
false  ,
"color messages logged to stdout (if supported by terminal)"   
)

◆ GLOG_DEFINE_bool() [4/10]

GLOG_DEFINE_bool ( log_prefix  ,
true  ,
"Prepend the log prefix to the start of each log line"   
)

◆ GLOG_DEFINE_bool() [5/10]

GLOG_DEFINE_bool ( log_utc_time  ,
false  ,
"Use UTC time for logging."   
)

◆ GLOG_DEFINE_bool() [6/10]

GLOG_DEFINE_bool ( log_year_in_prefix  ,
true  ,
"Include the year in the log prefix  
)

◆ GLOG_DEFINE_bool() [7/10]

GLOG_DEFINE_bool ( logtostderr  ,
BoolFromEnv("GOOGLE_LOGTOSTDERR", false)  ,
"log messages go to stderr instead of logfiles"   
)

◆ GLOG_DEFINE_bool() [8/10]

GLOG_DEFINE_bool ( logtostdout  ,
BoolFromEnv("GOOGLE_LOGTOSTDOUT", false)  ,
"log messages go to stdout instead of logfiles"   
)

◆ GLOG_DEFINE_bool() [9/10]

GLOG_DEFINE_bool ( stop_logging_if_full_disk  ,
false  ,
"Stop attempting to log to disk if the disk is full."   
)

◆ GLOG_DEFINE_bool() [10/10]

GLOG_DEFINE_bool ( timestamp_in_logfile_name  ,
BoolFromEnv("GOOGLE_TIMESTAMP_IN_LOGFILE_NAME", true)  ,
"put a timestamp at the end of the log file name  
)

◆ GLOG_DEFINE_int32() [1/6]

GLOG_DEFINE_int32 ( logbuflevel  ,
,
"Buffer log messages logged at this level or lower" " (-1 means don't buffer; 0 means buffer INFO only;" " ...)"   
)

◆ GLOG_DEFINE_int32() [2/6]

GLOG_DEFINE_int32 ( logbufsecs  ,
30  ,
"Buffer log messages for at most this many seconds"   
)

◆ GLOG_DEFINE_int32() [3/6]

GLOG_DEFINE_int32 ( logcleansecs  ,
60 *  5,
"Clean overdue logs every this many seconds"   
)

◆ GLOG_DEFINE_int32() [4/6]

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_int32() [5/6]

GLOG_DEFINE_int32 ( logfile_mode  ,
0664  ,
"Log file mode/permissions."   
)

◆ GLOG_DEFINE_int32() [6/6]

GLOG_DEFINE_int32 ( minloglevel  ,
,
"Messages logged at a lower level than this don't " "actually get logged anywhere"   
)

◆ GLOG_DEFINE_string() [1/5]

GLOG_DEFINE_string ( alsologtoemail  ,
""  ,
"log messages go to these email addresses " "in addition to logfiles"   
)

◆ GLOG_DEFINE_string() [2/5]

GLOG_DEFINE_string ( log_backtrace_at  ,
""  ,
"Emit a backtrace when logging at file:linenum."   
)

◆ GLOG_DEFINE_string() [3/5]

GLOG_DEFINE_string ( log_dir  ,
DefaultLogDir()  ,
"If  specified,
logfiles are written into this directory instead " "of the default logging directory."   
)

◆ GLOG_DEFINE_string() [4/5]

GLOG_DEFINE_string ( log_link  ,
""  ,
"Put additional links to the log " "files in this directory"   
)

◆ GLOG_DEFINE_string() [5/5]

GLOG_DEFINE_string ( logmailer  ,
""  ,
"Mailer used to send logging email"   
)

◆ GLOG_DEFINE_uint32()

GLOG_DEFINE_uint32 ( max_log_size  ,
1800  ,
"approx. maximum log file size (in MB). A value of 0 will " "be silently overridden to 1."   
)

◆ InitGoogleLogging()

void InitGoogleLogging ( const char *  argv0)

Definition at line 2618 of file logging.cc.

◆ InstallFailureFunction()

void InstallFailureFunction ( logging_fail_func_t  fail_func)

Definition at line 1941 of file logging.cc.

◆ LogToStderr()

void LogToStderr ( )

Definition at line 2158 of file logging.cc.

◆ MakeCheckOpValueString() [1/3]

template<>
void MakeCheckOpValueString ( std::ostream *  os,
const char &  v 
)

Definition at line 2585 of file logging.cc.

◆ MakeCheckOpValueString() [2/3]

template<>
void MakeCheckOpValueString ( std::ostream *  os,
const signed char &  v 
)

Definition at line 2594 of file logging.cc.

◆ MakeCheckOpValueString() [3/3]

template<>
void MakeCheckOpValueString ( std::ostream *  os,
const unsigned char &  v 
)

Definition at line 2603 of file logging.cc.

◆ MaxLogSize()

static uint32 MaxLogSize ( )
static

Definition at line 353 of file logging.cc.

◆ operator<<()

ostream& operator<< ( ostream &  os,
const PRIVATE_Counter &   
)

Definition at line 2035 of file logging.cc.

◆ posix_strerror_r()

int posix_strerror_r ( int  err,
char *  buf,
size_t  len 
)

Definition at line 2490 of file logging.cc.

◆ pread()

static ssize_t pread ( int  fd,
void buf,
size_t  count,
off_t  offset 
)
static

Definition at line 215 of file logging.cc.

◆ pwrite()

static ssize_t pwrite ( int  fd,
void buf,
size_t  count,
off_t  offset 
)
static

Definition at line 231 of file logging.cc.

◆ RemoveLogSink()

void RemoveLogSink ( LogSink *  destination)

Definition at line 2142 of file logging.cc.

◆ ReprintFatalMessage()

void ReprintFatalMessage ( )

Definition at line 1808 of file logging.cc.

◆ SendEmail()

bool SendEmail ( const char *  dest,
const char *  subject,
const char *  body 
)

Definition at line 2281 of file logging.cc.

◆ SendEmailInternal()

static bool SendEmailInternal ( const char *  dest,
const char *  subject,
const char *  body,
bool  use_logging 
)
static

Definition at line 2229 of file logging.cc.

◆ SetApplicationFingerprint()

void SetApplicationFingerprint ( const std::string fingerprint)

Definition at line 941 of file logging.cc.

◆ SetEmailLogging()

void SetEmailLogging ( LogSeverity  min_severity,
const char *  addresses 
)

Definition at line 2154 of file logging.cc.

◆ SetLogDestination()

void SetLogDestination ( LogSeverity  severity,
const char *  base_filename 
)

Definition at line 2067 of file logging.cc.

◆ SetLogFilenameExtension()

void SetLogFilenameExtension ( const char *  ext)

Definition at line 2146 of file logging.cc.

◆ SetLogSymlink()

void SetLogSymlink ( LogSeverity  severity,
const char *  symlink_basename 
)

Definition at line 2071 of file logging.cc.

◆ SetStderrLogging()

void SetStderrLogging ( LogSeverity  min_severity)

Definition at line 2150 of file logging.cc.

◆ SeverityToColor()

static GLogColor SeverityToColor ( LogSeverity  severity)
static

Definition at line 304 of file logging.cc.

◆ ShellEscape()

static string ShellEscape ( const string src)
static

Definition at line 2196 of file logging.cc.

◆ ShutdownGoogleLogging()

void ShutdownGoogleLogging ( )

Definition at line 2632 of file logging.cc.

◆ StrError()

string StrError ( int  err)

Definition at line 2540 of file logging.cc.

◆ TerminalSupportsColor()

static bool TerminalSupportsColor ( )
static

Definition at line 269 of file logging.cc.

◆ TestOnly_ClearLoggingDirectoriesList()

void TestOnly_ClearLoggingDirectoriesList ( )

Definition at line 2359 of file logging.cc.

◆ TruncateLogFile()

void TruncateLogFile ( const char *  path,
uint64  limit,
uint64  keep 
)

Definition at line 2380 of file logging.cc.

◆ TruncateStdoutStderr()

void TruncateStdoutStderr ( )

Definition at line 2458 of file logging.cc.

◆ WriteToStderr()

static void WriteToStderr ( const char *  message,
size_t  len 
)
static

Definition at line 803 of file logging.cc.

Variable Documentation

◆ crash_reason

CrashReason crash_reason
static

Definition at line 1535 of file logging.cc.

◆ exit_on_dfatal

bool exit_on_dfatal = true
static

Definition at line 409 of file logging.cc.

◆ fatal_message

char fatal_message[256]
static

Definition at line 1806 of file logging.cc.

◆ fatal_msg_data_exclusive

LogMessage::LogMessageData fatal_msg_data_exclusive
static

Definition at line 1537 of file logging.cc.

◆ fatal_msg_data_shared

LogMessage::LogMessageData fatal_msg_data_shared
static

Definition at line 1538 of file logging.cc.

◆ fatal_msg_exclusive

bool fatal_msg_exclusive = true
static

Definition at line 1536 of file logging.cc.

◆ fatal_msg_lock

Mutex fatal_msg_lock
static

Definition at line 1534 of file logging.cc.

◆ fatal_time

time_t fatal_time
static

Definition at line 1805 of file logging.cc.

◆ g_logging_fail_func

GLOG_EXPORT logging_fail_func_t g_logging_fail_func
Initial value:
=
reinterpret_cast<logging_fail_func_t>(&abort)

Definition at line 1938 of file logging.cc.

◆ kDontNeedShellEscapeChars

const char kDontNeedShellEscapeChars[]
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+-_.=/:,@"

Definition at line 2191 of file logging.cc.

◆ log_mutex

Mutex log_mutex
static

Definition at line 396 of file logging.cc.

◆ logging_directories_list

vector<string>* logging_directories_list
static

Definition at line 2334 of file logging.cc.

◆ LogSeverityNames

const char* const LogSeverityNames[NUM_SEVERITIES]
Initial value:
= {
"INFO", "WARNING", "ERROR", "FATAL"
}

Definition at line 404 of file logging.cc.

◆ stop_writing

bool stop_writing = false
static

Definition at line 402 of file logging.cc.

name
GLuint const GLchar * name
Definition: glcorearb.h:3055
NULL
NULL
Definition: test_security_zap.cpp:405
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
func
GLenum func
Definition: glcorearb.h:3052


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:03