|
Freya
0.0.1
A Gtk3 MPD Client
|
00001 /*********************************************************** 00002 * This file is part of Freya 00003 * - A free MPD Gtk3 MPD Client - 00004 * 00005 * Authors: Christopher Pahl, Christoph Piechula, 00006 * Eduard Schneider 00007 * 00008 * Copyright (C) [2011-2012] 00009 * Hosted at: https://github.com/studentkittens/Freya 00010 * 00011 * __..--''``---....___ _..._ __ 00012 * /// //_.-' .-/"; ` ``<._ ``.''_ `. / // / 00013 * ///_.-' _..--.'_ `( ) ) // // 00014 * / (_..-' // (< _ ;_..__ ; `' / /// 00015 * / // // // `-._,_)' // / ``--...____..-' /// / // 00016 * Ascii-Art by Felix Lee <flee@cse.psu.edu> 00017 * 00018 * Freya is free software: you can redistribute it and/or modify 00019 * it under the terms of the GNU General Public License as published by 00020 * the Free Software Foundation, either version 3 of the License, or 00021 * (at your option) any later version. 00022 * 00023 * Freya is distributed in the hope that it will be useful, 00024 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 * GNU General Public License for more details. 00027 * 00028 * You should have received a copy of the GNU General Public License 00029 * along with Freya. If not, see <http://www.gnu.org/licenses/>. 00030 **************************************************************/ 00031 #ifndef FREYA_LOG_WRITER_GUARD 00032 #define FREYA_LOG_WRITER_GUARD 00033 00034 #include <stdio.h> 00035 #include <glibmm/ustring.h> 00036 #include "../Utils/Singleton.hh" 00037 00038 /* Not supposed to used directly, use the macros below */ 00039 #define _MSG(level, msg, ...) Log::Writer::instance().message(__FILE__, __LINE__, level, msg, ##__VA_ARGS__) 00040 #define LogSetVerbosity(X) Log::Writer::instance().set_verbosity((Log::LOGLEVEL)X) 00041 #define LogGetVerbosity Log::Writer::instance().get_verbosity() 00042 00043 /* The actual macros */ 00044 #define Warning(msg, ...) _MSG(Log::LOG_WARN, msg, ##__VA_ARGS__) 00045 #define Info(msg, ...) _MSG(Log::LOG_INFO, msg, ##__VA_ARGS__) 00046 #define Critical(msg, ...) _MSG(Log::LOG_CRITICAL, msg, ##__VA_ARGS__) 00047 #define Error(msg, ...) _MSG(Log::LOG_ERROR, msg, ##__VA_ARGS__) 00048 #define Debug(msg, ...) _MSG(Log::LOG_DEBUG, msg, ##__VA_ARGS__) 00049 #define Success(msg, ...) _MSG(Log::LOG_OK, msg, ##__VA_ARGS__) 00050 00051 namespace Log 00052 { 00056 enum LOGLEVEL 00057 { 00058 LOG_CRITICAL = 1, 00059 LOG_ERROR, 00060 LOG_WARN, 00061 LOG_OK, 00062 LOG_INFO, 00063 LOG_DEBUG, 00064 LOG_NUMS_OF_LEVEL 00065 }; 00066 00067 class Writer 00068 { 00069 /* Make this class a singleton, 00070 * this implicitely defines a ctor, 00071 * Just the dtor is defined expl. below. 00072 */ 00073 DEF_SINGLETON(Writer); 00074 00075 public: 00076 00080 ~Writer(); 00081 00091 void message(const char *file, int line, LOGLEVEL level, const char *msg, ...); 00092 00102 void set_verbosity(LOGLEVEL v); 00103 00109 LOGLEVEL get_verbosity(); 00110 00114 void clear(); 00115 00116 private: 00117 00121 Glib::ustring m_Logpath; 00125 FILE * m_Logfile; 00126 00130 LOGLEVEL m_Verbosity; 00131 00137 void get_current_time(char buffer[]); 00138 00139 void write_out(std::stringstream& stream); 00140 }; 00141 } 00142 00143 #endif
1.8.0