int main(int, char**) { Py_Initialize(); ackward::logging::initialize(); basicConfig(); Logger log = getLogger(); log.addHandler(handlers::SocketHandler(L"http://www.slashdot.org", 80)); log.info(L"rtfa"); return 0; }
int main(int, char**) { //create a logger, named 'test' Logger logger; //log everything to the console StreamHandler handler(LogLevel::LOG_DEBUG); std::string format = "Thread = %t, Name = %c, Level = %p, File = %F, Method = %M, Line = %L, TimeStamp = %d, Message = %m"; handler.setFormatter(new StandardFormatter(format)); logger.addHandler(&handler, true); //log only WARNING or worse to the file //FileHandler fileHandler("./test.log", LogLevel::LOG_WARNING); //logger.addHandler(&fileHandler); logger.warn(Ctxt("WARNING Test!")); logger.debug(Ctxt("DEBUG TEST!")); logger.info(Ctxt("INFO TEST!")); logger.critical(Ctxt("CRITICAL TEST!")); //use the global logging methods error("global error"); warn("global warning"); logger.removeHandler(&handler); logger.warn(Ctxt("No Handlers")); logger.addHandler(new NullHandler, true); logger.warn(Ctxt("Null Handler - should not log!")); logger.addHandler(new StreamHandler(LogLevel::LOG_DEBUG), true); logger.warn(Ctxt("WARNING Test!")); return 0; }
int main(int argc, char **argv) { //create a logger, named 'test' Logger *logger = new Logger("test"); //rotate every 1024 bytes, max of 5 backups RotatingFileHandler handler("./rotate.log", 1024, 5); logger->addHandler(&handler); int loops = 10; for (int i = 0; i < loops; ++i) { logger->warn(Ctxt("WARNING Test! ")); logger->debug(Ctxt("DEBUG TEST! ")); logger->info(Ctxt("INFO TEST! ")); logger->critical(Ctxt("CRITICAL TEST! ")); } delete logger; return 0; }
Object AbstractContextI::lookupLogger(const String& name) const throw (NamingException) { Object object = lookup(name); Logger logger; MapAnything loggerconfiguration; if (object->instanceOf(logger) || object->instanceOf(loggerconfiguration)) { if (object->instanceOf(loggerconfiguration)) { Anything loggername; lookup(name + L"/name", loggername); logger = Logger::getLogger(loggername); } object = logger; if (isBound(name + L"/level")) { Anything level; lookup(name + L"/level", level); logger->setLevel(Level::parse(level)); } if (isBound(name + L"/flush")) { Anything flush; lookup(name + L"/flush", flush); logger->setFlushAfterLog(flush); } if (isBound(name + L"/handlers")) { Iterator<Handler> h = logger->getHandlers()->iterator(); while (h->hasNext()) logger->removeHandler(h->next()); Anything handlers; lookup(name + L"/handlers", handlers); Iterator<Anything> i = handlers->iterator(); while (i->hasNext()) { String filename = i->next(); if (L"CONSOLE" == filename->toUpperCase()) { logger->addHandler(ConsoleHandler::getInstance()); } else { try { logger->addHandler(new StreamHandlerI(new jlj::io::FileOutputStreamI(filename))); } catch (const Exception& e) { throw NamingException(WITHDETAILS(e->toString())); } } } } else { if (0 == logger->getHandlers()->size()) logger->addHandler(ConsoleHandler::getInstance()); } const_cast<AbstractContextI*>(this)->rebind(name, object); } return object; }