DDLogFlag+DDLogLevel.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2025, Deusty, LLC
  4. // All rights reserved.
  5. //
  6. // Redistribution and use of this software in source and binary forms,
  7. // with or without modification, are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. //
  12. // * Neither the name of Deusty nor the names of its contributors may be used
  13. // to endorse or promote products derived from this software without specific
  14. // prior written permission of Deusty, LLC.
  15. #if SWIFT_PACKAGE
  16. public import CocoaLumberjack
  17. #endif
  18. extension DDLogFlag {
  19. public static func from(_ logLevel: DDLogLevel) -> DDLogFlag {
  20. DDLogFlag(rawValue: logLevel.rawValue)
  21. }
  22. public init(_ logLevel: DDLogLevel) {
  23. self = DDLogFlag(rawValue: logLevel.rawValue)
  24. }
  25. /// Returns the log level, or the lowest equivalent.
  26. public func toLogLevel() -> DDLogLevel {
  27. if let ourValid = DDLogLevel(rawValue: rawValue) {
  28. return ourValid
  29. } else {
  30. if contains(.verbose) {
  31. return .verbose
  32. } else if contains(.debug) {
  33. return .debug
  34. } else if contains(.info) {
  35. return .info
  36. } else if contains(.warning) {
  37. return .warning
  38. } else if contains(.error) {
  39. return .error
  40. } else {
  41. return .off
  42. }
  43. }
  44. }
  45. }