ViewController.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2021, 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 viewDidLoad() {
  27. super.viewDidLoad()
  28. // Do any additional setup after loading the view, typically from a nib.
  29. }
  30. override func viewDidAppear(_ animated: Bool) {
  31. super.viewDidAppear(animated)
  32. let formatter = Formatter()
  33. if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
  34. let logger = DDOSLogger.sharedInstance
  35. logger.logFormatter = formatter
  36. DDLog.add(logger)
  37. } else if let logger = DDTTYLogger.sharedInstance {
  38. logger.logFormatter = formatter
  39. DDLog.add(logger)
  40. }
  41. DDLogVerbose("Verbose")
  42. DDLogDebug("Debug")
  43. DDLogInfo("Info")
  44. DDLogWarn("Warn")
  45. DDLogError("Error")
  46. printSomething()
  47. dynamicLogLevel = ddloglevel
  48. DDLogVerbose("Verbose")
  49. DDLogDebug("Debug")
  50. DDLogInfo("Info")
  51. DDLogWarn("Warn")
  52. DDLogError("Error")
  53. DDLogVerbose("Verbose", level: ddloglevel)
  54. DDLogDebug("Debug", level: ddloglevel)
  55. DDLogInfo("Info", level: ddloglevel)
  56. DDLogWarn("Warn", level: ddloglevel)
  57. DDLogError("Error", level: ddloglevel)
  58. printSomething()
  59. }
  60. }