[Feature Enhancement]: Complete Logging Implementation

Aperta
#18 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Una pull request collegata è già stata integrata.

  • #9 di @MasterJ93 — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
swift

Direzione di ricerca

Read the package areas for ATProtoKit, ATProtoTools, and ATProtoAdmin, then inspect the applyWrites() example in the issue as a guide to the requested logging points. Add logging across all three classes, including session and request failures and outcomes; completion means all three checklist items are covered. A linked pull request was merged, so check its changes and the current code before taking this on.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement good first issue
Summary

No response

Pain points

The current implementation of ATProtoKit lacks a centralized logging mechanism, leading to several challenges, namely that debugging is much more difficult to deal with.

To solve this, SwiftLog will be integrated into the package. Furthermore, two logging backend implementations will be used: one that maps to Apple's unified Logger framework (for Apple platforms) and one that maps to the standard SwiftLog logger.

To be more specific, log events for the methods should be added as appropriate. As an example, take a look at applyWrites():

public func applyWrites(_ repositoryDID: String,
                        shouldValidate: Bool? = true,
                        writes: [ApplyWritesUnion],
                        swapCommit: String?) async throws {

    guard session != nil,
          let accessToken = session?.accessToken else {
        throw ATRequestPrepareError.missingActiveSession
    }

    guard let sessionURL = session?.pdsURL,
          let requestURL = URL(string: "\(sessionURL)/xrpc/com.atproto.repo.applyWrites") else {
        throw ATRequestPrepareError.invalidRequestURL
    }

    let requestBody = RepoApplyWrites(
        repositoryDID: repositoryDID,
        shouldValidate: shouldValidate,
        writes: writes,
        swapCommit: swapCommit
    )

    do {
        let request = APIClientService.createRequest(forRequest: requestURL,
                                                     andMethod: .post,
                                                     acceptValue: nil,
                                                     contentTypeValue: "application/json",
                                                     authorizationValue: "Bearer \(accessToken)")

        try await APIClientService.sendRequest(request,
                                               withEncodingBody: requestBody)
    } catch {
        throw error
    }
}

Various places within the method can have log events, including:

  • Within the first guard statement's else block, stating that session or accessToken doesn't have a value.
  • After the guard statement which would show the value of accessToken (albeit, obfuscated).
  • Within the second guard statement's else block, stating that there's an invalid request URL, followed by a String(describing:) of the request URL.
  • After the guard statement, which would show the value of requestURL.
  • After requestBody, which would show the values of requestBody.
  • After request, which would show the value of request.
  • After the try await code, which would say that the request has been successful.
  • Within the catch block, which gives an error log, followed by displaying the error itself.

This issue will focus on implementing log events to the ATProtoKit, ATProtoTools, and ATProtoAdmin classes. Future updates will deal with the remaining parts of the Swift package.

Considered Alternatives

No response

Is this a breaking change?

Yes

Additional Context
  • Implement log events on all parts of the ATProtoKit class.
  • Implement log events on all parts of the ATProtoAdmin class.
  • Implement log events on all parts of the ATProtoTools class.
Lingua principale
Swift
Stelle
226
Fork
40
Merge medio
5h 8m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MasterJ93/ATProtoKit

Tutte le issue di MasterJ93/ATProtoKit

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.