本文整理汇总了C++中Appender类的典型用法代码示例。如果您正苦于以下问题:C++ Appender类的具体用法?C++ Appender怎么用?C++ Appender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Appender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: snprintf
Appender * NetAppender::getAppender(com_device_t &dev)
{
char name[1024];
snprintf(name, sizeof(name), "NET:%s/%s", dev.host, dev.file);
Appender *app = (Appender *)comlog_get_nameMg()->get(type_appender, name);
if (app == NULL) {
_com_debug("create net appender %s", name);
app = new NetAppender;
app->setDeviceInfo(dev);
_com_debug("try to open the netappender[%s]", name);
if (app->open(NULL) != 0) {
_com_error("sorry failt to open %s", name);
delete app;
return NULL;
}
com_device_t dev2;
if (deviceNetToFile(dev, dev2) == 0) {
app->_bkappender = FileAppender::getAppender(dev2);
//assert (app->_bkappender);
//
if (app->_bkappender != NULL) {
app->_bkappender->setLayout(dev2.layout);
app->_bkappender->_open = dev2.open;
}
}
comlog_get_nameMg()->set(name, app);
}
return app;
}
示例2: redirectLog
int CommInpCfg :: redirectLog ()
{
time_t curr_t;
struct tm *ptm;
char log_file_name[32];
time (&curr_t);
ptm = gmtime (&curr_t);
strftime (log_file_name, 32, "%Y%m%d_%H%M%S.log", ptm);
string AppLogFile(dataOpt__.WorkingPath);
AppLogFile.append("/")
.append(log_file_name);
Category& rootLogCategory = Category::getRoot();
rootLogCategory.removeAllAppenders();
Appender* appender = new FileAppender("Log", AppLogFile);
PatternLayout* patternLayout = new PatternLayout();
patternLayout->setConversionPattern("[%d{%Y:%m:%d %H:%M:%S.%I}] %p %c %x: %m%n");
Layout* layout = dynamic_cast<Layout*> (patternLayout);
appender->setLayout(layout);
cout << "Redirecting logging from stdout to : " << AppLogFile << endl;
rootLogCategory.addAppender(appender);
return 0;
}
示例3: LogLevel
bool Log::SetLogLevel(std::string const& name, const char* newLevelc, bool isLogger /* = true */)
{
LogLevel newLevel = LogLevel(atoi(newLevelc));
if (newLevel < 0)
return false;
if (isLogger)
{
LoggerMap::iterator it = loggers.begin();
while (it != loggers.end() && it->second.getName() != name)
++it;
if (it == loggers.end())
return false;
it->second.setLogLevel(newLevel);
if (newLevel != LOG_LEVEL_DISABLED && newLevel < lowestLogLevel)
lowestLogLevel = newLevel;
}
else
{
Appender* appender = GetAppenderByName(name);
if (!appender)
return false;
appender->setLogLevel(newLevel);
}
return true;
}
示例4: return
Appender * AppenderManager::getNextAppender()
{
int s = m_appenders.size();
if ( s == 1 )
return (*m_appenders.begin());
if ( s == 0 )
return NULL;
int n = m_curAppender++;
int m = -1;
Appender * p = NULL;
while( n != m_curAppender )
{
if ( n >= s )
n = 0;
p = m_appenders[n];
if (!p->isFail() )
{
if ( !p->isFull() )
{
m_curAppender = n;
return p;
}
if ( m == -1 )
m = n;
m = n;
}
++n;
}
m_curAppender = m;
return m_appenders[m];
}
示例5: RollFileAppender
Logger& Logger::get_instance( const std::string& filename, Level::LogLevel level, long size, int index )
{
if ( !logger )
{
Appender* appender = new RollFileAppender(filename.c_str(), size, index);
Filter* filter = new LevelFilter( level );
appender->tie_filter( filter );
logger = new Logger();
logger->add_appender( appender );
}
return *logger;
}
示例6: tokens
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++));
auto factoryFunction = appenderFactory.find(type);
if (factoryFunction == appenderFactory.end())
{
fprintf(stderr, "Log::CreateAppenderFromConfig: Unknown type %d for appender %s\n", type, name.c_str());
return;
}
try
{
Appender* appender = factoryFunction->second(NextAppenderId(), name, level, flags, ExtraAppenderArgs(iter, tokens.end()));
appenders[appender->getId()] = appender;
}
catch (InvalidAppenderArgsException const& iaae)
{
fprintf(stderr, "%s", iaae.what());
}
}
示例7: new
void HttpLog::init()
{
s_pLogger = Logger::getRootLogger() ;
new(achAccessLog) AccessLog("");
Appender *appender
= Appender::getAppender("stderr", "appender.ps");
Layout *layout = Layout::getLayout(ERROR_LOG_PATTERN, "layout.pattern");
layout->setUData(s_logPattern);
appender->setLayout(layout);
logger()->setLevel(Level::DEBUG);
logger()->setAppender(appender);
}
示例8: initLog4Qt
void initLog4Qt(Level level) {
Log4Qt::Layout* layout;
Appender* appender = LogManager::rootLogger()->appender("A1");
if (appender) {
logger()->debug("initLogQt: using existing appender A1");
if (level != Level::INFO_INT) {
LogManager::rootLogger()->setLevel(level);
}
layout = appender->layout();
} else {
LogManager::rootLogger()->setLevel(level);
// Create console layout
TTCCLayout* tccLayout = new TTCCLayout();
tccLayout->setName("Layout");
tccLayout->setDateFormat(TTCCLayout::ABSOLUTEDATE);
tccLayout->setThreadPrinting(false);
tccLayout->activateOptions();
// Create appender A1 for console if level set through cmd line option
if (level != Level::INFO_INT) {
ConsoleAppender* a = new ConsoleAppender(tccLayout,
ConsoleAppender::STDERR_TARGET);
a->setName("A1");
a->activateOptions();
// Set appender on root logger
LogManager::rootLogger()->addAppender(a);
}
layout = tccLayout;
}
// Let Log4Qt handle qDebug(), qWarning(), qCritical() and qFatal()
LogManager::setHandleQtMessages(true);
LogManager::qtLogger()->setLevel(Logger::rootLogger()->level());
// Create appender A2 for log window
Gui::TLogWindow::appender = new Gui::TLogWindowAppender(layout);
Gui::TLogWindow::appender->setName("A2");
Gui::TLogWindow::appender->activateOptions();
// Set log window appender on root logger
LogManager::rootLogger()->addAppender(Gui::TLogWindow::appender);
logger()->info("initLog4Qt: root logger initialized on level %1",
LogManager::rootLogger()->level().toString());
}
示例9: initLogger
static log4cxx::Logger* initLogger(const char* logFile, const char* logLevel)
{
static char s_parttern[] = "%d [%p] [%c] %m";
using namespace LOG4CXX_NS;
Logger *pLogger = Logger::getRootLogger() ;
Appender * appender
= Appender::getAppender( logFile, "appender.ps" );
Layout* layout = Layout::getLayout( "patternErrLog", "layout.pattern" );
layout->setUData( s_parttern );
appender->setLayout( layout );
log4cxx::Level::setDefaultLevel(Level::toInt(logLevel));
pLogger->setLevel( logLevel );
pLogger->setAppender( appender );
return pLogger;
}
示例10: CommInpCfg
CommInpCfg :: CommInpCfg()
{
// Set up logging with stdout as destination
Category& rootLogCategory = Category::getRoot();
rootLogCategory.setPriority(Priority::INFO);
rootLogCategory.removeAllAppenders();
Appender* appender = new FileAppender("_", dup(fileno(stdout)));
PatternLayout* patternLayout = new PatternLayout();
patternLayout->setConversionPattern("[%d{%Y:%m:%d %H:%M:%S.%I}] %p %c %x: %m%n");
Layout* layout = dynamic_cast<Layout*> (patternLayout);
appender->setLayout(layout);
rootLogCategory.addAppender(appender);
}
示例11: writeArray
void Writer::writeArray(Appender& appender, const Value& value, Size indent)
{
appender.append("[" + lineBreak());
for (Size i = 0; i < value.getLength(); i++)
{
appender.append(space(indent + 1));
write(appender, value.get(i), indent + 1);
if (i + 1 != value.getLength())
{
appender.append(",");
}
appender.append(lineBreak());
}
appender.append(space(indent) + "]");
}
示例12: locker
void MainThreadAppender::append(const LoggingEvent &rEvent)
{
QReadLocker locker(&mAppenderGuard);
Appender *pAppender;
Q_FOREACH(pAppender, mAppenders)
{
if (QThread::currentThread() != qApp->thread())
{
LoggingEvent *event = new LoggingEvent(rEvent);
qApp->postEvent(pAppender, event);
}
else
pAppender->doAppend(rEvent);
}
}
示例13: lock
bool Logger::readLog(std::string &target) {
bool success = false;
LockGuard lock(m_mutex);
for (size_t i=0; i<m_appenders.size(); ++i) {
Appender *appender = m_appenders[i];
if (appender->getClass()->derivesFrom(MTS_CLASS(StreamAppender))) {
StreamAppender *streamAppender =
static_cast<StreamAppender *>(appender);
if (streamAppender->logsToFile()) {
streamAppender->readLog(target);
success = true;
break;
}
}
}
return success;
}
示例14: writeObject
void Writer::writeObject(Appender& appender, const Value& value, Size indent)
{
appender.append("{" + lineBreak());
auto propNames = value.getPropertyNames();
for (Size i = 0; i < propNames.size(); i++)
{
const std::string& name = propNames[i];
appender.append(space(indent + 1) + '"' + name + "\": ");
write(appender, value.get(name), indent + 1);
if (i + 1 != propNames.size())
{
appender.append(",");
}
appender.append(lineBreak());
}
appender.append(space(indent) + "}");
}
示例15: logger
int HttpLog::setErrorLogFile(const char *pFileName)
{
Appender *appender
= Appender::getAppender(pFileName, "appender.ps");
if (appender)
{
Appender *pOld = logger()->getAppender();
if ((pOld) && (pOld != appender))
pOld->close();
Layout *layout = Layout::getLayout(ERROR_LOG_PATTERN, "layout.pattern");
appender->setLayout(layout);
logger()->setAppender(appender);
return 0;
}
else
return LS_FAIL;
}