| 1 |
/* |
| 2 |
* This File is part of Davix, The IO library for HTTP based protocols |
| 3 |
* Copyright (C) CERN 2013 |
| 4 |
* Author: Adrien Devresse <[email protected]> |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef DAVIX_LOGGER_INTERNAL_HPP |
| 23 |
#define DAVIX_LOGGER_INTERNAL_HPP |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "davix_internal_config.hpp" |
| 28 |
#include "../libs/alibxx/str/format.hpp" |
| 29 |
|
| 30 |
#include <utils/davix_logger.hpp> |
| 31 |
|
| 32 |
namespace Davix{ |
| 33 |
|
| 34 |
|
| 35 |
// log a string message to the davix logger |
| 36 |
void logStr(int scope, int log_level, const std::string & str); |
| 37 |
|
| 38 |
// Simple logger to trace in / out of function scope |
| 39 |
// |
| 40 |
class ScopeLogger{ |
| 41 |
public: |
| 42 |
ScopeLogger(int scopep, const char* msgp) : scope(0), msg(NULL){ |
| 43 |
if( getLogLevel() >= DAVIX_LOG_TRACE && getLogScope() & scopep){ |
| 44 |
msg = msgp; |
| 45 |
scope = scopep; |
| 46 |
logStr(scope, davix_get_log_level(), ::Davix::fmt::format(" -> {}",msg)); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
~ScopeLogger(){ |
| 51 |
if(msg){ |
| 52 |
logStr(scope, davix_get_log_level(), ::Davix::fmt::format(" <- {}",msg)); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
private: |
| 57 |
int scope; |
| 58 |
const char* msg; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
#define DAVIX_SLOG(lvl, scope, msg, ...) \ |
| 64 |
do{ \ |
| 65 |
if( (::Davix::getLogScope() & scope) && (::Davix::getLogLevel() >= lvl) ){ \ |
| 66 |
::Davix::logStr(scope, lvl, ::Davix::fmt::format(msg, ##__VA_ARGS__)); } \ |
| 67 |
}while(0) |
| 68 |
|
| 69 |
|
| 70 |
#define DAVIX_SCOPE_TRACE(scope, id) \ |
| 71 |
::Davix::ScopeLogger id(scope, __func__) |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
} // Davix |
| 76 |
|
| 77 |
#endif // DAVIX_LOGGER_INTERNAL_HPP |