Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Hashable to Loggerable #51

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}