36 queue_all_msgs(true) {
39 static class GxLoggerGuard {
43 GxLoggerGuard() : logger_instance(0) {}
44 ~GxLoggerGuard() { destroy(); }
45 void create() { logger_instance =
new GxLogger; }
46 void destroy() {
if (logger_instance) {
delete logger_instance; logger_instance = 0; }}
47 GxLogger *get() {
return logger_instance; }
53 logger_guard.create();
54 l = logger_guard.get();
60 logger_guard.destroy();
63 GxLogger::~GxLogger() {
67 void GxLogger::set_ui_thread() {
69 assert(pthread_equal(pthread_self(), ui_thread));
71 got_new_msg =
new Glib::Dispatcher;
72 ui_thread = pthread_self();
73 got_new_msg->connect(mem_fun(*
this, &GxLogger::write_queued));
83 if (!queue_all_msgs) {
86 queue_all_msgs =
false;
90 void GxLogger::write_queued() {
91 if (handlers.empty()) {
97 std::list<logmsg> l = msglist;
98 if (!queue_all_msgs) {
104 for (std::list<logmsg>::iterator i = l.begin(); i != l.end(); ++i) {
105 if (queue_all_msgs) {
107 handlers(i->msg, i->msgtype, i->plugged);
111 handlers(i->msg, i->msgtype, i->plugged);
116 std::string GxLogger::format(
const char* func,
const std::string& msg) {
120 struct tm *tm_now = localtime(&now);
121 std::ostringstream msgbuf;
122 msgbuf <<
"[" << std::setfill(
'0')
123 << std::setw(2) << tm_now->tm_hour <<
":"
124 << std::setw(2) << tm_now->tm_min <<
":"
125 << std::setw(2) << tm_now->tm_sec <<
"]"
126 <<
" " << func <<
" *** " << msg;
135 if (handlers.empty() || !(pthread_equal(pthread_self(), ui_thread))) {
136 boost::mutex::scoped_lock lock(msgmutex);
138 msglist.push_back(logmsg(formatted_msg, msgtype,
false));
139 if (!handlers.empty() && msglist.size() == 1) {
144 handlers(formatted_msg, msgtype,
false);
145 if (queue_all_msgs) {
146 msglist.push_back(logmsg(formatted_msg, msgtype,
true));
178 std::string msgbuf = std::string(_(
"fatal system error: ")) + func +
" *** " + msg +
"\n";
197 exit_sig.emit_reverse(!pthread_equal(pthread_self(), ui_thread));
199 msg =
"** guitarix exit **";
201 std::cerr << msg << std::endl;