Пример #1
0
int main(int argc, char ** argv) {
	try {
		Appender errApp("Error.log", Level::ERROR, false);
		Appender debugApp("Debug.log", Level::DEBUG, true);
		Appender * dynApp = new Appender("Dynamic.log", Level::INFO, false);
		try {
			Appender badApp("Error.log", Level::ERROR, false);
		} catch ( exception & e ) {
			cout << "Correctly failed to open two appenders to one file." << endl;
		}
		logger1.Error("This should show up for all Appenders");
		delete dynApp;
		logger1.Error("This should only be in Error and Debug");
		logger2.Info("This should only be in debug");
		Appender::enableConsole(Level::INFO);
		logger1.Info("This should show up on the console.");
		logger2.Debug("This should only be in the debug log");
		fLogger.Info("Entering Foo");
		foo();
		fLogger.Info("Exiting foo.");
		Appender::enableConsole(Level::DEBUG);
		logger2.Debug("This will be in the console.");
		logger1.fDebug("%s - %i", "format test", 42);
		Appender::disableConsole();
		logger2.Debug("This will not be on the console.");
		logger1.Error("Exiting");
	} catch ( exception & e ) {
		cerr << "Unhandled exception: ";
		cerr << e.what() << endl;
		cerr << "Exiting." << endl;
		return 1;
	}
	return 0;
}
Пример #2
0
//
// Setup server: create sockets, load modules, etc
//
INT_32 MainProcess::Setup(Logger  & oLogger,
                          bool    & bLoggerStarted)
{
	// Initialize loggers, before of all other modules
	oLogger.Info("Starting logger subsystem");
	STLW::vector<ModuleConfig>::const_iterator itvLoggers = oGlobalContext.config.loggers.begin();
	while (itvLoggers != oGlobalContext.config.loggers.end())
	{
		const INT_32 iRC = LoadModule(itvLoggers -> type,
		                              itvLoggers -> name,
		                              itvLoggers -> library,
		                              itvLoggers -> driver,
		                              itvLoggers -> params,
		                              oGlobalContext.config.libexec_dirs,
		                              oLogger);
		if (iRC != 0) { return iRC; }
		oLogger.Info("Logger `%s` started", itvLoggers -> name.c_str());
		++itvLoggers;
	}

	// Get logger from factory for main process
	Object * pObject = oGlobalContext.factory.GetObject("Logger/" + oGlobalContext.config.logger_type);
	if (pObject == NULL)
	{
		oLogger.Emerg("Can't get main process logger `%s`", oGlobalContext.config.logger_type.c_str());
		return -1;
	}

	oLogger.Info("Logger subsystem started");

	// Start logger subsystem
	oGlobalContext.error_log  = static_cast<LoggerObject *>(pObject) -> GetErrorLog(NULL);
	oGlobalContext.error_log -> Notice("Log started");

	oGlobalContext.transfer_log = static_cast<LoggerObject *>(pObject) -> GetCustomLog(NULL);
	oGlobalContext.transfer_log -> Notice("Log started");

	bLoggerStarted = true;

	// Load modules
	oGlobalContext.error_log -> Info("Starting modules");
	STLW::vector<ModuleConfig>::const_iterator itvModules = oGlobalContext.config.modules.begin();
	while(itvModules != oGlobalContext.config.modules.end())
	{
		const INT_32 iRC = LoadModule(itvModules -> type,
		                              itvModules -> name,
		                              itvModules -> library,
		                              itvModules -> driver,
		                              itvModules -> params,
		                              oGlobalContext.config.libexec_dirs,
		                             *oGlobalContext.error_log);
		if (iRC != 0) { return iRC; }

		++itvModules;
	}
	oGlobalContext.error_log -> Info("All modules started");

return 0;
}
Пример #3
0
void test_Logger(){
    {
        Logger lg;
        lg.Log(LOG_WARN, "Test logger");
        lg.Debug("logger debug");
        lg.Fatal("Fatal test [%s] [%d]", "args", 1);
        lg.SetHandler("test_log");
        lg.SetLevel(LOG_ALL);
        lg.Info("info test [%s]", "args");
        Logger* lg_ptr = Logger::GetLogger("test");
        lg_ptr->Error("You can see me in file test");
        Logger* lg_ptr2 = Logger::GetLogger();
        lg_ptr2->Error("You can see me in console");
    }
    {
        LOG(LOG_DEBUG, "log debug info: %s", "Hello"); 
    }    
    {
        SetLogger(LOG_WARN, "test_logger.log");
        LOG(LOG_DEBUG, "DEBUG NO SEE, you should not see this");
        LOG(LOG_ERROR, "ERROR, you should know");
        LOG(LOG_WARN, "WARN, you should see this");
    }    
    {
        SetLogger(LOG_ALL);
        LOG(LOG_DEBUG, "DEBUG [%d], you should see this", LOG_DEBUG);
        LOG(LOG_WARN,  "LOG_WARN [%d], you should see this", LOG_WARN);
        LOG(LOG_ERROR, "LOG_ERROR [%d], you should see this", LOG_ERROR);
        LOG(LOG_FATAL, "LOG_FATAL [%d], you should see this", LOG_FATAL);
    }
}
Пример #4
0
	Module* JavaScriptModule::CreateModule(std::string& path)
	{
		Poco::Path p(path);
		std::string basename = p.getBaseName();
		std::string name = basename.substr(0,basename.length()-jsSuffix.length()+3);
		std::string moduledir = path.substr(0,path.length()-basename.length()-3);

		Logger *logger = Logger::Get("JavaScript");
		logger->Info("Loading JS path=%s", path.c_str());

		JavaScriptModuleInstance* instance = new JavaScriptModuleInstance(this->host, path, moduledir, name);
		return instance;
	}
