main.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2025 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import ArgumentParser
  17. import Foundation
  18. import Logging
  19. struct Tests: ParsableCommand {
  20. nonisolated(unsafe) static var configuration = CommandConfiguration(
  21. abstract: "Commands for running and interacting with integration tests.",
  22. discussion: """
  23. A note on logging: by default, only log levels "info" and above are logged. For further \
  24. debugging, you can set the "LOG_LEVEL" environment variable to a different minimum level \
  25. (eg; "debug").
  26. """,
  27. subcommands: [Decrypt.self]
  28. // defaultSubcommand: Run.self
  29. )
  30. }
  31. LoggingSystem.bootstrap { label in
  32. var handler = StreamLogHandler.standardOutput(label: label)
  33. if let level = ProcessInfo.processInfo.environment["LOG_LEVEL"] {
  34. if let parsedLevel = Logger.Level(rawValue: String(level)) {
  35. handler.logLevel = parsedLevel
  36. return handler
  37. } else {
  38. print(
  39. """
  40. [WARNING]: Unrecognized log level "\(level)"; defaulting to "info".
  41. Valid values: \(Logger.Level.allCases.map(\.rawValue))
  42. """
  43. )
  44. }
  45. }
  46. handler.logLevel = .info
  47. return handler
  48. }
  49. Tests.main()