XCGLogger icon indicating copy to clipboard operation
XCGLogger copied to clipboard

Add optional logging destination for integration with Crashlytics

Open msanders opened this issue 10 years ago • 11 comments

See #68. Only catch is this currently needs to be dragged into the parent project since we don't have access to the symbols for Crashlytics at time time we're linking the library (not sure if there's a better workaround).

msanders avatar Aug 12 '15 21:08 msanders

@DaveWoodCom thoughts?

msanders avatar Sep 15 '15 23:09 msanders

I still like the idea, it's just low in priorities right now. Ideally anyone can use this already, without it being added to the master branch. But I'll need to set up a Crashlytics account etc to fully test. Priority for me right now is still getting out my next game (so close), and then cramming on the Apple TV to hit the day 1 release date!

DaveWoodCom avatar Sep 16 '15 00:09 DaveWoodCom

+1 it's working well for me

esetnik avatar Jan 27 '16 18:01 esetnik

I too am using it nicely, though I needed to add:

import Crashlytics

to the beginning, which would in consequence make XCGLogger depend on Crashlytics too (requiring a change in .podspec), which is unnecessary for those who do not use Crashlytics with XCGLogger (unless XCGLogger's philosophy is "batteries included" :smile:)

So perhaps this should be in the podspec made as a separate "module" (if podspec allows that, I don't know) so that people having 'XCGLogger' in their Podfile would not get 'Crashlytics' unless explicitly opting in for XCGCrashlyticsLogDestination (which could be specified in their Podfile as e.g. XCGLogger/Crashlytics)?

Or another option is to make a separate repo from this, with its own podspec.

dusek avatar Feb 04 '16 11:02 dusek

Just a note that the only reason we are still on CocoaLumberjack is because it sends data up to Crashlytics.

CocoaLumberjack isn't so hot with Swift, though, so XCGLogger seems like a great one to move to... but we'd really like a slick, supported interface to Crashlytics.

Any chance of this getting resurrected?

karlbecker avatar Oct 27 '16 21:10 karlbecker

@karlbecker you can use this version. It works just fine for me.

//
//  XCGLogger+Crashlytics.swift
//  XCGLogger
//
//  Created by Michael Sanders on 8/12/15.
//  Copyright 2015 Cerebral Gardens. All rights reserved.
//
import XCGLogger
import Crashlytics

// MARK: - XCGCrashlyticsLogDestination
// - An optional log destination that sends the logs to Crashlytics
open class CrashlyticsLogDestination: BaseDestination {
  public override init(owner: XCGLogger?, identifier: String) {
    super.init(owner: owner, identifier: identifier)
    showDate = false
  }

  open override func output(logDetails: LogDetails, message: String) {
    let args: [CVarArg] = [message]
    withVaList(args) { (argp: CVaListPointer) -> Void in
      CLSLogv("%@", argp)
    }
  }
}

esetnik avatar Oct 27 '16 21:10 esetnik

It says this branch has conflicts that must be resolved - will I be losing out on lots of nice improvements that have been made since this branch was created?

Any chance @dusek 's suggestion could happen?

So perhaps this should be in the podspec made as a separate "module" (if podspec allows that, I don't know) so that people having 'XCGLogger' in their Podfile would not get 'Crashlytics' unless explicitly opting in for XCGCrashlyticsLogDestination (which could be specified in their Podfile as e.g. XCGLogger/Crashlytics)?

karlbecker avatar Oct 27 '16 21:10 karlbecker

@karlbecker you don't need to use this branch you can just drop the extension I pasted above into your application and add a CrashlyticsLogDestination and you're good to go. That version I pasted above works with the latest official release of XCGLogger. It's just an extension for Crashlytics.

esetnik avatar Oct 27 '16 21:10 esetnik

Oh fantastic! Thanks for the explanation - I'm still fairly new to Swift!

karlbecker avatar Oct 27 '16 22:10 karlbecker

You should update the code to handle logging via the optional queue like this:

` import Crashlytics import XCGLogger

open class CrashlyticsLogDestination : BaseQueuedDestination {

// MARK: - Overridden Methods
/// Print the log to the Apple System Log facility (using NSLog).
///
/// - Parameters:
///     - message:   Formatted/processed message ready for output.
///
/// - Returns:  Nothing
///
open override func write(message: String) {
    
    let outputClosure = {
        let aTextArray : [CVarArg] = [message]
        CLSLogv("%@", getVaList(aTextArray))
    }
    
    if let logQueue = logQueue {
        logQueue.async(execute: outputClosure)
    } else {
        outputClosure()
    }
}

}`

ArkadiGiniApps avatar Mar 28 '18 17:03 ArkadiGiniApps

I wanted to note that Crashlytics will be gone. Users have to move to Firebase. I'm not sure how that will affect this PR. They haven't released new SDK yet.

fassko avatar Nov 30 '18 08:11 fassko