ViewController.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. import UIKit
  16. import CocoaLumberjackSwift
  17. let ddloglevel = DDLogLevel.verbose
  18. private func printSomething() {
  19. DDLogVerbose("Verbose")
  20. DDLogDebug("Debug")
  21. DDLogInfo("Info")
  22. DDLogWarn("Warn")
  23. DDLogError("Error")
  24. }
  25. final class ViewController: UIViewController {
  26. override func viewDidAppear(_ animated: Bool) {
  27. super.viewDidAppear(animated)
  28. let formatter = Formatter()
  29. if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
  30. let logger = DDOSLogger.sharedInstance
  31. logger.logFormatter = formatter
  32. DDLog.add(logger)
  33. } else if let logger = DDTTYLogger.sharedInstance {
  34. logger.logFormatter = formatter
  35. DDLog.add(logger)
  36. }
  37. DDLogVerbose("Verbose")
  38. DDLogDebug("Debug")
  39. DDLogInfo("Info")
  40. DDLogWarn("Warn")
  41. DDLogError("Error")
  42. printSomething()
  43. dynamicLogLevel = ddloglevel
  44. DDLogVerbose("Verbose")
  45. DDLogDebug("Debug")
  46. DDLogInfo("Info")
  47. DDLogWarn("Warn")
  48. DDLogError("Error")
  49. DDLogVerbose("Verbose", level: ddloglevel)
  50. DDLogDebug("Debug", level: ddloglevel)
  51. DDLogInfo("Info", level: ddloglevel)
  52. DDLogWarn("Warn", level: ddloglevel)
  53. DDLogError("Error", level: ddloglevel)
  54. printSomething()
  55. }
  56. }