| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef LEVELOGGER_H |
| 21 | #define LEVELOGGER_H |
| 22 | |
| 23 | #include <iosfwd> |
| 24 | |
| 25 | #include "globaldef.h" |
| 26 | |
| 27 | class Configuration; |
| 28 | |
| 29 | class LeveLogger |
| 30 | { |
| 31 | private: // members |
| 32 | /// the allowed logging level; init it once for the whole session |
| 33 | unsigned int allowedLevel = 0; |
| 34 | |
| 35 | public: // interface |
| 36 | /// sets output file and allowedLevel by given values |
| 37 | bool initLogger ( unsigned int l, const char* filename ); |
| 38 | /** sets output file and allowedLevel by config file. |
| 39 | * The values will be taken from Config|[LeveLogger]|{allowedLevel,file} |
| 40 | * Default level is 0, but the file name is mandatory. |
| 41 | */ |
| 42 | bool initLogger ( Configuration& Config ); |
| 43 | |
| 44 | /// @return true if LEVEL will be allowed |
| 45 | bool isWritable ( unsigned int level ) const |
| 46 | { |
| 47 | if ( USE_LOGGING ) |
| 48 | return level <= allowedLevel; |
| 49 | else |
| 50 | return false; |
| 51 | } |
| 52 | }; // LeveLogger |
| 53 | |
| 54 | /// the only main logger/manager for all usage |
| 55 | extern LeveLogger LLM; |
| 56 | /// file stream to be used by LLM; be sure that every OP with LL is guarded by LLM |
| 57 | extern std::ostream& LL; |
| 58 | |
| 59 | // macro for checking if LL is writable and then return |
| 60 | #define CHECK_LL_RETURN(val) \ |
| 61 | if (!LLM.isWritable(val)) return |
| 62 | |
| 63 | // macro for checking if LL is writable and then return value |
| 64 | #define CHECK_LL_RETURN_VALUE(val,ret) \ |
| 65 | if (!LLM.isWritable(val)) return (ret) |
| 66 | |
| 67 | #endif // LEVELOGGER_H |