Skip to content

Commit

Permalink
Fix slowdown by logging (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
humdrum authored Jul 22, 2024
1 parent 6860357 commit 10b1870
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Sources/Core/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,34 @@ enum Logger {

private static var yorkieLogger = Logging.Logger(label: "Yorkie")

static func trace(_ message: String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .trace, message, error: error, filename: filename, function: function, line: line)
static func trace(_ message: @autoclosure () -> String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .trace, message(), error: error, filename: filename, function: function, line: line)
}

static func debug(_ message: String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .debug, message, error: error, filename: filename, function: function, line: line)
static func debug(_ message: @autoclosure () -> String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .debug, message(), error: error, filename: filename, function: function, line: line)
}

static func info(_ message: String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .info, message, error: error, filename: filename, function: function, line: line)
static func info(_ message: @autoclosure () -> String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .info, message(), error: error, filename: filename, function: function, line: line)
}

static func warning(_ message: String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .warning, message, error: error, filename: filename, function: function, line: line)
static func warning(_ message: @autoclosure () -> String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .warning, message(), error: error, filename: filename, function: function, line: line)
}

static func error(_ message: String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .error, message, error: error, filename: filename, function: function, line: line)
static func error(_ message: @autoclosure () -> String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .error, message(), error: error, filename: filename, function: function, line: line)
}

static func critical(_ message: String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .critical, message, error: error, filename: filename, function: function, line: line)
static func critical(_ message: @autoclosure () -> String, error: Error? = nil, filename: String = #fileID, function: String = #function, line: UInt = #line) {
self.log(level: .critical, message(), error: error, filename: filename, function: function, line: line)
}

static func log(level: Logging.Logger.Level, _ message: String, error: Error? = nil, filename: String = #file, function: String = #function, line: UInt = #line) {
var log = message
static func log(level: Logging.Logger.Level, _ message: @autoclosure () -> String, error: Error? = nil, filename: String = #file, function: String = #function, line: UInt = #line) {
guard Logger.logLevel <= level else { return }

var log = message()

if let error {
log += "(\(String(describing: error)))"
Expand Down

0 comments on commit 10b1870

Please sign in to comment.