Skip to content

Commit

Permalink
Move Hashable to Loggerable (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushichop authored Sep 20, 2022
1 parent b8dc015 commit 59e8da7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['macos-latest', 'ubuntu-latest', 'windows-latest']
os: ['macos-latest', 'ubuntu-latest']
swift-version: ['5.4.2']
fail-fast: false
steps:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [x.y.z](https://github.com/sushichop/Puppy/releases/tag/x.y.z) (yyyy-mm-dd)

- Use macro for debugging. [#50](https://github.com/sushichop/Puppy/pull/50)
- Move `Hashable` to `Loggerable`. [#51](https://github.com/sushichop/Puppy/pull/51)

## [0.5.0](https://github.com/sushichop/Puppy/releases/tag/0.5.0) (2022-02-28)

Expand Down
32 changes: 14 additions & 18 deletions Sources/Puppy/BaseLogger.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import Foundation

public protocol Loggerable {

public protocol Loggerable: Hashable {
var label: String { get }
var queue: DispatchQueue? { get }

func log(_ level: LogLevel, string: String)
}

open class BaseLogger: Loggerable {
extension Loggerable {
public func hash(into hasher: inout Hasher) {
hasher.combine(label)
}

public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.label == rhs.label
}
}

open class BaseLogger: Loggerable {
public var enabled: Bool = true
public var logLevel: LogLevel = .trace

Expand All @@ -23,13 +31,12 @@ open class BaseLogger: Loggerable {
func formatMessage(_ level: LogLevel, message: String, tag: String, function: String, file: String, line: UInt, swiftLogInfo: [String: String], label: String, date: Date, threadID: UInt64) {
if !enabled { return }

var formattedMessage = ""
var tmpFormattedMessage = message
if let format = format {
formattedMessage = format.formatMessage(level, message: message, tag: tag, function: function, file: file, line: line, swiftLogInfo: swiftLogInfo, label: label, date: date, threadID: threadID)
} else {
formattedMessage = message
tmpFormattedMessage = format.formatMessage(level, message: message, tag: tag, function: function, file: file, line: line, swiftLogInfo: swiftLogInfo, label: label, date: date, threadID: threadID)
}

let formattedMessage = tmpFormattedMessage
if let queue = queue {
queue.async {
self.log(level, string: formattedMessage)
Expand All @@ -52,14 +59,3 @@ open class BaseLogger: Loggerable {
print("NEED TO OVERRIDE!!: \(string)")
}
}

extension BaseLogger: Hashable {

public func hash(into hasher: inout Hasher) {
hasher.combine(label)
}

public static func == (lhs: BaseLogger, rhs: BaseLogger) -> Bool {
return lhs.label == rhs.label
}
}

0 comments on commit 59e8da7

Please sign in to comment.