| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "atlas/library/config.h" |
| 4 |
|
| 5 |
#include "eckit/log/Log.h" |
| 6 |
|
| 7 |
namespace atlas { |
| 8 |
|
| 9 |
class Log : public eckit::Log { |
| 10 |
public: |
| 11 |
using Channel = eckit::Channel; // derives from std::ostream |
| 12 |
|
| 13 |
static Channel& info(); |
| 14 |
static Channel& warning(); |
| 15 |
static Channel& trace(); |
| 16 |
static Channel& debug(); |
| 17 |
|
| 18 |
// Same as what fckit::Log provides |
| 19 |
enum Style |
| 20 |
{ |
| 21 |
SIMPLE = 0, |
| 22 |
PREFIX = 1, |
| 23 |
TIMESTAMP = 2 |
| 24 |
}; |
| 25 |
static void addFortranUnit(int unit, Style = PREFIX, const char* prefix = ""); |
| 26 |
static void setFortranUnit(int unit, Style = PREFIX, const char* prefix = ""); |
| 27 |
|
| 28 |
// Fortran unit numbers |
| 29 |
static int output_unit() { return 6; } |
| 30 |
static int error_unit() { return 0; } |
| 31 |
}; |
| 32 |
|
| 33 |
std::string backtrace(); |
| 34 |
|
| 35 |
} // namespace atlas |
| 36 |
|
| 37 |
#include <sstream> |
| 38 |
#include "atlas/library/detail/BlackMagic.h" |
| 39 |
#include "eckit/log/CodeLocation.h" |
| 40 |
|
| 41 |
namespace atlas { |
| 42 |
namespace detail { |
| 43 |
void debug_parallel_here(const eckit::CodeLocation&); |
| 44 |
void debug_parallel_what(const eckit::CodeLocation&, const std::string&); |
| 45 |
} // namespace detail |
| 46 |
} // namespace atlas |
| 47 |
|
| 48 |
#define ATLAS_DEBUG_HERE() \ |
| 49 |
do { \ |
| 50 |
::atlas::Log::info() << "DEBUG() @ " << Here() << std::endl; \ |
| 51 |
} while (0) |
| 52 |
#define ATLAS_DEBUG_WHAT(WHAT) \ |
| 53 |
do { \ |
| 54 |
::atlas::Log::info() << "DEBUG(" << WHAT << ") @ " << Here() << std::endl; \ |
| 55 |
} while (0) |
| 56 |
#define ATLAS_DEBUG_VAR(VAR) \ |
| 57 |
do { \ |
| 58 |
::atlas::Log::info() << "DEBUG( " << #VAR << " : " << VAR << " ) @ " << Here() << std::endl; \ |
| 59 |
} while (0) |
| 60 |
|
| 61 |
#define ATLAS_DEBUG(...) __ATLAS_SPLICE(__ATLAS_DEBUG_, __ATLAS_NARG(__VA_ARGS__))(__VA_ARGS__) |
| 62 |
#define __ATLAS_DEBUG_0 ATLAS_DEBUG_HERE |
| 63 |
#define __ATLAS_DEBUG_1 ATLAS_DEBUG_WHAT |
| 64 |
|
| 65 |
#define ATLAS_DEBUG_BACKTRACE() \ |
| 66 |
do { \ |
| 67 |
::atlas::Log::info() << "DEBUG() @ " << Here() << "Backtrace:\n" << ::atlas::backtrace() << std::endl; \ |
| 68 |
} while (0) |
| 69 |
|
| 70 |
#define ATLAS_DEBUG_PARALLEL_HERE() \ |
| 71 |
do { \ |
| 72 |
::atlas::detail::debug_parallel_here(Here()); \ |
| 73 |
} while (0) |
| 74 |
#define ATLAS_DEBUG_PARALLEL_WHAT(WHAT) \ |
| 75 |
do { \ |
| 76 |
std::stringstream w; \ |
| 77 |
w << WHAT; \ |
| 78 |
::atlas::detail::debug_parallel_what(Here(), w.str()); \ |
| 79 |
} while (0) |
| 80 |
|
| 81 |
#define ATLAS_DEBUG_PARALLEL(...) \ |
| 82 |
__ATLAS_SPLICE(__ATLAS_DEBUG_PARALLEL_, __ATLAS_NARG(__VA_ARGS__)) \ |
| 83 |
(__VA_ARGS__) |
| 84 |
#define __ATLAS_DEBUG_PARALLEL_0 ATLAS_DEBUG_PARALLEL_HERE |
| 85 |
#define __ATLAS_DEBUG_PARALLEL_1 ATLAS_DEBUG_PARALLEL_WHAT |