Skip to content

Commit

Permalink
update logging service
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Sep 1, 2023
1 parent fceafe5 commit 3fa466a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Sentry

struct ThirdPartyConfigurator: Configurator {

Expand Down
28 changes: 18 additions & 10 deletions Example/WalletApp/ApplicationLayer/LoggingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ final class LoggingService {

public static var instance = LoggingService()
private var publishers = [AnyCancellable]()
private var isLogging = false
private var isLogging: Bool {
get {
return queue.sync { _isLogging }
}
set {
queue.sync { _isLogging = newValue }
}
}
private var _isLogging = false

private let queue = DispatchQueue(label: "com.walletApp.loggingService")

func setUpUser(account: String, clientId: String) {
Expand All @@ -24,26 +33,25 @@ final class LoggingService {
guard let sentryDsn = InputConfig.sentryDsn, !sentryDsn.isEmpty else { return }
SentrySDK.start { options in
options.dsn = "https://\(sentryDsn)"
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1.0
}
}

func startLogging() {
queue.sync {
guard isLogging == false else { return }
isLogging = true
}
guard !isLogging else { return }
isLogging = true

Networking.instance.logsPublisher
.sink { log in
self.queue.sync {
.sink { [weak self] log in
self?.queue.sync {
switch log {
case .error(let log):
SentrySDK.capture(error: LoggingError.networking(log.aggregated))
case .warn(let log):
SentrySDK.capture(message: log.aggregated)
// Example of setting level to warning
var event = Event(level: .warning)
event.message = SentryMessage(formatted: log.aggregated)
SentrySDK.capture(event: event)
default:
return
}
Expand Down

0 comments on commit 3fa466a

Please sign in to comment.