2 * Copyright (c) 2003-2019 Apple Inc. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #if defined(WIN32) || defined(EFI32) || defined(EFI64) || defined(EFIX64)
20 // Need to add Windows/EFI syslog support here
23 #define LOG_PERROR 0x20
28 #include "mDNSEmbeddedAPI.h"
30 mDNSexport
int mDNS_LoggingEnabled
= 0;
31 mDNSexport
int mDNS_PacketLoggingEnabled
= 0;
32 mDNSexport
int mDNS_McastLoggingEnabled
= 0;
33 mDNSexport
int mDNS_McastTracingEnabled
= 0;
36 mDNSexport
int mDNS_DebugMode
= mDNStrue
;
38 mDNSexport
int mDNS_DebugMode
= mDNSfalse
;
41 // Note, this uses mDNS_vsnprintf instead of standard "vsnprintf", because mDNS_vsnprintf knows
42 // how to print special data types like IP addresses and length-prefixed domain names
43 #if MDNS_DEBUGMSGS > 1
44 mDNSexport
void verbosedebugf_(const char *format
, ...)
48 va_start(args
, format
);
49 buffer
[mDNS_vsnprintf(buffer
, sizeof(buffer
), format
, args
)] = 0;
51 mDNSPlatformWriteDebugMsg(buffer
);
55 // Log message with default "mDNSResponder" ident string at the start
56 #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG)
57 mDNSlocal
void LogMsgWithLevelv(os_log_t category
, os_log_type_t level
, const char *format
, va_list args
)
60 mDNS_vsnprintf(buffer
, (mDNSu32
)sizeof(buffer
), format
, args
);
61 os_log_with_type(category
? category
: mDNSLogCategory_Default
, level
, "%{private}s", buffer
);
64 mDNSlocal
void LogMsgWithLevelv(const char *category
, mDNSLogLevel_t level
, const char *format
, va_list args
)
68 const char *const lim
= &buffer
[512];
69 if (category
) mDNS_snprintf_add(&dst
, lim
, "%s: ", category
);
70 mDNS_vsnprintf(dst
, (mDNSu32
)(lim
- dst
), format
, args
);
71 mDNSPlatformWriteLogMsg(ProgramName
, buffer
, level
);
75 #define LOG_HELPER_BODY(CATEGORY, LEVEL) \
78 va_start(args,format); \
79 LogMsgWithLevelv(CATEGORY, LEVEL, format, args); \
84 #if !MDNS_HAS_VA_ARG_MACROS
85 void LogMsg_(const char *format
, ...) LOG_HELPER_BODY(NULL
, MDNS_LOG_INFO
)
86 void LogOperation_(const char *format
, ...) LOG_HELPER_BODY(NULL
, MDNS_LOG_INFO
)
87 void LogSPS_(const char *format
, ...) LOG_HELPER_BODY(NULL
, MDNS_LOG_INFO
)
88 void LogInfo_(const char *format
, ...) LOG_HELPER_BODY(NULL
, MDNS_LOG_INFO
)
89 void LogDebug_(const char *format
, ...) LOG_HELPER_BODY(NULL
, MDNS_LOG_DEBUG
)
93 void debugf_(const char *format
, ...) LOG_HELPER_BODY(MDNS_LOG_DEBUG
)
96 // Log message with default "mDNSResponder" ident string at the start
97 mDNSexport
void LogMsgWithLevel(mDNSLogCategory_t category
, mDNSLogLevel_t level
, const char *format
, ...)
98 LOG_HELPER_BODY(category
, level
)
100 mDNSexport
void LogToFD(int fd
, const char *format
, ...)
103 va_start(args
, format
);
104 #if APPLE_OSX_mDNSResponder
106 buffer
[mDNS_vsnprintf(buffer
, (mDNSu32
)sizeof(buffer
), format
, args
)] = '\0';
107 dprintf(fd
, "%s\n", buffer
);
110 LogMsgWithLevelv(NULL
, MDNS_LOG_INFO
, format
, args
);