コード例 #1
0
LevelPtr OptionConverter::toLevel(const LogString& value,
        const LevelPtr& defaultValue)
{
    size_t hashIndex = value.find(LOG4CXX_STR("#"));

        if (hashIndex == LogString::npos)
        {
                if (value.empty())
                {
                        return defaultValue;
                }
                else
                {
                        LogLog::debug(
                ((LogString) LOG4CXX_STR("OptionConverter::toLevel: no class name specified, level=["))
                         + value
                         +LOG4CXX_STR("]"));
                        // no class name specified : use standard Level class
                        return Level::toLevelLS(value, defaultValue);
                }
        }

        LogString clazz = value.substr(hashIndex + 1);
        LogString levelName = value.substr(0, hashIndex);
        LogLog::debug(((LogString) LOG4CXX_STR("OptionConverter::toLevel: class=["))
           + clazz + LOG4CXX_STR("], level=[") + levelName + LOG4CXX_STR("]"));

        // This is degenerate case but you never know.
        if (levelName.empty())
        {
                return Level::toLevelLS(value, defaultValue);
        }

        try
        {
                Level::LevelClass& levelClass =
                        (Level::LevelClass&)Loader::loadClass(clazz);
                return levelClass.toLevel(levelName);
        }
        catch (ClassNotFoundException&)
        {
                LogLog::warn(((LogString) LOG4CXX_STR("custom level class ["))
                   + clazz + LOG4CXX_STR("] not found."));
        }
        catch(Exception& oops)
        {
                LogLog::warn(
                        LOG4CXX_STR("class [") + clazz + LOG4CXX_STR("], level [") + levelName +
                        LOG4CXX_STR("] conversion) failed."), oops);
        }
        catch(...)
        {
                LogLog::warn(
                        LOG4CXX_STR("class [") + clazz + LOG4CXX_STR("], level [") + levelName +
                        LOG4CXX_STR("] conversion) failed."));
        }

        return defaultValue;
}
コード例 #2
0
void Logger::l7dlog(const LevelPtr& level1, const LogString& key,
                    const LocationInfo& location, const std::vector<LogString>& params) const
{
        if (repository == 0 || repository->isDisabled(level1->toInt()))
        {
                return;
        }

        if (level1->isGreaterOrEqual(getEffectiveLevel()))
        {
                LogString pattern = getResourceBundleString(key);
                LogString msg;

                if (pattern.empty())
                {
                        msg = key;
                }
                else
                {
                        msg = StringHelper::format(pattern, params);
                }

                forcedLogLS(level1, msg, location);
        }
}
コード例 #3
0
//-------------------------------------------------------------------------------------
LevelPtr ScriptLevel::toLevelLS(const LogString& sArg, const LevelPtr& defaultLevel)
{
   if (sArg.empty())
    {
       return defaultLevel;
    }

    if (StringHelper::equalsIgnoreCase(sArg,
          LOG4CXX_STR("SCRIPT"), LOG4CXX_STR("script"))) {
      return getScript();
    }
    else if (StringHelper::equalsIgnoreCase(sArg,
          LOG4CXX_STR("S_INFO"), LOG4CXX_STR("s_info"))) {
      return getScriptInfo();
    }
    else if (StringHelper::equalsIgnoreCase(sArg,
          LOG4CXX_STR("S_WAR"), LOG4CXX_STR("s_war"))) {
      return getScriptWarning();
    }
    else if (StringHelper::equalsIgnoreCase(sArg,
          LOG4CXX_STR("S_ERR"), LOG4CXX_STR("s_err"))) {
      return getScriptError();
    }
    else if (StringHelper::equalsIgnoreCase(sArg,
          LOG4CXX_STR("S_DBG"), LOG4CXX_STR("s_dbg"))) {
      return getScriptDebug();
    }

    return Level::toLevel(sArg, defaultLevel);
}
コード例 #4
0
 bool get(LogString& in, logchar& c)
 {
         if (in.empty()) {
             c = 0;
             return false;
         }
         c = in[0];
         in.erase(in.begin());
         return true;
 }
