Lingua-Identify-CLD
view release on metacpan or search on metacpan
cld-src/base/logging.h view on Meta::CPAN
#define COMPACT_GOOGLE_LOG_FATAL NullStreamFatal()
#define COMPACT_GOOGLE_LOG_QFATAL NullStreamFatal()
#define LOG_TO_STRING_FATAL(message) NullStreamFatal()
#endif
// For DFATAL, we want to use LogMessage (as opposed to
// LogMessageFatal), to be consistent with the original behavior.
#ifdef NDEBUG
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL LogMessage(__FILE__, __LINE__, FATAL)
#else
#define COMPACT_GOOGLE_LOG_DFATAL NullStreamFatal()
#endif
#define GOOGLE_LOG_INFO(counter) \
LogMessage(__FILE__, __LINE__, INFO, counter, &LogMessage::SendToLog)
#define SYSLOG_INFO(counter) \
LogMessage(__FILE__, __LINE__, INFO, counter, \
&LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_WARNING(counter) \
LogMessage(__FILE__, __LINE__, WARNING, counter, &LogMessage::SendToLog)
#define SYSLOG_WARNING(counter) \
LogMessage(__FILE__, __LINE__, WARNING, counter, \
&LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_ERROR(counter) \
LogMessage(__FILE__, __LINE__, ERROR, counter, &LogMessage::SendToLog)
#define SYSLOG_ERROR(counter) \
LogMessage(__FILE__, __LINE__, ERROR, counter, \
&LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_FATAL(counter) \
LogMessage(__FILE__, __LINE__, FATAL, counter, &LogMessage::SendToLog)
#define SYSLOG_FATAL(counter) \
LogMessage(__FILE__, __LINE__, FATAL, counter, \
&LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_DFATAL(counter) \
LogMessage(__FILE__, __LINE__, DFATAL_LEVEL, counter, &LogMessage::SendToLog)
#define SYSLOG_DFATAL(counter) \
LogMessage(__FILE__, __LINE__, DFATAL_LEVEL, counter, \
&LogMessage::SendToSyslogAndLog)
#ifdef OS_WINDOWS
// A very useful logging macro to log windows errors:
#define LOG_SYSRESULT(result) \
if (FAILED(result)) { \
LPTSTR message = NULL; \
LPTSTR msg = reinterpret_cast<LPTSTR>(&message); \
DWORD message_length = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
FORMAT_MESSAGE_FROM_SYSTEM, \
0, result, 0, msg, 100, NULL); \
if (message_length > 0) { \
LogMessage(__FILE__, __LINE__, ERROR, 0, \
&LogMessage::SendToLog).stream() << message; \
LocalFree(message); \
} \
}
#endif
// We use the preprocessor's merging operator, "##", so that, e.g.,
// LOG(INFO) becomes the token GOOGLE_LOG_INFO. There's some funny
// subtle difference between ostream member streaming functions (e.g.,
// ostream::operator<<(int) and ostream non-member streaming functions
// (e.g., ::operator<<(ostream&, string&): it turns out that it's
// impossible to stream something like a string directly to an unnamed
// ostream. We employ a neat hack by calling the stream() member
// function of LogMessage which seems to avoid the problem.
#define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
#define SYSLOG(severity) SYSLOG_ ## severity(0).stream()
// A convenient shorthand
#define LG LOG(INFO)
class LogSink; // defined below
// If a non-NULL sink pointer is given, we push this message to that sink.
// For LOG_TO_SINK we then do normal LOG(severity) logging as well.
// This is useful for capturing messages and passing/storing them
// somewhere more specific than the global log of the process.
// Argument types:
// LogSink* sink;
// LogSeverity severity;
// The cast is to disambiguate NULL arguments.
#define LOG_TO_SINK(sink, severity) \
LogMessage(__FILE__, __LINE__, severity, \
static_cast<LogSink*>(sink), true).stream()
#define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \
LogMessage(__FILE__, __LINE__, severity, \
static_cast<LogSink*>(sink), false).stream()
// If a non-NULL string pointer is given, we write this message to that string.
// We then do normal LOG(severity) logging as well.
// This is useful for capturing messages and storing them somewhere more
// specific than the global log of the process.
// Argument types:
// string* message;
// LogSeverity severity;
// The cast is to disambiguate NULL arguments.
// NOTE: LOG(severity) expands to LogMessage().stream() for the specified
// severity.
#define LOG_TO_STRING(severity, message) \
LOG_TO_STRING_##severity(static_cast<string*>(message)).stream()
// If a non-NULL pointer is given, we push the message onto the end
// of a vector of strings; otherwise, we report it with LOG(severity).
// This is handy for capturing messages and perhaps passing them back
// to the caller, rather than reporting them immediately.
// Argument types:
// LogSeverity severity;
// vector<string> *outvec;
// The cast is to disambiguate NULL arguments.
#define LOG_STRING(severity, outvec) \
LOG_TO_STRING_##severity(static_cast<vector<string>*>(outvec)).stream()
#define LOG_IF(severity, condition) \
!(condition) ? (void) 0 : LogMessageVoidify() & LOG(severity)
#define SYSLOG_IF(severity, condition) \
!(condition) ? (void) 0 : LogMessageVoidify() & SYSLOG(severity)
#define LOG_ASSERT(condition) \
LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
#define SYSLOG_ASSERT(condition) \
SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
cld-src/base/logging.h view on Meta::CPAN
#define DCHECK_LT(val1, val2) \
while (false) \
CHECK_LT(val1, val2)
#define DCHECK_GE(val1, val2) \
while (false) \
CHECK_GE(val1, val2)
#define DCHECK_GT(val1, val2) \
while (false) \
CHECK_GT(val1, val2)
#define DCHECK_STREQ(str1, str2) \
while (false) \
CHECK_STREQ(str1, str2)
#define DCHECK_STRCASEEQ(str1, str2) \
while (false) \
CHECK_STRCASEEQ(str1, str2)
#define DCHECK_STRNE(str1, str2) \
while (false) \
CHECK_STRNE(str1, str2)
#define DCHECK_STRCASENE(str1, str2) \
while (false) \
CHECK_STRCASENE(str1, str2)
#endif // NDEBUG
// Log only in verbose mode.
#define VLOG(verboselevel) LOG_IF(INFO, VLOG_IS_ON(verboselevel))
#define VLOG_IF(verboselevel, condition) \
LOG_IF(INFO, (condition) && VLOG_IS_ON(verboselevel))
#define VLOG_EVERY_N(verboselevel, n) \
LOG_IF_EVERY_N(INFO, VLOG_IS_ON(verboselevel), n)
#define VLOG_IF_EVERY_N(verboselevel, condition, n) \
LOG_IF_EVERY_N(INFO, (condition) && VLOG_IS_ON(verboselevel), n)
// [MLOG is OBSOLETE - use the more convenient VLOG(n) macros]
// Log only when a module-specific value (MODULE_FLAG) has a specific
// value. MODULE_FLAG must be a macro that evaluates to the name of
// the flag that you wish to use. You should '#define MODULE_FLAG
// <variable name>' before using this macro. (For example:
// #define MODULE_FLAG FLAGS_dnsverbose
#define MLOG(verboselevel) LOG_IF(INFO, MODULE_FLAG >= (verboselevel))
// Redefine the standard assert to use our nice log files
#undef assert
#define assert(x) DLOG_ASSERT(x)
//
// This class more or less represents a particular log message. You
// create an instance of LogMessage and then stream stuff to it.
// When you finish streaming to it, ~LogMessage is called and the
// full message gets streamed to the appropriate destination.
//
// You shouldn't actually use LogMessage's constructor to log things,
// though. You should use the LOG() macro (and variants thereof)
// above.
class LogMessage {
public:
enum {
// Passing kNoLogPrefix for the line number disables the
// log-message prefix. Useful for using the LogMessage
// infrastructure as a printing utility. See also the --log_prefix
// flag for controlling the log-message prefix on an
// application-wide basis.
kNoLogPrefix = -1
};
class LogStream : public ostrstream {
public:
LogStream(char *buf, int len, int ctr)
: ostrstream(buf, len),
ctr_(ctr) {
self_ = this;
}
int ctr() const { return ctr_; }
void set_ctr(int ctr) { ctr_ = ctr; }
LogStream* self() const { return self_; }
private:
int ctr_; // Counter hack (for the LOG_EVERY_X() macro)
LogStream *self_; // Consistency check hack
};
public:
// icc 8 requires this typedef to avoid an internal compiler error.
typedef void (LogMessage::*SendMethod)();
LogMessage(const char* file, int line, LogSeverity severity, int ctr,
SendMethod send_method);
// Two special constructors that generate reduced amounts of code at
// LOG call sites for common cases.
// Used for LOG(INFO): Implied are:
// severity = INFO, ctr = 0, send_method = &LogMessage::SendToLog.
//
// Using this constructor instead of the more complex constructor above
// saves 19 bytes per call site.
LogMessage(const char* file, int line);
// Used for LOG(severity) where severity != INFO. Implied
// are: ctr = 0, send_method = &LogMessage::SendToLog
//
// Using this constructor instead of the more complex constructor above
// saves 17 bytes per call site.
LogMessage(const char* file, int line, LogSeverity severity);
// Constructor to log this message to a specified sink (if not NULL).
// Implied are: ctr = 0, send_method = &LogMessage::SendToSinkAndLog if
// also_send_to_log is true, send_method = &LogMessage::SendToSink otherwise.
LogMessage(const char* file, int line, LogSeverity severity, LogSink* sink,
bool also_send_to_log);
// Constructor where we also give a vector<string> pointer
// for storing the messages (if the pointer is not NULL).
// Implied are: ctr = 0, send_method = &LogMessage::SaveOrSendToLog.
LogMessage(const char* file, int line, LogSeverity severity,
vector<string>* outvec);
// Constructor where we also give a string pointer for storing the
// message (if the pointer is not NULL). Implied are: ctr = 0,
// send_method = &LogMessage::WriteToStringAndLog.
LogMessage(const char* file, int line, LogSeverity severity,
string* message);
// A special constructor used for check failures
LogMessage(const char* file, int line, const CheckOpString& result);
~LogMessage();
// Flush a buffered message to the sink set in the constructor. Always
// called by the destructor, it may also be called from elsewhere if
// needed. Only the first call is actioned; any later ones are ignored.
void Flush();
// An arbitrary limit on the length of a single log message. This
// is so that streaming can be done more efficiently.
static const size_t kMaxLogMessageLen;
// Theses should not be called directly outside of logging.*,
// only passed as SendMethod arguments to other LogMessage methods:
void SendToLog(); // Actually dispatch to the logs
void SendToSyslogAndLog(); // Actually dispatch to syslog and the logs
// Call abort() or similar to perform LOG(FATAL) crash.
// Writes current stack trace to stderr.
static void Fail() ATTRIBUTE_NORETURN;
// Same as Fail(), but without writing out the stack trace.
// It is assumed that the caller has already generated and
// written the trace as appropriate.
static void FailWithoutStackTrace() ATTRIBUTE_NORETURN;
// Similar to FailWithoutStackTrace(), but without abort()ing.
// Terminates the process with error exit code.
static void FailQuietly() ATTRIBUTE_NORETURN;
ostream& stream() { return *(data_->stream_); }
int preserved_errno() const { return data_->preserved_errno_; }
// Must be called without the log_mutex held. (L < log_mutex)
static int64 num_messages(int severity);
private:
// Fully internal SendMethod cases:
void SendToSinkAndLog(); // Send to sink if provided and dispatch to the logs
void SendToSink(); // Send to sink if provided, do nothing otherwise.
// Write to string if provided and dispatch to the logs.
void WriteToStringAndLog();
void SaveOrSendToLog(); // Save to stringvec if provided, else to logs
void Init(const char* file, int line, LogSeverity severity,
void (LogMessage::*send_method)());
// Used to fill in crash information during LOG(FATAL) failures.
void RecordCrashReason(base::CrashReason* reason);
// Counts of messages sent at each priority:
static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex
// We keep the data in a separate struct so that each instance of
// LogMessage uses less stack space.
struct LogMessageData {
LogMessageData() {};
int preserved_errno_; // errno at Init() time
scoped_array<char> buf_; // buffer space for non FATAL messages
char* message_text_; // Complete message text
scoped_ptr<LogStream> stream_alloc_;
LogStream* stream_;
char severity_; // level of LogMessage (ex. I, W, E, F)
int line_; // line number of file that called LOG
void (LogMessage::*send_method_)(); // Call this in destructor to send
union { // At most one of these is used: union to keep the size low.
( run in 0.878 second using v1.01-cache-2.11-cpan-d8267643d1d )