Skip to content

Commit 0a3cf71

Browse files
authored
Fix wlan check failure on macos (#42770)
### What does this PR do? This PR provides a solution to WiFi check failure on MacOS ### Motivation WINA-2015: Wifi-Check does not work on the latest version on the Mac ### Describe how you validated your changes Ensure command "agent check wlan" works correctly and all CI pipelines pass. More details can be found in JIRA case [WINA-2015](https://datadoghq.atlassian.net/browse/WINA-2015). ### Additional Notes [WINA-2015]: https://datadoghq.atlassian.net/browse/WINA-2015?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: hongshi.guo <hongshi.guo@datadoghq.com>
1 parent 33ba729 commit 0a3cf71

18 files changed

Lines changed: 1859 additions & 294 deletions

File tree

cmd/agent/install_mac_os.sh

Lines changed: 279 additions & 48 deletions
Large diffs are not rendered by default.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
import Foundation
7+
import os.log
8+
9+
enum LogLevel {
10+
case debug, info, error
11+
}
12+
13+
class Logger {
14+
private static var useFileLogging = false
15+
private static let osLog = OSLog(subsystem: "com.datadoghq.agent", category: "GUI")
16+
17+
/// Configure logging mode at startup
18+
/// - Parameter useFileLogging: If true, uses NSLog (file-based); if false, uses os_log (unified logging)
19+
static func configure(useFileLogging: Bool) {
20+
self.useFileLogging = useFileLogging
21+
if useFileLogging {
22+
NSLog("[Logger] File-based logging enabled")
23+
} else {
24+
os_log("[Logger] Unified logging (os_log) enabled", log: osLog, type: .info)
25+
}
26+
}
27+
28+
/// Log a message with specified level and context
29+
/// - Parameters:
30+
/// - message: The message to log
31+
/// - level: Log level (debug, info, error)
32+
/// - context: Optional context string (e.g., class name)
33+
static func log(_ message: String, level: LogLevel = .info, context: String = "") {
34+
let prefix = context.isEmpty ? "" : "[\(context)] "
35+
let fullMessage = "\(prefix)\(message)"
36+
37+
if useFileLogging {
38+
// Use NSLog which outputs to stdout/stderr (redirected to file by LaunchAgent)
39+
NSLog(fullMessage)
40+
} else {
41+
// Use os_log (default) - automatic log size management by macOS
42+
switch level {
43+
case .debug:
44+
os_log("%{public}@", log: osLog, type: .debug, fullMessage)
45+
case .info:
46+
os_log("%{public}@", log: osLog, type: .info, fullMessage)
47+
case .error:
48+
os_log("%{public}@", log: osLog, type: .error, fullMessage)
49+
}
50+
}
51+
}
52+
53+
/// Log a debug message
54+
static func debug(_ message: String, context: String = "") {
55+
log(message, level: .debug, context: context)
56+
}
57+
58+
/// Log an info message
59+
static func info(_ message: String, context: String = "") {
60+
log(message, level: .info, context: context)
61+
}
62+
63+
/// Log an error message
64+
static func error(_ message: String, context: String = "") {
65+
log(message, level: .error, context: context)
66+
}
67+
}

0 commit comments

Comments
 (0)