00001 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ 00002 /* 00003 * mitie 00004 * Copyright (C) Jason Spencer 2009 <mitie@jasonspencer.org> 00005 * 00006 * mitie is free software: you can redistribute it and/or modify it 00007 * under the terms of the GNU General Public License as published by the 00008 * Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * mitie is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00014 * See the GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 // ok, don't laugh, but I love this "hack" - super simple logging and zero runtime overhead. 00021 // when there is a block of code reposinsible for logging just stick the logging level around it, e.g. 00022 /* 00023 00024 JLOG (1, std::cout << "log level 1" << std::endl; 00025 std::cout << "more lglevel1 "<< std::endl; ) 00026 00027 JLOG (2, 00028 std::cout << "log level 2" << std::endl; 00029 double x = 1.2; 00030 std::cout << "Additionally, this log contains (), so sin(x) = " << sin(x) << " when x is " << x << std::endl; 00031 ) 00032 00033 JLOG(3, 00034 int y [] = { 1 , 4 , 5 , 42 }; 00035 int N = sizeof(y)/sizeof(y[0]); 00036 for(unsigned int i = 0 ; i < N ; ++i) std::cout << y[i] << std::endl; 00037 std::cout << "log level 3" << std::endl; 00038 ) 00039 00040 */ 00041 00042 #ifndef _JLOG_HH_ 00043 #define _JLOG_HH_ 1 00044 00045 #define JLOG(x,...) if(JLOGLEVEL>=x){ __VA_ARGS__ } 00046 00047 #endif // _JLOG_HH_