コード例 #5
0
void Logger::removeAppender(const LogString& name1)
{
        synchronized sync(mutex);

        if(name1.empty() || aai == 0)
        {
                return;
        }

        aai->removeAppender(name1);
}
コード例 #6
0
AppenderPtr Logger::getAppender(const LogString& name1) const
{
        synchronized sync(mutex);

        if (aai == 0 || name1.empty())
        {
                return 0;
        }

        return aai->getAppender(name1);
}
コード例 #7
0
LogString OptionConverter::getSystemProperty(const LogString& key, const LogString& def)
{
        if (!key.empty())
        {
                LogString value(System::getProperty(key));

                if (!value.empty())
                {
                        return value;
                }
        }
        return def;
}
コード例 #8
0
void PropertySetter::setProperty(const LogString& option,
                                 const LogString& value,
                                 Pool&)
{
        if (value.empty())
                return;

        if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
        {
                LogLog::debug(LOG4CXX_STR("Setting option name=[") +
                        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
                OptionHandlerPtr(obj)->setOption(option, value);
        }
}
コード例 #9
0
ファイル: script_loglevel.cpp プロジェクト: zgpxgame/kbengine
LevelPtr ScriptLevel::toLevelLS(const LogString& sArg, const LevelPtr& defaultLevel)
{
   if (sArg.empty())
    {
       return defaultLevel;
    }

    if (StringHelper::equalsIgnoreCase(sArg,
          LOG4CXX_STR("SCRIPT"), LOG4CXX_STR("script"))) {
      return getScript();
    }

    return Level::toLevel(sArg, defaultLevel);
}
コード例 #10
0
void OptionConverter::selectAndConfigure(const File& configFileName,
         const LogString& _clazz, spi::LoggerRepositoryPtr& hierarchy)
{
        ConfiguratorPtr configurator;
        LogString clazz = _clazz;

        LogString filename(configFileName.getPath());
        if(clazz.empty() 
                && filename.length() > 4
                && StringHelper::equalsIgnoreCase(
                   filename.substr(filename.length() -4), 
                   LOG4CXX_STR(".XML"), LOG4CXX_STR(".xml")))
        {
            clazz = log4cxx::xml::DOMConfigurator::getStaticClass().toString();
        }

        if(!clazz.empty())
        {
                LogLog::debug(LOG4CXX_STR("Preferred configurator class: ") + clazz);
                configurator = instantiateByClassName(clazz,
                        Configurator::getStaticClass(),
                        0);
                if(configurator == 0)
                {
                        LogLog::error(LOG4CXX_STR("Could not instantiate configurator [")
                                 + clazz + LOG4CXX_STR("]."));
                        return;
                }
        }
        else
        {
                configurator = new PropertyConfigurator();
        }

        configurator->doConfigure(configFileName, hierarchy);
}
コード例 #11
0
void SyslogAppender::setFacility(const LogString& facilityName)
{
        if (facilityName.empty())
        {
                return;
        }

        syslogFacility = getFacility(facilityName);
        if (syslogFacility == LOG_UNDEF)
        {
                LogLog::error(LOG4CXX_STR("[")+facilityName +
                                LOG4CXX_STR("] is an unknown syslog facility. Defaulting to [USER]."));
                syslogFacility = LOG_USER;
        }

        this->initSyslogFacilityStr();
}
コード例 #12
0
void SyslogAppender::setSyslogHost(const LogString& syslogHost1)
{
        if (this->sw != 0)
        {
                delete this->sw;
                this->sw = 0;
        }

// On the local host, we can directly use the system function 'syslog'
// if it is available (cf. append)
#if LOG4CXX_HAVE_SYSLOG
        if (syslogHost1 != LOG4CXX_STR("localhost") && syslogHost1 != LOG4CXX_STR("127.0.0.1")
        && !syslogHost1.empty())
#endif
                this->sw = new SyslogWriter(syslogHost1);

        this->syslogHost = syslogHost1;
}
コード例 #13
0
void AppenderAttachableImpl::removeAppender(const LogString& name)
{
        if (name.empty())
        {
                return;
        }

        AppenderList::iterator it, itEnd = appenderList.end();
        AppenderPtr appender;
        for(it = appenderList.begin(); it != itEnd; it++)
        {
                appender = *it;
                if(name == appender->getName())
                {
                        appenderList.erase(it);
                        return;
                }
        }
}
コード例 #14
0
AppenderPtr AppenderAttachableImpl::getAppender(const LogString& name) const
{
        if (name.empty())
        {
                return 0;
        }

        AppenderList::const_iterator it, itEnd = appenderList.end();
        AppenderPtr appender;
        for(it = appenderList.begin(); it != itEnd; it++)
        {
                appender = *it;
                if(name == appender->getName())
                {
                        return appender;
                }
        }

        return 0;
}
コード例 #15
0
long OptionConverter::toFileSize(const LogString& s, long dEfault)
{
        if(s.empty())
        {
                return dEfault;
        }

        size_t index = s.find_first_of(LOG4CXX_STR("bB"));
        if (index != LogString::npos && index > 0) {
          long multiplier = 1;
          index--;
          if (s[index] == 0x6B /* 'k' */ || s[index] == 0x4B /* 'K' */) {
                multiplier = 1024;
          } else if(s[index] == 0x6D /* 'm' */ || s[index] == 0x4D /* 'M' */) {
                multiplier = 1024*1024;
          } else if(s[index] == 0x67 /* 'g'*/ || s[index] == 0x47 /* 'G' */) {
                multiplier = 1024*1024*1024;
          }
          return toInt(s.substr(0, index), 1) * multiplier;
        }

        return toInt(s, 1);
}
コード例 #16
0
ObjectPtr OptionConverter::instantiateByClassName(const LogString& className,
        const Class& superClass, const ObjectPtr& defaultValue)
{
        if(!className.empty())
        {
                try
                {
                        const Class& classObj = Loader::loadClass(className);
                        ObjectPtr newObject =  classObj.newInstance();
                        if (!newObject->instanceof(superClass))
                        {
                                return defaultValue;
                        }

                        return newObject;
                }
                catch (Exception& e)
                {
                        LogLog::error(LOG4CXX_STR("Could not instantiate class [") +
                                className + LOG4CXX_STR("]."), e);
                }
        }
        return defaultValue;
}