Skip to content

Commit

Permalink
Merge pull request #15 from shogo4405/xcode14
Browse files Browse the repository at this point in the history
Bump to up 2.3.0
  • Loading branch information
shogo4405 authored Sep 12, 2022
2 parents 3bcae34 + d3e55e8 commit 0213f0b
Show file tree
Hide file tree
Showing 43 changed files with 653 additions and 703 deletions.
Binary file modified .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Logboard.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Logboard"
s.version = "2.2.4"
s.version = "2.3.0"
s.summary = "Simple Logging framework"
s.swift_version = "5.0"

Expand All @@ -16,16 +16,16 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/shogo4405/Logboard.git", :tag => "#{s.version}" }
s.social_media_url = "http://twitter.com/shogo4405"

s.ios.deployment_target = "9.0"
s.ios.deployment_target = "11.0"
s.ios.source_files = "Platforms/iOS/*.{h,swift}"

s.osx.deployment_target = "10.9"
s.osx.source_files = "Platforms/macOS/*.{h,swift}"

s.tvos.deployment_target = "9.0"
s.tvos.deployment_target = "11.0"
s.tvos.source_files = "Platforms/tvOS/*.{h,swift}"

s.watchos.deployment_target = "2.0"
s.watchos.deployment_target = "4.0"
s.watchos.source_files = "Platforms/watchOS/*.{h,swift}"

s.source_files = "Sources/**/*.swift"
Expand Down
126 changes: 60 additions & 66 deletions Logboard.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,34 @@ logger.error("error")
```

## Requirements
|-|iOS|OSX|tvOS|watchOS|XCode|Swift|CocoaPods|Carthage|
|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|
|2.2.0+|9.0+|10.9+|9.0+|2.0|12.0+|5.3|1.3.0|0.31.0+|
|2.1.0+|8.0+|10.9+|9.0+|2.0|11.0+|5.0|1.3.0|0.31.0+|
|-|iOS|OSX|tvOS|watchOS|Xcode|Swift|
|:----:|:----:|:----:|:----:|:----:|:----:|:----:|
|2.3.0+|11.0+|10.9+|11.0+|4.0|14.0+|5.3|
|2.2.0+|9.0+|10.9+|9.0+|2.0|13.0+|5.3|

## Installation
*Please set up your project Swift 5.0

### CocoaPods
```rb
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

def import_pods
pod 'Logboard', '~> 2.2.2'
pod 'Logboard', '~> 2.3.0'
end

target 'Your Target' do
platform :ios, '9.0'
platform :ios, '11.0'
import_pods
end
```
### Carthage
```
github "shogo4405/Logboard" ~> 2.2.2
github "shogo4405/Logboard" ~> 2.3.0
```

## Appenders
### ConsoleAppender
Use print function. You can see XCode's console.
Use print function. You can see Xcode's console.
```swift
let logger = Logboard.with("identifier")
let console = ConsoleAppender()
Expand Down
11 changes: 6 additions & 5 deletions Sources/Logboard/ConsoleAppender.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Foundation

