Initial Commit
This commit is contained in:
parent
a1fd9eee98
commit
22f9c06308
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
|
@ -0,0 +1,30 @@
|
|||
// swift-tools-version:5.3
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "zealous-logger",
|
||||
platforms: [.macOS(.v10_12),
|
||||
.iOS(.v12)],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "zealous-logger",
|
||||
targets: ["zealous-logger"]),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "zealous-logger",
|
||||
dependencies: []),
|
||||
.testTarget(
|
||||
name: "zealous-loggerTests",
|
||||
dependencies: ["zealous-logger"]),
|
||||
]
|
||||
)
|
|
@ -0,0 +1,72 @@
|
|||
//
|
||||
// ConsoleLogger.swift
|
||||
//
|
||||
//
|
||||
// Created by Francisco Gindre on 3/8/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os
|
||||
|
||||
class ConsoleLogger: Logger {
|
||||
enum LogLevel: Int {
|
||||
case debug
|
||||
case error
|
||||
case warning
|
||||
case event
|
||||
case info
|
||||
}
|
||||
|
||||
enum LoggerType {
|
||||
case osLog
|
||||
case printerLog
|
||||
}
|
||||
|
||||
var level: LogLevel
|
||||
var loggerType: LoggerType
|
||||
|
||||
init(logLevel: LogLevel, type: LoggerType = .osLog) {
|
||||
self.level = logLevel
|
||||
self.loggerType = type
|
||||
}
|
||||
|
||||
private static let subsystem = Bundle.main.bundleIdentifier!
|
||||
|
||||
@available(OSX 10.12, *)
|
||||
static let oslog = OSLog(subsystem: subsystem, category: "logs")
|
||||
|
||||
func debug(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
|
||||
guard level.rawValue == LogLevel.debug.rawValue else { return }
|
||||
log(level: "DEBUG 🐞", message: message, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
func error(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
|
||||
guard level.rawValue <= LogLevel.error.rawValue else { return }
|
||||
log(level: "ERROR 💥", message: message, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
func warn(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
|
||||
guard level.rawValue <= LogLevel.warning.rawValue else { return }
|
||||
log(level: "WARNING ⚠️", message: message, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
func event(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
|
||||
guard level.rawValue <= LogLevel.event.rawValue else { return }
|
||||
log(level: "EVENT ⏱", message: message, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
func info(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
|
||||
guard level.rawValue <= LogLevel.info.rawValue else { return }
|
||||
log(level: "INFO ℹ️", message: message, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
private func log(level: String, message: String, file: String, function: String, line: Int) {
|
||||
let fileName = (file as NSString).lastPathComponent
|
||||
switch loggerType {
|
||||
case .printerLog:
|
||||
print("[\(level)] \(fileName) - \(function) - line: \(line) -> \(message)")
|
||||
default:
|
||||
os_log("[%{public}@] %{public}@ - %{public}@ - Line: %{public}d -> %{public}@", level, fileName, function, line, message)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import Foundation
|
||||
/**
|
||||
Represents what's expected from a logging entity
|
||||
*/
|
||||
public protocol Logger {
|
||||
|
||||
func debug(_ message: String, file: String, function: String, line: Int)
|
||||
|
||||
func info(_ message: String, file: String, function: String, line: Int)
|
||||
|
||||
func event(_ message: String, file: String, function: String, line: Int)
|
||||
|
||||
func warn(_ message: String, file: String, function: String, line: Int)
|
||||
|
||||
func error(_ message: String, file: String, function: String, line: Int)
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import XCTest
|
||||
|
||||
import zealous_loggerTests
|
||||
|
||||
var tests = [XCTestCaseEntry]()
|
||||
tests += zealous_loggerTests.allTests()
|
||||
XCTMain(tests)
|
|
@ -0,0 +1,9 @@
|
|||
import XCTest
|
||||
|
||||
#if !canImport(ObjectiveC)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(zealous_loggerTests.allTests),
|
||||
]
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,15 @@
|
|||
import XCTest
|
||||
@testable import zealous_logger
|
||||
|
||||
final class zealous_loggerTests: XCTestCase {
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||
// results.
|
||||
//XCTAssertEqual(zealous_logger().text, "Hello, World!")
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testExample", testExample),
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue