Changeset 5897 for branches/newapi
- Timestamp:
- 12/02/07 02:15:44 (12 months ago)
- Location:
- branches/newapi/licq/src
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/newapi/licq/src/daemon.cpp
r5797 r5897 26 26 #include "plugin/pluginloaderimpl.h" 27 27 #include "plugin/pluginmanagerimpl.h" 28 #include "util/log.h"29 #include "util/logdistributor.h"30 28 #include "util/streamlogsink.h" 31 29 #include "util/support.h" … … 39 37 #include <sys/stat.h> 40 38 #include <sys/types.h> 41 #include <unistd.h>42 43 static LicqDaemon::Daemon singleGlobalDaemonInstance;44 39 45 40 Licq::Daemon* Licq::Daemon::getInstance() 46 41 { 47 return &singleGlobalDaemonInstance;42 return LicqDaemon::Daemon::getInstance(); 48 43 } 49 44 50 45 LicqDaemon::Daemon* LicqDaemon::Daemon::getInstance() 51 46 { 52 return &singleGlobalDaemonInstance; 47 static LicqDaemon::Daemon daemon; 48 return &daemon; 53 49 } 54 50 … … 93 89 94 90 LicqDaemon::Daemon::Daemon() 95 : myLog("daemon", &myLogDistributor) 96 { 97 myStreamLogSink = new StreamLogSink(std::cerr); 98 myLogDistributor.registerSink(myStreamLogSink); 99 91 : myLog(*Log::getThreadLog()) 92 { 100 93 myPluginLoader = new PluginLoaderImpl(); 101 94 myPluginCache = new PluginCacheImpl(myLog, *myPluginLoader); … … 108 101 delete myPluginCache; 109 102 delete myPluginLoader; 110 111 myLogDistributor.unregisterSink(myStreamLogSink);112 delete myStreamLogSink;113 }114 115 void LicqDaemon::Daemon::setupLocalization()116 {117 103 } 118 104 … … 121 107 } 122 108 123 bool LicqDaemon::Daemon::init(int argc, char** argv )109 bool LicqDaemon::Daemon::init(int argc, char** argv, StreamLogSink& streamLogSink) 124 110 { 125 111 namespace po = boost::program_options; … … 167 153 } 168 154 169 if (vm.count("nocolors") || !isatty(STDERR_FILENO))170 myStreamLogSink->setUseColors(false);155 if (vm.count("nocolors")) 156 streamLogSink.setUseColors(false); 171 157 172 158 { … … 199 185 it != plugins.end(); ++it) 200 186 { 187 /* 201 188 Licq::Plugin::Id 202 189 id = myPluginManager->loadPlugin(*it, myLogDistributor, 0, NULL); 203 190 myLog.debug(tr("Loaded plugin %1% with id %2%") % *it % id); 191 */ 204 192 } 205 193 } -
branches/newapi/licq/src/daemon.h
r5656 r5897 23 23 #include "licq/interface/daemon.h" 24 24 #include "util/log.h" 25 #include "util/logdistributor.h"26 25 27 26 #include <iosfwd> … … 31 30 namespace LicqDaemon 32 31 { 32 33 class StreamLogSink; 33 34 34 35 class Daemon : public Licq::Daemon … … 40 41 ~Daemon(); 41 42 42 void setupLocalization();43 43 void installSignalHandlers(); 44 44 45 bool init(int argc, char** argv );45 bool init(int argc, char** argv, StreamLogSink& streamLogSink); 46 46 int main(); 47 47 … … 52 52 53 53 private: 54 LogDistributor myLogDistributor; 55 Log myLog; 56 57 class StreamLogSink* myStreamLogSink; 54 Log& myLog; 58 55 59 56 class PluginLoader* myPluginLoader; -
branches/newapi/licq/src/main.cpp
r5809 r5897 10 10 #include "licq/exception/exception.h" 11 11 #include "licq/exception/invalidargumentexception.h" 12 #include "util/log.h" 13 #include "util/logdistributor.h" 12 14 #include "util/tr.h" 15 #include "util/streamlogsink.h" 13 16 14 17 #include <iostream> 18 #include <unistd.h> 15 19 16 20 /* … … 51 55 int main(int argc, char** argv) 52 56 { 57 LicqDaemon::LogDistributor logDistributor; 58 LicqDaemon::Log::setThreadLog(new LicqDaemon::Log("licq", &logDistributor)); 59 Licq::Log& log = *LicqDaemon::Log::getThreadLog(); 60 61 // Enable logging to stderr 62 LicqDaemon::StreamLogSink streamLogSink(std::cerr); 63 logDistributor.registerSink(&streamLogSink); 64 if (!isatty(STDERR_FILENO)) 65 streamLogSink.setUseColors(false); 66 67 // Fail if argv[0] isn't set 53 68 if (argc < 1) 54 69 { 55 std::cerr << "Licq requires at least one argument\n";70 log.fatal() << tr("Licq requires argv[0] to be set"); 56 71 exit(EXIT_FAILURE); 57 72 } 58 73 74 int retval = 0; 59 75 try 60 76 { … … 66 82 try 67 83 { 68 if (!daemon->init(argc, argv ))84 if (!daemon->init(argc, argv, streamLogSink)) 69 85 exit(EXIT_SUCCESS); 70 86 } … … 72 88 { 73 89 std::cerr << ex << "\n"; 74 std::cerr << "Try `" << argv[0] << " --help' for more information.\n";90 std::cerr << tr("Try `%1% --help' for more information.") % argv[0] << "\n"; 75 91 exit(EXIT_FAILURE); 76 92 } 77 93 78 int ret = daemon->main(); 79 return ret; 94 retval = daemon->main(); 80 95 } 81 96 catch (const Licq::Exception& ex) 82 97 { 83 std::cerr << ex << "\n";98 log.fatal() << ex; 84 99 exit(EXIT_FAILURE); 85 100 } 86 101 catch (const std::exception& ex) 87 102 { 88 std::cerr << "Caught std::exception: " << ex.what() << "\n";103 log.fatal() << tr("Caught std::exception: %1%") % ex.what(); 89 104 exit(EXIT_FAILURE); 90 105 } 91 106 catch (...) 92 107 { 93 std::cerr << "Caught unknown exception\n";108 log.fatal() << tr("Caught unknown exception"); 94 109 exit(EXIT_FAILURE); 95 110 } 96 return 0; 111 112 if (retval != 0) 113 log.error(tr("Licq finished with exit code %1%") % retval); 114 115 logDistributor.unregisterSink(&streamLogSink); 116 return retval; 97 117 98 118 /*