Пример #5
0
void organizeML(void) {
    int startTime = GetTickCount();
    sprintf(tmp, "started at: %d", startTime);
    logger.Info("ml_org::organizeML()", tmp);

    int result = DialogBox(plugin.hDllInstance, MAKEINTRESOURCE(IDD_PROGRESS),
                           plugin.hwndLibraryParent, organize_dlgproc);

    int stopTime = GetTickCount();
    //int totalMS = (stopTime - startTime);
    //sprintf(tmp, "complete (%d), total time: %dms, avg: %.4fms / record",
    //	    result, totalMS, ((float) totalMS / (float) ml_org_records->Size));
    //logger.Info("ml_org::organizeML()", tmp);

    // make sure to re-sync the ML DB after all this...
    SendMessage(plugin.hwndLibraryParent, WM_ML_IPC, 0, ML_IPC_DB_SYNCDB);
}
Пример #6
0
	Module* RubyModule::CreateModule(std::string& path)
	{
		rb_load_file(path.c_str());
		ruby_exec();

//		ruby_cleanup();  <-- at some point we need to call?


		Poco::Path p(path);
		std::string basename = p.getBaseName();
		std::string name = basename.substr(0,basename.length()-ruby_suffix.length()+3);
		std::string moduledir = path.substr(0,path.length()-basename.length()-3);

		Logger *logger = Logger::Get("Ruby");
		logger->Info("Loading Ruby path=%s", path.c_str());

		return new RubyModuleInstance(host, path, moduledir, name);
	}