/// The ConsoleAppender class can output your xcode console with print function.
public class ConsoleAppender: LogboardAppender {
public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
print(Logboard.dateFormatter.string(from: Date()), "[\(level)]", "[\(logboard.identifier)]", "[\(filename(file.description)):\(line)]", function, ">", message.map({ String(describing: $0) }).joined(separator: ""))
public class ConsoleAppender: LBLoggerAppender {
public func append(_ logboard: LBLogger, level: LBLogger.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
print(LBLogger.dateFormatter.string(from: Date()), "[\(level)]", "[\(logboard.identifier)]", "[\(filename(file.description)):\(line)]", function, ">", message.map({ String(describing: $0) }).joined(separator: ""))
}
public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
print(Logboard.dateFormatter.string(from: Date()), "[\(level)]", "[\(logboard.identifier)]", "[\(filename(file.description)):\(line)]", function, ">", String(format: format, arguments))

public func append(_ logboard: LBLogger, level: LBLogger.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
print(LBLogger.dateFormatter.string(from: Date()), "[\(level)]", "[\(logboard.identifier)]", "[\(filename(file.description)):\(line)]", function, ">", String(format: format, arguments))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

extension Logboard {
extension LBLogger {
/// The logging message model.
public struct Data {
/// The date.
Expand All @@ -23,7 +23,7 @@ extension Logboard {
guard let strings: [String.SubSequence] = String(bytes: data, encoding: .utf8)?.split(separator: "\t"), 7 <= strings.count else {
return nil
}
date = Logboard.dateFormatter.date(from: String(strings[0])) ?? Date()
date = LBLogger.dateFormatter.date(from: String(strings[0])) ?? Date()
level = Level(string: String(strings[1])) ?? .trace
identifier = String(strings[2])
file = String(strings[3])
Expand All @@ -34,9 +34,9 @@ extension Logboard {
}
}

extension Logboard.Data: CustomStringConvertible {
extension LBLogger.Data: CustomStringConvertible {
// MARK: CustomStringConvertible
public var description: String {
return "\(Logboard.dateFormatter.string(from: date)) [\(level)] [\(identifier)] [\(filename(file)):\(line)] \(function) > \(message)"
return "\(LBLogger.dateFormatter.string(from: date)) [\(level)] [\(identifier)] [\(filename(file)):\(line)] \(function) > \(message)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ func filename(_ file: String) -> String {
return file.components(separatedBy: "/").last ?? file
}

/// The Logboard class is writing string messages to the LogboardAppender.
public class Logboard {
/// The LBLogger class is writing string messages to the LogboardAppender.
public class LBLogger {
/// The default dateFormatter values that is yyyy-dd-MM HH:mm:ss.SSS.
static public var dateFormatter: DateFormatter = {
let dateFormatter: DateFormatter = DateFormatter()
Expand Down Expand Up @@ -61,30 +61,30 @@ public class Logboard {
}
}

private static var instances: [String: Logboard] = [:]
private static var instances: [String: LBLogger] = [:]

/// Create or get a Logboard instance.
public static func with(_ identifier: String) -> Logboard {
public static func with(_ identifier: String) -> LBLogger {
if instances[identifier] == nil {
instances[identifier] = Logboard(identifier)
instances[identifier] = LBLogger(identifier)
}
return instances[identifier]!
}

/// The identifier is the subsystem name.
public let identifier: String
/// Specifies the logging level.
public var level: Logboard.Level = .info
public var level: LBLogger.Level = .info
/// Specifies logging appenders.
public var appender: LogboardAppender = ConsoleAppender()
public var appender: LBLoggerAppender = ConsoleAppender()

/// Create a logger with the identifier.
public init(_ identifier: String) {
self.identifier = identifier
}

/// Is logging enabled for the supplied level or not.
public func isEnabledFor(level: Logboard.Level) -> Bool {
public func isEnabledFor(level: LBLogger.Level) -> Bool {
return self.level.rawValue <= level.rawValue
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

/// An interface that manages the logging appending.
public protocol LogboardAppender {
public protocol LBLoggerAppender {
/// Appends a logging message string.
func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int)
func append(_ logboard: LBLogger, level: LBLogger.Level, message: [Any], file: StaticString, function: StaticString, line: Int)

/// Appends a logging message with a format sting.
func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int)
func append(_ logboard: LBLogger, level: LBLogger.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int)
}
8 changes: 4 additions & 4 deletions Sources/Logboard/MultiAppender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import Foundation
/// multi.appenders.append(SocketAppender())
/// logger.appender = multi
/// ```
public class MultiAppender: LogboardAppender {
public class MultiAppender: LBLoggerAppender {
/// The appenders.
public var appenders: [LogboardAppender] = []
public var appenders: [LBLoggerAppender] = []

public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
for appender in appenders {
appender.append(logboard, level: level, message: message, file: file, function: function, line: line)
}
}

public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
for appender in appenders {
appender.append(logboard, level: level, format: format, arguments: arguments, file: file, function: function, line: line)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Logboard/NullAppender.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

/// The NullAppender class does output no message.
public class NullAppender: LogboardAppender {
public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
public class NullAppender: LBLoggerAppender {
public func append(_ logboard: LBLogger, level: LBLogger.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
}

public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import OSLog
@available(macOS 11.0, *)
@available(tvOS 14.0, *)
@available(watchOS 7.0, *)
public class OSLoggerAppender: LogboardAppender {
public class OSLoggerAppender: LBLoggerAppender {
private let logger: Logger

/// Creates a logger using the specified subsystem and category.
public init(sybsystem: String, category: String) {
logger = Logger(subsystem: sybsystem, category: category)
}

public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
let message =
"[\(filename(file.description)):\(line)]" +
function.description +
Expand All @@ -38,7 +38,7 @@ public class OSLoggerAppender: LogboardAppender {
}
}

public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
let message =
"[\(filename(file.description)):\(line)]" +
function.description +
Expand Down
10 changes: 5 additions & 5 deletions Sources/Logboard/SocketAppender.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// The SocketAppender class writes a message to LogboardConsole service.
public class SocketAppender: LogboardAppender {
public class SocketAppender: LBLoggerAppender {
private var socket: NetSocket = NetSocket()

/// Connects the Logboard Console service.
Expand All @@ -14,9 +14,9 @@ public class SocketAppender: LogboardAppender {
socket.close(isDisconnected: false)
}

public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
let strings: [String] = [
Logboard.dateFormatter.string(from: Date()),
LBLogger.dateFormatter.string(from: Date()),
level.description,
logboard.identifier,
file.description,
Expand All @@ -29,9 +29,9 @@ public class SocketAppender: LogboardAppender {
}
}

public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
public func append(_ logboard: LBLogger, level: LBLogger.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
let strings: [String] = [
Logboard.dateFormatter.string(from: Date()),
LBLogger.dateFormatter.string(from: Date()),
level.description,
logboard.identifier,
file.description,
Expand Down
Loading

0 comments on commit 0213f0b

Please sign in to comment.