本文整理汇总了C++中LogMessage类的典型用法代码示例。如果您正苦于以下问题:C++ LogMessage类的具体用法?C++ LogMessage怎么用?C++ LogMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
void Log::write (LogMessage log_message) {
for (int i = 0; (unsigned) i < Log::loggers.size(); i++) {
if (Log::loggers[i]->get_level() >= log_message.get_level() ) {
Log::loggers[i]->write(log_message);
}
}
}
示例2: fatalCheckToString
// helper for fatal CHECK
std::string fatalCheckToString(const LogMessage& msg) {
auto out = LogDetailsToString(msg);
static const std::string contractExitReason = {"EXIT trigger caused by broken Contract:"};
out.append("\n\t*******\t " + contractExitReason + " CHECK(" + msg.expression() + ")\n\t"
+ '"' + msg. message() + '"');
return out;
}
示例3: log
void LogAppenderBase::log(const LogMessage& message)
{
if(message.getLogLevel() >= m_logLevel)
{
logMessage(message);
}
}
示例4: write
void Appender::write(LogMessage& message)
{
if (!level || level > message.level)
return;
message.prefix.clear();
if (flags & APPENDER_FLAGS_PREFIX_TIMESTAMP)
message.prefix.append(message.getTimeStr());
if (flags & APPENDER_FLAGS_PREFIX_LOGLEVEL)
{
if (!message.prefix.empty())
message.prefix.push_back(' ');
char text[MAX_QUERY_LEN];
snprintf(text, MAX_QUERY_LEN, "%-5s", Appender::getLogLevelString(message.level));
message.prefix.append(text);
}
if (flags & APPENDER_FLAGS_PREFIX_LOGFILTERTYPE)
{
if (!message.prefix.empty())
message.prefix.push_back(' ');
message.prefix.push_back('[');
message.prefix.append(message.type);
message.prefix.push_back(']');
}
if (!message.prefix.empty())
message.prefix.push_back(' ');
_write(message);
}
示例5: handleMessage
void StandardLogHandler::handleMessage(
const LogMessage& message,
const LogCategory* handlerCategory) {
if (message.getLevel() < getLevel()) {
return;
}
writer_->writeMessage(formatter_->formatMessage(message, handlerCategory));
}
示例6: add
// ajoute un message de log dans un fichier, et écriture dans la console
void LogSystem::add(LogMessage log) {
QTextStream cout(stdout, QIODevice::WriteOnly);
QFile fichier("fichierDeLog.txt");
// ouverture en mode Append, pour écrire à la fin.
fichier.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
QTextStream flux(&fichier);
QString tmp = log.toString().c_str();
// écriture du log dans le fichier
flux << tmp << "\n";
// éciture du log sur la console
cout << "Ecriture dans le fichier de log : " << log.toString().c_str() << endl;
fichier.close();
}
示例7: messagePrefix
std::string FileLogHandler::messagePrefix(const LogMessage & message)
{
std::string prefix = levelString(message.level());
if (!message.context().empty())
{
if (!prefix.empty())
prefix = prefix + " ";
prefix = prefix + "[" + message.context() + "]";
}
if (prefix.empty())
return prefix;
return prefix + ": ";
}
示例8: TEST
TEST(LogMessagePoolTests, GetAndRelease) {
static const size_t INITIAL_CAPACITY=128;
static const size_t MAX_CAPACITY= 1024;
static const size_t MAX_RETURNED_MESSAGE_SIZE= 256;
static const size_t INITIAL_POOL_SIZE= 4;
static const size_t MAX_POOL_SIZE= 8;
TestingLogMessagePool factory(INITIAL_CAPACITY, MAX_CAPACITY,
MAX_RETURNED_MESSAGE_SIZE, INITIAL_POOL_SIZE,
MAX_POOL_SIZE);
std::vector<LogMessage*> messagesInPool;
std::vector<LogMessage*> newMessagesInPool;
LogMessage* msg;
messagesInPool.reserve(INITIAL_POOL_SIZE);
factory.getMessagesInPool(std::back_inserter(messagesInPool));
EXPECT_EQ(messagesInPool.size(), INITIAL_POOL_SIZE);
msg= factory.get();
EXPECT_EQ(msg->capacity(), factory.initialMessageSize());
EXPECT_EQ(msg->maxCapacity(), factory.maxMessageSize());
EXPECT_TRUE(msg->empty());
// Verify the message came from the pool
EXPECT_EQ(factory.numMessagesInPool(), INITIAL_POOL_SIZE-1);
EXPECT_TRUE(std::find(messagesInPool.begin(), messagesInPool.end(), msg) != messagesInPool.end());
// Verify the message returned to the pool
factory.release(msg);
EXPECT_EQ(factory.numMessagesInPool(), INITIAL_POOL_SIZE);
factory.getMessagesInPool(std::back_inserter(newMessagesInPool));
std::sort(messagesInPool.begin(), messagesInPool.end());
std::sort(newMessagesInPool.begin(), newMessagesInPool.end());
if (messagesInPool != newMessagesInPool) {
std::ostringstream details;
details << "messagesInPool != newMessagesInPool\n messagesInPool = [ "
<< join(messagesInPool.begin(), messagesInPool.end(), ", ")
<< " ]\n newMessagesInPool = [ "
<< join(newMessagesInPool.begin(), newMessagesInPool.end(), ", ")
<< " ]";
EXPECT_TRUE(false) << details.str();
}
}
示例9: log
void Console::log(const LogMessage& message) {
if (message.string().empty())
return;
logToDebug(message);
logToFile(message);
if (m_textCtrl != NULL)
logToConsole(message);
else
m_buffer.push_back(message);
}
示例10: logToStdOut
// Format and print the message
// =============================================================================================
void LoggerFactory::logToStdOut(const LogMessage& message)
{
std::stringstream ss(message.toString());
std::string line;
while (std::getline(ss, line, '\n'))
{
line += "\n";
std::printf(line.c_str());
}
}
示例11: logToConsole
void Console::logToConsole(const LogMessage& message) {
long start = m_textCtrl->GetLastPosition();
m_textCtrl->AppendText(message.string());
m_textCtrl->AppendText("\n");
long end = m_textCtrl->GetLastPosition();
switch (message.level()) {
case LLDebug:
m_textCtrl->SetStyle(start, end, wxTextAttr(*wxLIGHT_GREY, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa
break;
case LLInfo:
m_textCtrl->SetStyle(start, end, wxTextAttr(*wxWHITE, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa
break;
case LLWarn:
m_textCtrl->SetStyle(start, end, wxTextAttr(*wxYELLOW, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa
break;
case LLError:
m_textCtrl->SetStyle(start, end, wxTextAttr(*wxRED, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa
break;
}
}
示例12: DoesMatch
bool LogFilterRegex::DoesMatch(const LogMessage &message) const {
switch (m_filter_target) {
case eFilterTargetActivity:
// Empty fields never match a condition.
if (!message.HasActivity())
return false;
return ::regexec(&m_regex, message.GetActivity(), 0, nullptr, 0) == 0;
case eFilterTargetActivityChain:
// Empty fields never match a condition.
if (!message.HasActivity())
return false;
return ::regexec(&m_regex, message.GetActivityChain().c_str(), 0, nullptr,
0) == 0;
case eFilterTargetCategory:
// Empty fields never match a condition.
if (!message.HasCategory())
return false;
return ::regexec(&m_regex, message.GetCategory(), 0, nullptr, 0) == 0;
case eFilterTargetMessage: {
const char *message_text = message.GetMessage();
if (!message_text) {
DNBLogThreadedIf(LOG_DARWIN_LOG,
"LogFilterRegex: regex "
"\"%s\" no match due to nullptr message.",
m_regex_text.c_str());
return false;
}
bool match = ::regexec(&m_regex, message_text, 0, nullptr, 0) == 0;
DNBLogThreadedIf(LOG_DARWIN_LOG, "LogFilterRegex: regex "
"\"%s\" %s message \"%s\".",
m_regex_text.c_str(), match ? "matches" : "does not match",
message_text);
return match;
}
case eFilterTargetSubsystem:
// Empty fields never match a condition.
if (!message.HasSubsystem())
return false;
return ::regexec(&m_regex, message.GetSubsystem(), 0, nullptr, 0) == 0;
default:
// We don't know this type.
return false;
}
}
示例13: log
void LogManager::log(LogMessage msg)
{
//don't do any formatting changes or filtering to the TTY output since we
//use the raw output to do diffs with the output of a real PS3 and some
//programs write text in single bytes to the console
if (msg.mType != TTY)
{
std::string prefix;
switch (msg.mServerity)
{
case Success:
prefix = "S ";
break;
case Notice:
prefix = "! ";
break;
case Warning:
prefix = "W ";
break;
case Error:
prefix = "E ";
break;
}
if (NamedThreadBase* thr = GetCurrentNamedThread())
{
prefix += "{" + thr->GetThreadName() + "} ";
}
msg.mText.insert(0, prefix);
msg.mText.append(1,'\n');
}
#ifdef BUFFERED_LOGGING
size_t size = msg.size();
std::vector<char> temp_buffer(size);
msg.serialize(temp_buffer.data());
mBuffer.pushRange(temp_buffer.begin(), temp_buffer.end());
mBufferReady.notify_one();
#else
mChannels[static_cast<u32>(msg.mType)].log(msg);
#endif
}
示例14: _write
void AppenderFile::_write(LogMessage const& message)
{
bool exceedMaxSize = maxFileSize > 0 && (fileSize.value() + message.Size()) > maxFileSize;
if (dynamicName)
{
char namebuf[TRINITY_PATH_MAX];
snprintf(namebuf, TRINITY_PATH_MAX, filename.c_str(), message.param1.c_str());
logfile = OpenFile(namebuf, mode, backup || exceedMaxSize);
}
else if (exceedMaxSize)
logfile = OpenFile(filename, "w", true);
if (!logfile)
return;
fprintf(logfile, "%s%s", message.prefix.c_str(), message.text.c_str());
fflush(logfile);
fileSize += uint64(message.Size());
if (dynamicName)
CloseFile();
}
示例15: admitMessage
void LogCategory::admitMessage(const LogMessage& message) const {
processMessage(message);
// If this is a fatal message, flush the handlers to make sure the log
// message was written out, then crash.
if (isLogLevelFatal(message.getLevel())) {
auto numHandlers = db_->flushAllHandlers();
if (numHandlers == 0) {
// No log handlers were configured.
// Print the message to stderr, to make sure we always print the reason
// we are crashing somewhere.
auto msg = folly::to<std::string>(
"FATAL:",
message.getFileName(),
":",
message.getLineNumber(),
": ",
message.getMessage(),
"\n");
folly::writeFull(STDERR_FILENO, msg.data(), msg.size());
}
std::abort();
}
}