Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/ThreemaFramework/Log/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 1 kB image not shown  

Quelle  FileLoggerCustom.swift   Sprache: JAVA

 

import CocoaLumberjackSwift
import Darwin
import Foundation

final class FileLoggerCustom: DDAbstractLogger {
    let logFile: URL

    /// Swift-side reference to the formatter, used on the logging hot path.
    ///
    /// `DDAbstractLogger.logFormatter` cannot be read from `log(message:)`: its accessor
    /// serialises through the logger queue that the callback already runs on, so the read
    /// would deadlock. Objective-C subclasses sidestep this by reading the ivar directly,
    /// which Swift cannot do for an inherited Objective-C ivar.
    private let logFormatterCustom: LogFormatterCustom

    init(logFile: URL) {
        self.logFile = logFile
        let formatter = LogFormatterCustom()
        self.logFormatterCustom = formatter
        super.init()
        self.logFormatter = formatter
    }

    /// Called by CocoaLumberjack on the logger queue, serialised per logger instance.
    /// Each `FileLoggerCustom` writes to its own file, so no cross-instance lock is needed.
    override func log(message logMessage: DDLogMessage) {
        let formatted = logFormatterCustom.format(message: logMessage) ?? logMessage.message
        guard let data = (formatted + "\n").data(using: .utf8) else {
            return
        }

        guard let file = fopen(logFile.path, "a") else {
            return
        }
        defer { fclose(file) }

        _ = data.withUnsafeBytes { buffer in
            fwrite(buffer.baseAddress, 1, data.count, file)
        }
        fsync(fileno(file))
    }
}

Messung
CHZG
899610095

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.