Upgrade to Pro — share decks privately, control downloads, hide ads and more …

サポート効率を上げるためのロギング環境構築

horimislime
September 17, 2017

 サポート効率を上げるためのロギング環境構築

iOSDC Japan 2017 2017/9/17 (日)
https://iosdc.jp/2017/node/1422

horimislime

September 17, 2017
Tweet

More Decks by horimislime

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ງݟ फҰ࿠ (@horimislime) • ! גࣜձࣾτϨλ • "

    iPad޲͚ͷ༧໿୆ாΞϓϦ։ൃ • # ϞόΠϧΞϓϦͷΤϥʔϩάऩूʹ͍ͭͯ iOSDC Japan 2017
  2. Logger.swift struct Logger { func info(message: String) { debugPrint(message) Bugsnag.leaveBreadcrumb(message)

    } func error(message: String) { debugPrint(message) Bugsnag.notifyError(...) } } iOSDC Japan 2017
  3. ͦͷଞͷίϯιʔϧϩά • γεςϜ͕ు͖ग़ͯ͠Δϩά (AutoLayout่ΕͳͲ) • ϩάอଘઌΛ೚ҙͷσΟϨΫτϦԼʹมߋͰ͖Δ • Ϋϥογϡʹhookͯ͠ϑΝΠϧͷத਎Λૹ৴͢Δ͜ͱ΋Մೳ var paths

    = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let directory = paths[0] let logFilePath = (directory as NSString).appendingPathComponent("\(Date()).log") freopen(logFilePath.cString(using: String.Encoding.ascii)!, "a+", stderr) iOSDC Japan 2017
  4. struct Service { func connectToDevice(completion: Result<Response, NSError>) { // ॲཧ

    if notReady { completion(.failure(NSError(domain: "in.toreta", code: 0, userInfo: nil))) } else { completion(.success(response)) } } } override func viewDidLoad() { super.viewDidLoad() service.connectToDevice { result in switch result { case .success(let data): ... case .failure(let _): HUD.show("Τϥʔ͕ൃੜ͠·ͨ͠ɻ઀ଓ؀ڥΛ֬ೝ͍ͩ͘͞ɻ") } } } iOSDC Japan 2017
  5. ϩδοΫΤϥʔ΋ৄࡉʹྻڍ enum ApplicationError: Error { case bleNotAvailable case hardwareNotReady ...

    } struct Service { func connectToDevice(completion: Result<Response, ApplicationError>) { // ॲཧ if notReady { completion(.failure(.hardwareNotReady)) } else { completion(.success(response)) } } } iOSDC Japan 2017
  6. enum ApplicationError: Error { ... case hardwareNotReady var errorCode: Int

    { switch self { ... case hardwareNotReady: return -3000 } } var localizedDescription: String { ... case hardwareNotReady: return "Τϥʔίʔυ: \(errorCode)" } var localizedFailureReason: String { ... case hardwareNotReady: return "઀ଓʹࣦഊ͠·ͨ͠ɻBLEσόΠεͷిݯΛ֬͝ೝ͍ͩ͘͞ɻ" } } iOSDC Japan 2017
  7. Error Codeͷར఺1 • ໰͍߹ΘͤͷແݴޠԽʹܨ͕Δ override func viewDidLoad() { ... service.connectToDevice

    { result in switch result { case .success(let data): ... case .failure(let error): Logger.shared.error(error) self.showAlert(withTitle: error.localizedDescription, message: error.localizedFailureReason) } } } iOSDC Japan 2017