本文整理汇总了C++中Appender::requiresLayout方法的典型用法代码示例。如果您正苦于以下问题:C++ Appender::requiresLayout方法的具体用法?C++ Appender::requiresLayout怎么用?C++ Appender::requiresLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Appender
的用法示例。
在下文中一共展示了Appender::requiresLayout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: instantiateAppender
Appender* PropertyConfiguratorImpl::instantiateAppender(const std::string& appenderName) {
Appender* appender = NULL;
std::string appenderPrefix = std::string("appender.") + appenderName;
// determine the type by the appenderName
Properties::iterator key = _properties.find(appenderPrefix);
if (key == _properties.end())
throw ConfigureFailure(std::string("Appender '") + appenderName + "' not defined");
std::string::size_type length = (*key).second.find_last_of(".");
std::string appenderType = (length == std::string::npos) ?
(*key).second : (*key).second.substr(length+1);
// and instantiate the appropriate object
if (appenderType == "ConsoleAppender") {
appender = new OstreamAppender(appenderName, &std::cout);
}
else if (appenderType == "FileAppender") {
std::string fileName = _properties.getString(appenderPrefix + ".fileName", "foobar");
bool append = _properties.getBool(appenderPrefix + ".append", true);
appender = new FileAppender(appenderName, fileName, append);
}
else if (appenderType == "RollingFileAppender") {
std::string fileName = _properties.getString(appenderPrefix + ".fileName", "foobar");
size_t maxFileSize = _properties.getInt(appenderPrefix + ".maxFileSize", 10*1024*1024);
int maxBackupIndex = _properties.getInt(appenderPrefix + ".maxBackupIndex", 1);
bool append = _properties.getBool(appenderPrefix + ".append", true);
appender = new RollingFileAppender(appenderName, fileName, maxFileSize, maxBackupIndex,
append);
}
else if (appenderType == "GenerationalFileAppender") {
std::string fileName = _properties.getString(appenderPrefix + ".fileName", "foobar");
bool append = _properties.getBool(appenderPrefix + ".append", true);
appender = new GenerationalFileAppender(appenderName, fileName, append);
}
else if (appenderType == "SyslogAppender") {
std::string syslogName = _properties.getString(appenderPrefix + ".syslogName", "syslog");
std::string syslogHost = _properties.getString(appenderPrefix + ".syslogHost", "localhost");
int facility = _properties.getInt(appenderPrefix + ".facility", -1) * 8; // * 8 to get LOG_KERN, etc. compatible values.
int portNumber = _properties.getInt(appenderPrefix + ".portNumber", -1);
appender = new RemoteSyslogAppender(appenderName, syslogName,
syslogHost, facility, portNumber);
}
#ifdef LOG4CPP_HAVE_SYSLOG
else if (appenderType == "LocalSyslogAppender") {
std::string syslogName = _properties.getString(appenderPrefix + ".syslogName", "syslog");
int facility = _properties.getInt(appenderPrefix + ".facility", -1) * 8; // * 8 to get LOG_KERN, etc. compatible values.
appender = new SyslogAppender(appenderName, syslogName, facility);
}
#endif // LOG4CPP_HAVE_SYSLOG
else if (appenderType == "AbortAppender") {
appender = new AbortAppender(appenderName);
}
#ifdef LOG4CPP_HAVE_LIBIDSA
else if (appenderType == "IdsaAppender") {
// default idsa name ???
std::string idsaName = _properties.getString(appenderPrefix + ".idsaName", "foobar");
appender = new IdsaAppender(appenderName, idsaname);
}
#endif // LOG4CPP_HAVE_LIBIDSA
#ifdef WIN32
// win32 debug appender
else if (appenderType == "Win32DebugAppender") {
appender = new Win32DebugAppender(appenderName);
}
// win32 NT event log appender
else if (appenderType == "NTEventLogAppender") {
std::string source = _properties.getString(appenderPrefix + ".source", "foobar");
appender = new NTEventLogAppender(appenderName, source);
}
#endif // WIN32
else {
throw ConfigureFailure(std::string("Appender '") + appenderName +
"' has unknown type '" + appenderType + "'");
}
if (appender->requiresLayout()) {
setLayout(appender, appenderName);
}
// set threshold
std::string thresholdName = _properties.getString(appenderPrefix + ".threshold", "");
try {
if (thresholdName != "") {
appender->setThreshold(Priority::getPriorityValue(thresholdName));
}
} catch(std::invalid_argument& e) {
throw ConfigureFailure(std::string(e.what()) +
" for threshold of appender '" + appenderName + "'");
}
return appender;
}