[libc++] Add missing iswctype_l in posix_l_fallbacks (#122484)
[llvm-project.git] / lldb / tools / debugserver / source / MacOSX / OsLogger.cpp
bloba83afb62b3650aa19b5daba367096cc965bacf93
1 //===-- OsLogger.cpp --------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "OsLogger.h"
10 #include <Availability.h>
12 #if (LLDB_USE_OS_LOG) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101200)
14 #include <os/log.h>
16 #include "DNBDefs.h"
17 #include "DNBLog.h"
19 #define LLDB_OS_LOG_MAX_BUFFER_LENGTH 256
21 namespace {
22 // Darwin os_log logging callback that can be registered with
23 // DNBLogSetLogCallback
24 void DarwinLogCallback(void *baton, uint32_t flags, const char *format,
25 va_list args) {
26 if (format == nullptr)
27 return;
29 static os_log_t g_logger;
30 if (!g_logger) {
31 g_logger = os_log_create("com.apple.dt.lldb", "debugserver");
32 if (!g_logger)
33 return;
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;
45 else
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; }
58 #else
60 DNBCallbackLog OsLogger::GetLogFunction() { return nullptr; }
62 #endif