Пример #7
0
int init(void) {
    iniFile = (char*) SendMessage(plugin.hwndWinampParent, WM_WA_IPC, 0, IPC_GETINIFILE);
    if (! mlOrgConfig.LoadConfiguration(iniFile)) {
        logger.Error("ml_org::init()", "could not load configuration");
        return 1;
    }

    logger.SetLogLevel(mlOrgConfig.m_logLevel);
    logger.SetLogfile(mlOrgConfig.m_logfile);

    // Grab ahold of the window function pointer so we can do our own thang
    // when someone presses the "Organize Media Library" menu item
    mlWndproc = (WNDPROC) SetWindowLongPtr(plugin.hwndLibraryParent,
                                           GWLP_WNDPROC, (LONG) winproc);
    if (mlWndproc == 0) {
        int error = GetLastError();
        sprintf(tmp, "could not get window func ptr (%d)", error);
        logger.Error("ml_org::init()", tmp);
        return error;
    }

    logger.Info("ml_org::init()", "plugin initialized");
    return 0;
}
Пример #8
0
void foo() {
	Appender fooApp("foo.log", Level::INFO, true);
	fLogger.Info("I'm in foo");
}
Пример #9
0
//
// Load modules
//
INT_32 MainProcess::LoadModule(const STLW::string                & sModuleType,
                               const STLW::string                & sModuleName,
                               const STLW::string                & sLibrary,
                               const STLW::string                & sDriver,
                               const VariantNC                   & oModuleConfig,
                               const STLW::vector<STLW::string>  & vLibexecDirs,
                               Logger                            & oLogger)
{
	oLogger.Info("Opening `%s/%s` from library `%s`", sModuleType.c_str(), sModuleName.c_str(), sLibrary.c_str());
	STLW::string sFullpath;
	INT_32 iRC = FindFile(vLibexecDirs, sLibrary, sFullpath);
	if (iRC == -1)
	{
		STLW::string sDirList;
		STLW::vector<STLW::string>::const_iterator itvLibexecDirs = vLibexecDirs.begin();
		for (;;)
		{
			sDirList += "`" + *itvLibexecDirs + "` ";
			++itvLibexecDirs;
			if (itvLibexecDirs == vLibexecDirs.end()) { break; }
			sDirList += ", ";
		}
		oLogger.Emerg("Can't find library `%s` in LibexecDirs(%s) ", sLibrary.c_str(), sDirList.c_str());
		return -1;
	}
	oLogger.Info("Library `%s` found here: `%s`", sLibrary.c_str(), sFullpath.c_str());

	Object * pObject = oGlobalContext.loader.GetObject(sFullpath.c_str(), sDriver.c_str());
	if (pObject == NULL)
	{
		oLogger.Emerg("Can't load object `%s` from file `%s`", sDriver.c_str(), sFullpath.c_str());
		return -1;
	}

	// Check type of object
	const STLW::string sObjectType = pObject -> GetObjectType();
	if (Unicode::CompareIgnoreCase(sObjectType.data(), sObjectType.size(), sModuleType.data(), sModuleType.size()) != 0)
	{
		oLogger.Emerg("Need type `%s`, but object `%s` loaded from file `%s` has type `%s`", sModuleType.c_str(), pObject -> GetObjectName(), sFullpath.c_str(), pObject -> GetObjectType());
		delete pObject;
		return -1;
	}

	oLogger.Info("Object `%s` with type `%s` loaded from file `%s`", pObject -> GetObjectName(), pObject -> GetObjectType(), sFullpath.c_str());

	// Initialize module
	iRC = static_cast<Module *>(pObject) -> InitModule(oGlobalContext, oModuleConfig, oSigHandler, oLogger);
	if (iRC != 0)
	{
		oLogger.Emerg("Can't initialize module `%s` from file `%s`", sModuleName.c_str(), sFullpath.c_str());
		delete pObject;
		return -1;
	}

	const STLW::string sFullName = sModuleType + '/' + sModuleName;
	vModules.push_back(sFullName);
	// Store object in factory
	if(oGlobalContext.factory.AddObject(sFullName, pObject) == NULL)
	{
		oLogger.Emerg("Can't add module `%s` from file `%s`", sModuleName.c_str(), sFullpath.c_str());
		static_cast<Module *>(pObject) -> DestroyModule(oGlobalContext, oSigHandler, oLogger);
		delete pObject;
		return -1;
	}

return 0;
}
Пример #10
0
void config(HWND parent) {
    logger.Info("ml_org::config()", "open");
    DialogBox(plugin.hDllInstance, MAKEINTRESOURCE(IDD_CONFIG), parent, config_dlgproc);
    logger.Info("ml_org::config()", "close");
}
Пример #11
0
void quit(void) {
    if (! mlOrgConfig.SaveConfiguration(iniFile)) {
        logger.Warn("ml_org::quit()", "could not save configuration");
    }
    logger.Info("ml_org::quit()", "plugin unloaded");
}