1 //===-- OsLogger.cpp --------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include <Availability.h>
12 #if (LLDB_USE_OS_LOG) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101200)
19 #define LLDB_OS_LOG_MAX_BUFFER_LENGTH 256
22 // Darwin os_log logging callback that can be registered with
23 // DNBLogSetLogCallback
24 void DarwinLogCallback(void *baton
, uint32_t flags
, const char *format
,
26 if (format
== nullptr)
29 static os_log_t g_logger
;
31 g_logger
= os_log_create("com.apple.dt.lldb", "debugserver");
36 os_log_type_t log_type
;
37 if (flags
& DNBLOG_FLAG_FATAL
)
38 log_type
= OS_LOG_TYPE_FAULT
;
39 else if (flags
& DNBLOG_FLAG_ERROR
)
40 log_type
= OS_LOG_TYPE_ERROR
;
41 else if (flags
& DNBLOG_FLAG_WARNING
)
42 log_type
= OS_LOG_TYPE_DEFAULT
;
43 else if (flags
& DNBLOG_FLAG_VERBOSE
)
44 log_type
= OS_LOG_TYPE_DEBUG
;
46 log_type
= OS_LOG_TYPE_DEFAULT
;
48 // This code is unfortunate. os_log* only takes static strings, but
49 // our current log API isn't set up to make use of that style.
50 char buffer
[LLDB_OS_LOG_MAX_BUFFER_LENGTH
];
51 vsnprintf(buffer
, sizeof(buffer
), format
, args
);
52 os_log_with_type(g_logger
, log_type
, "%{public}s", buffer
);
56 DNBCallbackLog
OsLogger::GetLogFunction() { return DarwinLogCallback
; }
60 DNBCallbackLog
OsLogger::GetLogFunction() { return nullptr; }