|
1 | 1 | import Foundation |
2 | 2 | import CocoaLumberjack |
3 | 3 |
|
4 | | -// June 14 2017 - @astralbodies |
5 | | -// Taken from CocoaLumberjack repository - reproduced to prevent issue with |
6 | | -// CocoaPods and some weird bug with frameworks |
7 | | - |
8 | | -// Software License Agreement (BSD License) |
9 | | -// |
10 | | -// Copyright (c) 2014-2016, Deusty, LLC |
11 | | -// All rights reserved. |
12 | | -// |
13 | | -// Redistribution and use of this software in source and binary forms, |
14 | | -// with or without modification, are permitted provided that the following conditions are met: |
15 | | -// |
16 | | -// * Redistributions of source code must retain the above copyright notice, |
17 | | -// this list of conditions and the following disclaimer. |
18 | | -// |
19 | | -// * Neither the name of Deusty nor the names of its contributors may be used |
20 | | -// to endorse or promote products derived from this software without specific |
21 | | -// prior written permission of Deusty, LLC. |
22 | | - |
23 | | -extension DDLogFlag { |
24 | | - public static func from(_ logLevel: DDLogLevel) -> DDLogFlag { |
25 | | - return DDLogFlag(rawValue: logLevel.rawValue) |
26 | | - } |
27 | | - |
28 | | - public init(_ logLevel: DDLogLevel) { |
29 | | - self = DDLogFlag(rawValue: logLevel.rawValue) |
30 | | - } |
31 | | - |
32 | | - ///returns the log level, or the lowest equivalant. |
33 | | - public func toLogLevel() -> DDLogLevel { |
34 | | - if let ourValid = DDLogLevel(rawValue: rawValue) { |
35 | | - return ourValid |
36 | | - } else { |
37 | | - if contains(.verbose) { |
38 | | - return .verbose |
39 | | - } else if contains(.debug) { |
40 | | - return .debug |
41 | | - } else if contains(.info) { |
42 | | - return .info |
43 | | - } else if contains(.warning) { |
44 | | - return .warning |
45 | | - } else if contains(.error) { |
46 | | - return .error |
47 | | - } else { |
48 | | - return .off |
49 | | - } |
50 | | - } |
51 | | - } |
52 | | -} |
53 | | - |
54 | | -public var defaultDebugLevel = DDLogLevel.verbose |
55 | | - |
56 | | -public func resetDefaultDebugLevel() { |
57 | | - defaultDebugLevel = DDLogLevel.verbose |
58 | | -} |
59 | | - |
60 | | -public func _DDLogMessage(_ message: @autoclosure () -> String, level: DDLogLevel, flag: DDLogFlag, context: Int, file: StaticString, function: StaticString, line: UInt, tag: Any?, asynchronous: Bool, ddlog: DDLog) { |
61 | | - if level.rawValue & flag.rawValue != 0 { |
62 | | - // Tell the DDLogMessage constructor to copy the C strings that get passed to it. |
63 | | - let logMessage = DDLogMessage(message: message(), level: level, flag: flag, context: context, file: String(describing: file), function: String(describing: function), line: line, tag: tag, options: [.copyFile, .copyFunction], timestamp: nil) |
64 | | - ddlog.log(asynchronous: asynchronous, message: logMessage) |
65 | | - } |
66 | | -} |
67 | | - |
68 | | -public func DDLogDebug(_ message: @autoclosure () -> String, level: DDLogLevel = defaultDebugLevel, context: Int = 0, file: StaticString = #file, function: StaticString = #function, line: UInt = #line, tag: Any? = nil, asynchronous async: Bool = true, ddlog: DDLog = DDLog.sharedInstance) { |
69 | | - _DDLogMessage(message(), level: level, flag: .debug, context: context, file: file, function: function, line: line, tag: tag, asynchronous: async, ddlog: ddlog) |
70 | | -} |
71 | | - |
72 | | -public func DDLogInfo(_ message: @autoclosure () -> String, level: DDLogLevel = defaultDebugLevel, context: Int = 0, file: StaticString = #file, function: StaticString = #function, line: UInt = #line, tag: Any? = nil, asynchronous async: Bool = true, ddlog: DDLog = DDLog.sharedInstance) { |
73 | | - _DDLogMessage(message(), level: level, flag: .info, context: context, file: file, function: function, line: line, tag: tag, asynchronous: async, ddlog: ddlog) |
| 4 | +@inlinable |
| 5 | +public func DDLogVerbose(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) { |
| 6 | + CocoaLumberjack.DDLogVerbose(message(), file: file, function: function, line: line) |
74 | 7 | } |
75 | 8 |
|
76 | | -public func DDLogWarn(_ message: @autoclosure () -> String, level: DDLogLevel = defaultDebugLevel, context: Int = 0, file: StaticString = #file, function: StaticString = #function, line: UInt = #line, tag: Any? = nil, asynchronous async: Bool = true, ddlog: DDLog = DDLog.sharedInstance) { |
77 | | - _DDLogMessage(message(), level: level, flag: .warning, context: context, file: file, function: function, line: line, tag: tag, asynchronous: async, ddlog: ddlog) |
| 9 | +@inlinable |
| 10 | +public func DDLogDebug(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) { |
| 11 | + CocoaLumberjack.DDLogDebug(message(), file: file, function: function, line: line) |
78 | 12 | } |
79 | 13 |
|
80 | | -public func DDLogVerbose(_ message: @autoclosure () -> String, level: DDLogLevel = defaultDebugLevel, context: Int = 0, file: StaticString = #file, function: StaticString = #function, line: UInt = #line, tag: Any? = nil, asynchronous async: Bool = true, ddlog: DDLog = DDLog.sharedInstance) { |
81 | | - _DDLogMessage(message(), level: level, flag: .verbose, context: context, file: file, function: function, line: line, tag: tag, asynchronous: async, ddlog: ddlog) |
| 14 | +@inlinable |
| 15 | +public func DDLogInfo(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) { |
| 16 | + CocoaLumberjack.DDLogInfo(message(), file: file, function: function, line: line) |
82 | 17 | } |
83 | 18 |
|
84 | | -public func DDLogError(_ message: @autoclosure () -> String, level: DDLogLevel = defaultDebugLevel, context: Int = 0, file: StaticString = #file, function: StaticString = #function, line: UInt = #line, tag: Any? = nil, asynchronous async: Bool = false, ddlog: DDLog = DDLog.sharedInstance) { |
85 | | - _DDLogMessage(message(), level: level, flag: .error, context: context, file: file, function: function, line: line, tag: tag, asynchronous: async, ddlog: ddlog) |
| 19 | +@inlinable |
| 20 | +public func DDLogWarn(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) { |
| 21 | + CocoaLumberjack.DDLogWarn(message(), file: file, function: function, line: line) |
86 | 22 | } |
87 | 23 |
|
88 | | -/// Returns a String of the current filename, without full path or extension. |
89 | | -/// |
90 | | -/// Analogous to the C preprocessor macro `THIS_FILE`. |
91 | | -public func CurrentFileName(_ fileName: StaticString = #file) -> String { |
92 | | - var str = String(describing: fileName) |
93 | | - if let idx = str.range(of: "/", options: .backwards)?.upperBound { |
94 | | -#if swift(>=4.0) |
95 | | - str = String(str[idx...]) |
96 | | -#else |
97 | | - str = str.substring(from: idx) |
98 | | -#endif |
99 | | - } |
100 | | - if let idx = str.range(of: ".", options: .backwards)?.lowerBound { |
101 | | -#if swift(>=4.0) |
102 | | - str = String(str.prefix(upTo: idx)) |
103 | | -#else |
104 | | - str = str.substring(to: idx) |
105 | | -#endif |
106 | | - } |
107 | | - return str |
| 24 | +@inlinable |
| 25 | +public func DDLogError(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) { |
| 26 | + CocoaLumberjack.DDLogError(message(), file: file, function: function, line: line) |
108 | 27 | } |
0 commit comments