📄 domconfigurator.cpp
字号:
if (className.empty())
{
logger->setLevel(OptionConverter::toLevel(levelStr, Level::getDebug()));
}
else
{
LogLog::debug(LOG4CXX_STR("Desired Level sub-class: [") + className + LOG4CXX_STR("]"));
try
{
Level::LevelClass& levelClass =
(Level::LevelClass&)Loader::loadClass(className);
LevelPtr level = levelClass.toLevel(levelStr);
logger->setLevel(level);
}
catch (Exception& oops)
{
LogLog::error(
LOG4CXX_STR("Could not create level [") + levelStr +
LOG4CXX_STR("]. Reported error follows."),
oops);
return;
}
catch (...)
{
LogLog::error(
LOG4CXX_STR("Could not create level [") + levelStr);
return;
}
}
}
LogLog::debug(loggerName + LOG4CXX_STR(" level set to ") +
logger->getEffectiveLevel()->toString());
}
void DOMConfigurator::setParameter(log4cxx::helpers::Pool& p,
log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
apr_xml_elem* elem,
PropertySetter& propSetter)
{
LogString name(subst(getAttribute(utf8Decoder, elem, NAME_ATTR)));
LogString value(subst(getAttribute(utf8Decoder, elem, VALUE_ATTR)));
value = subst(value);
propSetter.setProperty(name, value, p);
}
void DOMConfigurator::doConfigure(const File& filename, spi::LoggerRepositoryPtr& repository1)
{
repository1->setConfigured(true);
this->repository = repository1;
LogString msg(LOG4CXX_STR("DOMConfigurator configuring file "));
msg.append(filename.getPath());
msg.append(LOG4CXX_STR("..."));
LogLog::debug(msg);
loggerFactory = new DefaultLoggerFactory();
Pool p;
apr_file_t *fd;
log4cxx_status_t rv = filename.open(&fd, APR_READ, APR_OS_DEFAULT, p);
if (rv != APR_SUCCESS) {
LogString msg2(LOG4CXX_STR("Could not open file ["));
msg2.append(filename.getPath());
msg2.append(LOG4CXX_STR("]."));
LogLog::error(msg2);
} else {
apr_xml_parser *parser;
apr_xml_doc *doc;
rv = apr_xml_parse_file(p.getAPRPool(), &parser, &doc, fd, 2000);
if (rv != APR_SUCCESS) {
char errbuf[2000];
char errbufXML[2000];
LogString msg2(LOG4CXX_STR("Error parsing file ["));
msg2.append(filename.getPath());
msg2.append(LOG4CXX_STR("], "));
apr_strerror(rv, errbuf, sizeof(errbuf));
LOG4CXX_DECODE_CHAR(lerrbuf, std::string(errbuf));
apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML));
LOG4CXX_DECODE_CHAR(lerrbufXML, std::string(errbufXML));
msg2.append(lerrbuf);
msg2.append(lerrbufXML);
LogLog::error(msg2);
} else {
AppenderMap appenders;
CharsetDecoderPtr utf8Decoder(CharsetDecoder::getUTF8Decoder());
parse(p, utf8Decoder, doc->root, doc, appenders);
}
}
}
void DOMConfigurator::configure(const std::string& filename)
{
// File file(filename);
// DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#if LOG4CXX_WCHAR_T_API
void DOMConfigurator::configure(const std::wstring& filename)
{
// File file(filename);
// DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#endif
#if LOG4CXX_UNICHAR_API
void DOMConfigurator::configure(const std::basic_string<UniChar>& filename)
{
// File file(filename);
// DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#endif
#if LOG4CXX_CFSTRING_API
void DOMConfigurator::configure(const CFStringRef& filename)
{
// File file(filename);
// DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#endif
void DOMConfigurator::configureAndWatch(const std::string& filename)
{
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#if LOG4CXX_WCHAR_T_API
void DOMConfigurator::configureAndWatch(const std::wstring& filename)
{
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#endif
#if LOG4CXX_UNICHAR_API
void DOMConfigurator::configureAndWatch(const std::basic_string<UniChar>& filename)
{
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#endif
#if LOG4CXX_CFSTRING_API
void DOMConfigurator::configureAndWatch(const CFStringRef& filename)
{
configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
}
#endif
void DOMConfigurator::configureAndWatch(const std::string& filename, long delay)
{
File file(filename);
#if APR_HAS_THREADS
XMLWatchdog * xdog = new XMLWatchdog(file);
xdog->setDelay(delay);
xdog->start();
#else
DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif
}
#if LOG4CXX_WCHAR_T_API
void DOMConfigurator::configureAndWatch(const std::wstring& filename, long delay)
{
File file(filename);
#if APR_HAS_THREADS
XMLWatchdog * xdog = new XMLWatchdog(file);
xdog->setDelay(delay);
xdog->start();
#else
DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif
}
#endif
#if LOG4CXX_UNICHAR_API
void DOMConfigurator::configureAndWatch(const std::basic_string<UniChar>& filename, long delay)
{
File file(filename);
#if APR_HAS_THREADS
XMLWatchdog * xdog = new XMLWatchdog(file);
xdog->setDelay(delay);
xdog->start();
#else
DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif
}
#endif
#if LOG4CXX_CFSTRING_API
void DOMConfigurator::configureAndWatch(const CFStringRef& filename, long delay)
{
File file(filename);
#if APR_HAS_THREADS
XMLWatchdog * xdog = new XMLWatchdog(file);
xdog->setDelay(delay);
xdog->start();
#else
DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif
}
#endif
void DOMConfigurator::parse(
Pool& p,
log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
apr_xml_elem* element,
apr_xml_doc* doc,
AppenderMap& appenders)
{
std::string rootElementName(element->name);
if (rootElementName != CONFIGURATION_TAG)
{
if(rootElementName == OLD_CONFIGURATION_TAG)
{
//LogLog::warn(LOG4CXX_STR("The <")+String(OLD_CONFIGURATION_TAG)+
// LOG4CXX_STR("> element has been deprecated."));
//LogLog::warn(LOG4CXX_STR("Use the <")+String(CONFIGURATION_TAG)+
// LOG4CXX_STR("> element instead."));
}
else
{
LogLog::error(LOG4CXX_STR("DOM element is - not a <configuration> element."));
return;
}
}
LogString debugAttrib = subst(getAttribute(utf8Decoder, element, INTERNAL_DEBUG_ATTR));
static const LogString NuLL(LOG4CXX_STR("NULL"));
LogLog::debug(LOG4CXX_STR("debug attribute= \"") + debugAttrib +LOG4CXX_STR("\"."));
// if the log4j.dtd is not specified in the XML file, then the
// "debug" attribute is returned as the empty string.
if(!debugAttrib.empty() && debugAttrib != NuLL)
{
LogLog::setInternalDebugging(OptionConverter::toBoolean(debugAttrib, true));
}
else
{
LogLog::debug(LOG4CXX_STR("Ignoring internalDebug attribute."));
}
LogString confDebug = subst(getAttribute(utf8Decoder, element, CONFIG_DEBUG_ATTR));
if(!confDebug.empty() && confDebug != NuLL)
{
LogLog::warn(LOG4CXX_STR("The \"configDebug\" attribute is deprecated."));
LogLog::warn(LOG4CXX_STR("Use the \"internalDebug\" attribute instead."));
LogLog::setInternalDebugging(OptionConverter::toBoolean(confDebug, true));
}
LogString thresholdStr = subst(getAttribute(utf8Decoder, element, THRESHOLD_ATTR));
LogLog::debug(LOG4CXX_STR("Threshold =\"") + thresholdStr +LOG4CXX_STR("\"."));
if(!thresholdStr.empty() && thresholdStr != NuLL)
{
repository->setThreshold(thresholdStr);
}
apr_xml_elem* currentElement;
for(currentElement = element->first_child;
currentElement;
currentElement = currentElement->next) {
std::string tagName(currentElement->name);
if (tagName == CATEGORY_FACTORY_TAG)
{
parseLoggerFactory(p, utf8Decoder, currentElement);
}
}
for(currentElement = element->first_child;
currentElement;
currentElement = currentElement->next) {
std::string tagName(currentElement->name);
if (tagName == CATEGORY || tagName == LOGGER)
{
parseLogger(p, utf8Decoder, currentElement, doc, appenders);
}
else if (tagName == ROOT_TAG)
{
parseRoot(p, utf8Decoder, currentElement, doc, appenders);
}
}
}
LogString DOMConfigurator::subst(const LogString& value)
{
try
{
return OptionConverter::substVars(value, props);
}
catch(IllegalArgumentException& e)
{
LogLog::warn(LOG4CXX_STR("Could not perform variable substitution."), e);
return value;
}
}
LogString DOMConfigurator::getAttribute(
log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
apr_xml_elem* element,
const std::string& attrName) {
LogString attrValue;
for(apr_xml_attr* attr = element->attr;
attr;
attr = attr->next) {
if (attrName == attr->name) {
ByteBuffer buf((char*) attr->value, strlen(attr->value));
utf8Decoder->decode(buf, attrValue);
}
}
return attrValue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -