/src/znc/include/znc/ZNCDebug.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2004-2026 ZNC, see the NOTICE file for details. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #ifndef ZNCDEBUG_H |
18 | | #define ZNCDEBUG_H |
19 | | |
20 | | #include <znc/zncconfig.h> |
21 | | #include <znc/ZNCString.h> |
22 | | #include <sstream> |
23 | | |
24 | | /** Output a debug info if debugging is enabled. |
25 | | * If ZNC was compiled with <code>--enable-debug</code> or was started with |
26 | | * <code>--debug</code>, the given argument will be sent to stdout. |
27 | | * |
28 | | * You can use all the features of C++ streams: |
29 | | * @code |
30 | | * DEBUG("I had " << errors << " errors"); |
31 | | * @endcode |
32 | | * |
33 | | * @param f The expression you want to display. |
34 | | */ |
35 | | #define DEBUG(f) \ |
36 | 0 | do { \ |
37 | 0 | if (CDebug::Debug()) { \ |
38 | 0 | CDebugStream sDebug; \ |
39 | 0 | sDebug << f; \ |
40 | 0 | } \ |
41 | 0 | } while (0) |
42 | | |
43 | | class CDebug { |
44 | | public: |
45 | 0 | static void SetStdoutIsTTY(bool b) { stdoutIsTTY = b; } |
46 | 0 | static bool StdoutIsTTY() { return stdoutIsTTY; } |
47 | 0 | static void SetDebug(bool b) { debug = b; } |
48 | 0 | static bool Debug() { return debug; } |
49 | | |
50 | | static CString Filter(const CString& sUnfilteredLine); |
51 | | |
52 | | protected: |
53 | | static bool stdoutIsTTY; |
54 | | static bool debug; |
55 | | }; |
56 | | |
57 | | class CDebugStream : public std::ostringstream { |
58 | | public: |
59 | | ~CDebugStream(); |
60 | | }; |
61 | | |
62 | | #endif // !ZNCDEBUG_H |