Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Debugging/OWSLogs.h
1 views
1
//
2
// Copyright 2024 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
#import <CocoaLumberjack/CocoaLumberjack.h>
7
8
NS_ASSUME_NONNULL_BEGIN
9
10
#ifdef DEBUG
11
static const DDLogLevel ddLogLevel = DDLogLevelAll;
12
#else
13
static const DDLogLevel ddLogLevel = DDLogLevelInfo;
14
#endif
15
16
static inline BOOL ShouldLogFlag(DDLogFlag flag)
17
{
18
return ((DDLogFlag)ddLogLevel & flag) != 0;
19
}
20
21
static inline BOOL ShouldLogVerbose(void)
22
{
23
return ddLogLevel >= DDLogLevelVerbose;
24
}
25
26
static inline BOOL ShouldLogDebug(void)
27
{
28
return ddLogLevel >= DDLogLevelDebug;
29
}
30
31
static inline BOOL ShouldLogInfo(void)
32
{
33
return ddLogLevel >= DDLogLevelInfo;
34
}
35
36
static inline BOOL ShouldLogWarning(void)
37
{
38
return ddLogLevel >= DDLogLevelWarning;
39
}
40
41
static inline BOOL ShouldLogError(void)
42
{
43
return ddLogLevel >= DDLogLevelError;
44
}
45
46
/// A helper method for `OWSLogIfEnabled`, which checks if a level should be logged.
47
void OWSLogUnconditionally(DDLogFlag flag,
48
const char *file,
49
BOOL shouldTrimFilePath,
50
NSUInteger line,
51
const char *function,
52
NSString *format,
53
...) NS_FORMAT_FUNCTION(6, 7);
54
55
#define OWSLogIfEnabled(flg, fmt, ...) \
56
do { \
57
if (ShouldLogFlag(flg)) \
58
OWSLogUnconditionally(flg, __FILE__, YES, __LINE__, __PRETTY_FUNCTION__, (fmt), ##__VA_ARGS__); \
59
} while (0)
60
61
#define OWSLogVerbose(fmt, ...) OWSLogIfEnabled(DDLogFlagVerbose, fmt, ##__VA_ARGS__)
62
#define OWSLogDebug(fmt, ...) OWSLogIfEnabled(DDLogFlagDebug, fmt, ##__VA_ARGS__)
63
#define OWSLogInfo(fmt, ...) OWSLogIfEnabled(DDLogFlagInfo, fmt, ##__VA_ARGS__)
64
#define OWSLogWarn(fmt, ...) OWSLogIfEnabled(DDLogFlagWarning, fmt, ##__VA_ARGS__)
65
#define OWSLogError(fmt, ...) OWSLogIfEnabled(DDLogFlagError, fmt, ##__VA_ARGS__)
66
67
#define OWSLogFlush() \
68
do { \
69
[DDLog flushLog]; \
70
} while (0)
71
72
NS_ASSUME_NONNULL_END
73
74