ATLAS Offline Software
Loading...
Searching...
No Matches
AthMsgStreamMacros.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// AthMsgStreamMacros.h
8// Header file for useful macros when comes to using MsgStream
9// Author: S.Binet<binet@cern.ch>
11#ifndef ATHENABASECOMPS_ATHMSGSTREAMMACROS_H
12#define ATHENABASECOMPS_ATHMSGSTREAMMACROS_H 1
13
14// CxxUtils
15#include <format>
16
17// For the ATH_MSG macros, if a single argument is given, it is streamed
18// directly to the MsgStream:
19//
20// ATH_MSG_INFO("foo: " << foo) -> msg(lvl) << "foo: " << foo << endmsg
21//
22// If multiple arguments are given, the arguments are interpreted
23// as for std::format:
24//
25// ATH_MSG_INFO("foo: {}", foo) -> msg(lvl) << std::format("foo: {}", foo) << endmsg
26//
27
28#define ATH_MSG_OPEN (
29#define ATH_MSG_CLOSE )
30
31// FIXME: operator precedence ?!
32#define ATH_MSG_LVL_NOCHK(lvl, x, ...) \
33 this->msg(lvl) << __VA_OPT__(std::format ATH_MSG_OPEN ) x __VA_OPT__ (, __VA_ARGS__ ATH_MSG_CLOSE) << endmsg
34
35#define ATH_MSG_LVL(lvl, x, ...) \
36 do { \
37 if (this->msgLvl (lvl)) [[unlikely]] { \
38 ATH_MSG_LVL_NOCHK(lvl, x __VA_OPT__(, __VA_ARGS__)); \
39 } \
40 } while (0)
41
42#define ATH_MSG_VERBOSE(x, ...) ATH_MSG_LVL(MSG::VERBOSE, x __VA_OPT__(, __VA_ARGS__))
43#define ATH_MSG_DEBUG(x, ...) ATH_MSG_LVL(MSG::DEBUG, x __VA_OPT__(, __VA_ARGS__))
44// note that we are using the _NOCHK variant here
45#define ATH_MSG_INFO(x, ...) ATH_MSG_LVL_NOCHK(MSG::INFO, x __VA_OPT__(, __VA_ARGS__))
46#define ATH_MSG_WARNING(x, ...) ATH_MSG_LVL_NOCHK(MSG::WARNING, x __VA_OPT__(, __VA_ARGS__))
47#define ATH_MSG_ERROR(x, ...) ATH_MSG_LVL_NOCHK(MSG::ERROR, x __VA_OPT__(, __VA_ARGS__))
48#define ATH_MSG_FATAL(x, ...) ATH_MSG_LVL_NOCHK(MSG::FATAL, x __VA_OPT__(, __VA_ARGS__))
49#define ATH_MSG_ALWAYS(x, ...) ATH_MSG_LVL_NOCHK(MSG::ALWAYS, x __VA_OPT__(, __VA_ARGS__))
50
51// can be used like so: ATH_MSG(INFO) << "hello" << endmsg;
52#define ATH_MSG(lvl) \
53 if (this->msgLvl(MSG::lvl)) this->msg(MSG::lvl)
54
55#endif //> !ATHENABASECOMPS_ATHMSGSTREAMMACROS_H
56