|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2018 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2018-2021 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See http://swift.org/LICENSE.txt for license information
|
@@ -35,14 +35,23 @@ struct LogPolicy {
|
35 | 35 |
|
36 | 36 | /// Initializes a new `LogPolicy`.
|
37 | 37 | ///
|
38 |
| - /// - parameter maximumDepth: The maximum depth level for logging children of children. Defaults to 2. |
| 38 | + /// - parameter maximumDepth: The maximum depth level for logging children of children. Defaults to 2, but the default can be overridden with the `LOGGER_DEPTH` environment variable. |
39 | 39 | /// - parameter aggregateChildPolicy: The policy to use for logging children of aggregates. Defaults to logging no more than the first 10,000 children.
|
40 | 40 | /// - parameter containerChildPolicy: The policy to use for logging children of collections. Defaults to logging no more than the first 80 children plus the last 20 children.
|
41 |
| - init(maximumDepth: Int = 2, |
| 41 | + init(maximumDepth: Int = (LogPolicy.environmentMaxDepth ?? 2), |
42 | 42 | aggregateChildPolicy: ChildPolicy = .head(count: 10_000),
|
43 | 43 | containerChildPolicy: ChildPolicy = .headTail(headCount: 80, tailCount: 20)) {
|
44 | 44 | self.maximumDepth = maximumDepth
|
45 | 45 | self.aggregateChildPolicy = aggregateChildPolicy
|
46 | 46 | self.containerChildPolicy = containerChildPolicy
|
47 | 47 | }
|
| 48 | + |
| 49 | + /// Read and return the `LOGGER_DEPTH` from the environment. |
| 50 | + static let loggerDepthEnvironmentKey = "LOGGER_DEPTH" |
| 51 | + private static var environmentMaxDepth: Int? { |
| 52 | + guard let envDepth = ProcessInfo.processInfo.environment[loggerDepthEnvironmentKey] else { |
| 53 | + return nil |
| 54 | + } |
| 55 | + return Int(envDepth) |
| 56 | + } |
48 | 57 | }
|
0 commit comments