Last active
April 9, 2018 11:34
-
-
Save wata/adf253b21d6cffa94d46eaf5b18e2413 to your computer and use it in GitHub Desktop.
XCGLogger のログ送り先を Crashlytics にする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SEE ALSO: https://github.com/DaveWoodCom/XCGLogger/pull/78#issuecomment-256779363 | |
| open class CrashlyticsLogDestination: BaseDestination { | |
| public override init(owner: XCGLogger?, identifier: String = "\(XCGLogger.Constants.baseIdentifier).logdestination.crashlytics") { | |
| super.init(owner: owner, identifier: identifier) | |
| showDate = false | |
| } | |
| open override func output(logDetails: LogDetails, message: String) { | |
| let args: [CVarArg] = [message] | |
| withVaList(args) { (argp: CVaListPointer) in | |
| CLSLogv("%@", argp) | |
| } | |
| } | |
| } | |
| let log: XCGLogger = { | |
| let log = XCGLogger(identifier: "com.example.foo.logger", includeDefaultDestinations: false) | |
| #if DEBUG | |
| let destination = ConsoleDestination(identifier: XCGLogger.Constants.baseConsoleDestinationIdentifier) | |
| destination.outputLevel = .debug | |
| destination.showLogIdentifier = false | |
| destination.showFunctionName = true | |
| destination.showThreadName = true | |
| destination.showLevel = true | |
| destination.showFileName = true | |
| destination.showLineNumber = true | |
| destination.showDate = false | |
| destination.formatters = { | |
| let emojiLogFormatter = PrePostFixLogFormatter() | |
| emojiLogFormatter.apply(prefix: "🗯🗯🗯 ", postfix: " 🗯🗯🗯", to: .verbose) | |
| emojiLogFormatter.apply(prefix: "🔹🔹🔹 ", postfix: " 🔹🔹🔹", to: .debug) | |
| emojiLogFormatter.apply(prefix: "ℹ️ℹ️ℹ️ ", postfix: " ℹ️ℹ️ℹ️", to: .info) | |
| emojiLogFormatter.apply(prefix: "⚠️⚠️⚠️ ", postfix: " ⚠️⚠️⚠️", to: .warning) | |
| emojiLogFormatter.apply(prefix: "‼️‼️‼️ ", postfix: " ‼️‼️‼️", to: .error) | |
| emojiLogFormatter.apply(prefix: "💣💣💣 ", postfix: " 💣💣💣", to: .severe) | |
| return [emojiLogFormatter] | |
| }() | |
| log.add(destination: destination) | |
| #else | |
| let destination = CrashlyticsLogDestination(owner: log) | |
| destination.outputLevel = .debug | |
| destination.showLogIdentifier = false | |
| destination.showFunctionName = true | |
| destination.showThreadName = true | |
| destination.showLevel = true | |
| destination.showFileName = true | |
| destination.showLineNumber = true | |
| destination.showDate = false | |
| log.add(destination: destination) | |
| #endif | |
| return log | |
| }() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment