本文整理汇总了C++中ThreadData::hook方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadData::hook方法的具体用法?C++ ThreadData::hook怎么用?C++ ThreadData::hook使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadData
的用法示例。
在下文中一共展示了ThreadData::hook方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: log
void Logger::log(const std::string &msg, const StackTrace *stackTrace,
bool escape /* = true */, bool escapeMore /* = false */) {
ASSERT(!escapeMore || escape);
ThreadData *threadData = s_threadData.get();
if (++threadData->message > MaxMessagesPerRequest &&
MaxMessagesPerRequest >= 0) {
return;
}
boost::shared_ptr<StackTrace> deleter;
if (stackTrace == NULL) {
deleter = boost::shared_ptr<StackTrace>(new StackTrace());
stackTrace = deleter.get();
}
if (UseLogAggregator) {
LogAggregator::TheLogAggregator.log(*stackTrace, msg);
}
if (UseLogFile) {
FILE *f = Output ? Output : stdout;
string header, sheader;
if (LogHeader) {
header = GetHeader();
if (LogNativeStackTrace) {
sheader = header + "[" + stackTrace->hexEncode(5) + "] ";
} else {
sheader = header;
}
}
const char *escaped = escape ? EscapeString(msg) : msg.c_str();
const char *ending = escapeMore ? "\\n" : "\n";
if (f == stdout && Util::s_stderr_color) {
fprintf(f, "%s%s%s%s%s",
Util::s_stderr_color, sheader.c_str(), msg.c_str(), ending,
ANSI_COLOR_END);
} else {
fprintf(f, "%s%s%s", sheader.c_str(), escaped, ending);
}
FILE *tf = threadData->log;
if (tf) {
fprintf(tf, "%s%s%s", header.c_str(), escaped, ending);
fflush(tf);
}
if (threadData->hook) {
threadData->hook(header.c_str(), escaped, ending, threadData->hookData);
}
if (escape) {
free((void*)escaped);
}
fflush(f);
}
}
示例2: log
void Logger::log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape /* = false */, bool escapeMore /* = false */) {
if (Logger::Escape) {
escape = true;
}
assert(!escapeMore || escape);
ThreadData *threadData = s_threadData.get();
if (++threadData->message > MaxMessagesPerRequest &&
MaxMessagesPerRequest >= 0) {
return;
}
boost::shared_ptr<StackTrace> deleter;
if (LogNativeStackTrace && stackTrace == nullptr) {
deleter = boost::shared_ptr<StackTrace>(new StackTrace());
stackTrace = deleter.get();
}
if (UseSyslog) {
syslog(GetSyslogLevel(level), "%s", msg.c_str());
}
FILE *stdf = GetStandardOut(level);
if (UseLogFile) {
FILE *f;
if (UseCronolog) {
f = cronOutput.getOutputFile();
if (!f) f = stdf;
} else {
f = Output ? Output : stdf;
}
string header, sheader;
if (LogHeader) {
header = GetHeader();
if (LogNativeStackTrace) {
sheader = header + "[" + stackTrace->hexEncode(5) + "] ";
} else {
sheader = header;
}
}
const char *escaped = escape ? EscapeString(msg) : msg.c_str();
const char *ending = escapeMore ? "\\n" : "\n";
int bytes;
if (f == stdf && s_stderr_color) {
bytes =
fprintf(f, "%s%s%s%s%s",
s_stderr_color, sheader.c_str(), msg.c_str(), ending,
ANSI_COLOR_END);
} else {
bytes = fprintf(f, "%s%s%s", sheader.c_str(), escaped, ending);
}
bytesWritten.fetch_add(bytes, std::memory_order_relaxed);
FILE *tf = threadData->log;
if (tf) {
threadData->bytesWritten +=
fprintf(tf, "%s%s%s", header.c_str(), escaped, ending);
fflush(tf);
threadData->prevBytesWritten =
checkDropCache(threadData->bytesWritten,
threadData->prevBytesWritten,
tf);
}
if (threadData->hook) {
threadData->hook(header.c_str(), msg.c_str(), ending,
threadData->hookData);
}
if (escape) {
free((void*)escaped);
}
fflush(f);
if (UseCronolog || (Output && !Logger::IsPipeOutput)) {
prevBytesWritten =
checkDropCache(bytesWritten.load(std::memory_order_relaxed),
prevBytesWritten, f);
}
}
}
示例3: log
void Logger::log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape /* = false */, bool escapeMore /* = false */) {
if (Logger::AlwaysEscapeLog && Logger::Escape) {
escape = true;
}
assert(!escapeMore || escape);
ThreadData *threadData = s_threadData.get();
if (threadData->message != -1 &&
++threadData->message > MaxMessagesPerRequest &&
MaxMessagesPerRequest >= 0) {
return;
}
std::unique_ptr<StackTrace> deleter;
if (LogNativeStackTrace && stackTrace == nullptr) {
deleter.reset(new StackTrace());
stackTrace = deleter.get();
}
if (UseSyslog) {
syslog(GetSyslogLevel(level), "%s", msg.c_str());
}
if (UseLogFile) {
FILE *stdf = GetStandardOut(level);
FILE *f;
if (UseCronolog) {
f = cronOutput.getOutputFile();
if (!f) f = stdf;
} else {
f = Output ? Output : stdf;
}
std::string header, sheader;
if (LogHeader) {
header = GetHeader();
if (LogNativeStackTrace) {
sheader = header + "[" + stackTrace->hexEncode(5) + "] ";
} else {
sheader = header;
}
}
const char *escaped = escape ? EscapeString(msg) : msg.c_str();
const char *ending = escapeMore ? "\\n" : "\n";
int bytes;
if (f == stdf && s_stderr_color) {
bytes =
fprintf(f, "%s%s%s%s%s",
s_stderr_color, sheader.c_str(), msg.c_str(), ending,
ANSI_COLOR_END);
} else {
bytes = fprintf(f, "%s%s%s", sheader.c_str(), escaped, ending);
}
FILE *tf = threadData->log;
if (tf) {
int threadBytes =
fprintf(tf, "%s%s%s", header.c_str(), escaped, ending);
fflush(tf);
threadData->flusher.recordWriteAndMaybeDropCaches(tf, threadBytes);
}
if (threadData->hook) {
threadData->hook(header.c_str(), msg.c_str(), ending,
threadData->hookData);
}
if (escape) {
free((void*)escaped);
}
fflush(f);
if (UseCronolog || (Output && !Logger::IsPipeOutput)) {
flusher.recordWriteAndMaybeDropCaches(f, bytes);
}
}
}
示例4: log
void Logger::log(bool err, const std::string &msg,
const StackTrace *stackTrace,
bool escape /* = true */, bool escapeMore /* = false */) {
ASSERT(!escapeMore || escape);
ThreadData *threadData = s_threadData.get();
if (++threadData->message > MaxMessagesPerRequest &&
MaxMessagesPerRequest >= 0) {
return;
}
boost::shared_ptr<StackTrace> deleter;
if (stackTrace == NULL) {
deleter = boost::shared_ptr<StackTrace>(new StackTrace());
stackTrace = deleter.get();
}
if (UseLogAggregator) {
LogAggregator::TheLogAggregator.log(*stackTrace, msg);
}
FILE *stdf = err ? stderr : stdout;
if (UseLogFile) {
FILE *f;
if (UseCronolog) {
f = cronOutput.getOutputFile();
if (!f) f = stdf;
} else {
f = Output ? Output : stdf;
}
string header, sheader;
if (LogHeader) {
header = GetHeader();
if (LogNativeStackTrace) {
sheader = header + "[" + stackTrace->hexEncode(5) + "] ";
} else {
sheader = header;
}
}
const char *escaped = escape ? EscapeString(msg) : msg.c_str();
const char *ending = escapeMore ? "\\n" : "\n";
int bytes;
if (f == stdf && Util::s_stderr_color) {
bytes =
fprintf(f, "%s%s%s%s%s",
Util::s_stderr_color, sheader.c_str(), msg.c_str(), ending,
ANSI_COLOR_END);
} else {
bytes = fprintf(f, "%s%s%s", sheader.c_str(), escaped, ending);
}
atomic_add(bytesWritten, bytes);
FILE *tf = threadData->log;
if (tf) {
threadData->bytesWritten +=
fprintf(tf, "%s%s%s", header.c_str(), escaped, ending);
fflush(tf);
checkDropCache(threadData->bytesWritten,
threadData->prevBytesWritten,
tf);
}
if (threadData->hook) {
threadData->hook(header.c_str(), msg.c_str(), ending,
threadData->hookData);
}
if (escape) {
free((void*)escaped);
}
fflush(f);
if (UseCronolog || (Output && RuntimeOption::LogFile[0] != '|')) {
checkDropCache(bytesWritten, prevBytesWritten, f);
}
}
}
示例5: make_pair
std::pair<int, int> Logger::log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape /* = false */,
bool escapeMore /* = false */) {
if (Logger::AlwaysEscapeLog && Logger::Escape) {
escape = true;
}
assertx(!escapeMore || escape); // escape must be enabled to escapeMore
std::unique_ptr<StackTrace> deleter;
if (LogNativeStackTrace && stackTrace == nullptr) {
deleter.reset(new StackTrace());
stackTrace = deleter.get();
}
if (UseSyslog) {
syslog(GetSyslogLevel(level), "%s", msg.c_str());
}
int bytes = 0;
if (UseLogFile) {
ThreadData *threadData = s_threadData.get();
FILE* tf = threadData->log;
FILE* f = output();
std::string header, sheader;
if (LogHeader) {
header = GetHeader();
if (LogNativeStackTrace) {
sheader = header + "[" + stackTrace->hexEncode(5) + "] ";
} else {
sheader = header;
}
}
const char *escaped = escape ? EscapeString(msg) : msg.c_str();
const char *ending = escapeMore ? "\\n" : "\n";
if (f == m_standardOut && s_stderr_color) {
bytes =
fprintf(f, "%s%s%s%s%s",
s_stderr_color, sheader.c_str(), msg.c_str(), ending,
ANSI_COLOR_END);
} else {
bytes = fprintf(f, "%s%s%s", sheader.c_str(), escaped, ending);
}
if (tf && tf != f) {
int threadBytes =
fprintf(tf, "%s%s%s", header.c_str(), escaped, ending);
fflush(tf);
threadData->flusher.recordWriteAndMaybeDropCaches(tf, threadBytes);
}
if (threadData->hook) {
threadData->hook(header.c_str(), msg.c_str(), ending,
threadData->hookData);
}
if (escape) {
free((void*)escaped);
}
fflush(f);
if (UseCronolog || (m_output && !m_isPipeOutput)) {
m_flusher.recordWriteAndMaybeDropCaches(f, bytes);
}
}
return std::make_pair(1, bytes);
}