Skip to content

Commit 1eacaeb

Browse files
Copilotpylappludovic35
authored
feat: Fine-tune OUDSLogger: add verbose flag to suppress debug/log output by default (#1367)(#1368)
Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pylapp <7559007+pylapp@users.noreply.github.com> Co-authored-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> Co-authored-by: Ludovic PINEL <ludovic.pinel@orange.com>
1 parent 9af2c6d commit 1eacaeb

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- Move from Xcode 26.2 to Xcode 26.3 (Orange-OpenSource/ouds-ios#1375)
1212

13+
### Added
14+
15+
- `verbose` flag on `OUDSLogger` to suppress debug and log messages by default (Orange-OpenSource/ouds-ios#1365)
16+
1317
## [1.3.0](https://github.com/Orange-OpenSource/ouds-ios/compare/1.2.0...1.3.0) - 2026-03-26
1418

1519
### Added

OUDS/Core/ThemesContract/Sources/TokenatorConstants+Logs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ extension OUDSVersions {
5757
versionsLog += "- Text Area: \(Self.componentTextAreaVersion)\n"
5858
versionsLog += "- Text Input: \(Self.componentTextInputVersion)\n"
5959

60-
OL.info(versionsLog)
60+
OL.log(versionsLog)
6161
}
6262
}

OUDS/Foundations/Sources/OUDSLogger.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public typealias OL = OUDSLogger
1919

2020
/// The `os.Logger` wrapper used in the *OUDS iOS* library so as to logs things in standard output or elsewhere.
2121
///
22+
/// By default, debug and log level messages are suppressed even in DEBUG builds.
23+
/// Set `OUDSLogger.verbose = true` to enable them.
24+
///
2225
/// - Since: 0.8.0
2326
public struct OUDSLogger {
2427

@@ -28,18 +31,26 @@ public struct OUDSLogger {
2831
private static let bullet: String = "🍊"
2932
private static let prefix: String = "\(bullet) [OUDS]"
3033

31-
/// If compile mode is set as DEBUG, logs the message with a "debug" prefix
34+
/// When `true`, debug and log level messages are written to the console.
35+
/// Defaults to `false` so that OUDS internal logs do not pollute host-app output.
36+
/// Can be toggled at any time by library consumers.
37+
nonisolated(unsafe) public static var verbose: Bool = false
38+
39+
/// If compile mode is set as DEBUG and ``verbose`` is `true`, logs the message with a "debug" prefix
3240
/// and the `debug` method of the `os.Logger`
3341
/// - Parameter message: The message to log after the decoration
3442
public static func debug(_ message: String) {
43+
guard verbose else { return }
3544
#if DEBUG
3645
logger.debug("\(prefix):debug: 🪲 \(message)")
3746
#endif
3847
}
3948

4049
/// Logs the message with a "log" prefix and the `log` method of the `os.Logger`
50+
/// if ``verbose`` is `true`
4151
/// - Parameter message: The message to log after the prefix
4252
public static func log(_ message: String) {
53+
guard verbose else { return }
4354
#if DEBUG
4455
logger.log("\(prefix): 🗒️ \(message)")
4556
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Software Name: OUDS iOS
3+
// SPDX-FileCopyrightText: Copyright (c) Orange SA
4+
// SPDX-License-Identifier: MIT
5+
//
6+
// This software is distributed under the MIT license,
7+
// the text of which is available at https://opensource.org/license/MIT/
8+
// or see the "LICENSE" file for more details.
9+
//
10+
// Authors: See CONTRIBUTORS.txt
11+
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
12+
//
13+
14+
@testable import OUDSFoundations
15+
import Testing
16+
17+
@Suite("OUDSLogger Tests")
18+
struct OUDSLoggerTests {
19+
20+
@Test("verbose flag is false by default")
21+
func verboseFlagDefaultValue() {
22+
// The documented default is false; verify without resetting first
23+
// so we can detect if the declaration default were ever changed.
24+
#expect(OUDSLogger.verbose == false)
25+
}
26+
27+
@Test("verbose flag can be toggled by consumers")
28+
func verboseFlagCanBeChanged() {
29+
defer { OUDSLogger.verbose = false } // Always restore, even on failure
30+
OUDSLogger.verbose = true
31+
#expect(OUDSLogger.verbose == true)
32+
OUDSLogger.verbose = false
33+
#expect(OUDSLogger.verbose == false)
34+
}
35+
}

0 commit comments

Comments
 (0)