本文整理汇总了C++中AppenderConsole::InitColors方法的典型用法代码示例。如果您正苦于以下问题:C++ AppenderConsole::InitColors方法的具体用法?C++ AppenderConsole::InitColors怎么用?C++ AppenderConsole::InitColors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppenderConsole
的用法示例。
在下文中一共展示了AppenderConsole::InitColors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateAppenderFromConfig
void Log::CreateAppenderFromConfig(const char* name)
{
if (!name || *name == '\0')
return;
// Format=type,level,flags,optional1,optional2
// if type = File. optional1 = file and option2 = mode
// if type = Console. optional1 = Color
std::string options = "Appender.";
options.append(name);
options = ConfigMgr::GetStringDefault(options.c_str(), "");
Tokenizer tokens(options, ',');
Tokenizer::const_iterator iter = tokens.begin();
if (tokens.size() < 2)
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Wrong configuration for appender %s. Config line: %s\n", name, options.c_str());
return;
}
AppenderFlags flags = APPENDER_FLAGS_NONE;
AppenderType type = AppenderType(atoi(*iter));
++iter;
LogLevel level = LogLevel(atoi(*iter));
if (level > LOG_LEVEL_FATAL)
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Wrong Log Level %d for appender %s\n", level, name);
return;
}
if (++iter != tokens.end())
flags = AppenderFlags(atoi(*iter));
switch (type)
{
case APPENDER_CONSOLE:
{
AppenderConsole* appender = new AppenderConsole(NextAppenderId(), name, level, flags);
appenders[appender->getId()] = appender;
if (++iter != tokens.end())
appender->InitColors(*iter);
//fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type CONSOLE, Mask %u\n", appender->getName().c_str(), appender->getId(), appender->getLogLevel()); // DEBUG - RemoveMe
break;
}
case APPENDER_FILE:
{
std::string filename;
std::string mode = "a";
if (++iter == tokens.end())
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Missing file name for appender %s\n", name);
return;
}
filename = *iter;
if (++iter != tokens.end())
mode = *iter;
if (flags & APPENDER_FLAGS_USE_TIMESTAMP)
{
size_t dot_pos = filename.find_last_of(".");
if (dot_pos != filename.npos)
filename.insert(dot_pos, m_logsTimestamp);
else
filename += m_logsTimestamp;
}
uint8 id = NextAppenderId();
appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), flags);
//fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type FILE, Mask %u, File %s, Mode %s\n", name, id, level, filename.c_str(), mode.c_str()); // DEBUG - RemoveMe
break;
}
case APPENDER_DB:
{
uint8 id = NextAppenderId();
appenders[id] = new AppenderDB(id, name, level, realm);
break;
}
default:
fprintf(stderr, "Log::CreateAppenderFromConfig: Unknown type %d for appender %s\n", type, name);
break;
}
}
示例2: CreateAppenderFromConfig
void Log::CreateAppenderFromConfig(std::string const& appenderName)
{
if (appenderName.empty())
return;
// Format=type, level, flags, optional1, optional2
// if type = File. optional1 = file and option2 = mode
// if type = Console. optional1 = Color
std::string options = sConfigMgr->GetStringDefault(appenderName.c_str(), "");
Tokenizer tokens(options, ',');
Tokenizer::const_iterator iter = tokens.begin();
size_t size = tokens.size();
std::string name = appenderName.substr(9);
if (size < 2)
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Wrong configuration for appender %s. Config line: %s\n", name.c_str(), options.c_str());
return;
}
AppenderFlags flags = APPENDER_FLAGS_NONE;
AppenderType type = AppenderType(atoi(*iter++));
LogLevel level = LogLevel(atoi(*iter++));
if (level > LOG_LEVEL_FATAL)
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Wrong Log Level %d for appender %s\n", level, name.c_str());
return;
}
if (size > 2)
flags = AppenderFlags(atoi(*iter++));
switch (type)
{
case APPENDER_CONSOLE:
{
AppenderConsole* appender = new AppenderConsole(NextAppenderId(), name, level, flags);
appenders[appender->getId()] = appender;
if (size > 3)
appender->InitColors(*iter++);
//fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type CONSOLE, Mask %u\n", appender->getName().c_str(), appender->getId(), appender->getLogLevel());
break;
}
case APPENDER_FILE:
{
std::string filename;
std::string mode = "a";
if (size < 4)
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Missing file name for appender %s\n", name.c_str());
return;
}
filename = *iter++;
if (size > 4)
mode = *iter++;
if (flags & APPENDER_FLAGS_USE_TIMESTAMP)
{
size_t dot_pos = filename.find_last_of(".");
if (dot_pos != filename.npos)
filename.insert(dot_pos, m_logsTimestamp);
else
filename += m_logsTimestamp;
}
uint64 maxFileSize = 0;
if (size > 5)
maxFileSize = atoi(*iter++);
uint8 id = NextAppenderId();
appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), flags, maxFileSize);
//fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type FILE, Mask %u, File %s, Mode %s\n", name.c_str(), id, level, filename.c_str(), mode.c_str());
break;
}
case APPENDER_DB:
{
uint8 id = NextAppenderId();
appenders[id] = new AppenderDB(id, name, level);
break;
}
default:
fprintf(stderr, "Log::CreateAppenderFromConfig: Unknown type %d for appender %s\n", type, name.c_str());
break;
}
}