From 37818d3153e7061ff135cb81d106364ff3b959a1 Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Tue, 27 Sep 2022 20:00:44 +0300 Subject: [PATCH] feat: basic logger --- TILogging/Sources/Logger.swift | 52 +++++++++++++++++++++ TILogging/Sources/LoggerRepresentable.swift | 5 ++ TILogging/TILogging.podspec | 15 ++++++ 3 files changed, 72 insertions(+) create mode 100644 TILogging/Sources/Logger.swift create mode 100644 TILogging/Sources/LoggerRepresentable.swift create mode 100644 TILogging/TILogging.podspec diff --git a/TILogging/Sources/Logger.swift b/TILogging/Sources/Logger.swift new file mode 100644 index 00000000..5eb345c1 --- /dev/null +++ b/TILogging/Sources/Logger.swift @@ -0,0 +1,52 @@ +import os + +public struct TILogger: LoggerRepresentable { + + // MARK: - Properties + + public static let defaultLogger = TILogger(subsystem: .defaultSubsystem ?? "", category: .pointsOfInterest) + + public let logInfo: OSLog + + // MARK: - Init + + public init(subsystem: String, category: String) { + self.logInfo = .init(subsystem: subsystem, category: category) + } + + public init(subsystem: String, category: OSLog.Category) { + self.logInfo = .init(subsystem: subsystem, category: category) + } + + // MARK: - LoggerRepresentable + + public func log(_ message: StaticString, log: OSLog?, type: OSLogType, _ arguments: CVarArg...) { + os_log(message, log: log ?? logInfo, type: type, arguments) + } + + // MARK: - Public methods + + public func verbose(_ message: StaticString, _ arguments: CVarArg...) { + self.log(message, log: logInfo, type: .default, arguments) + } + + public func info(_ message: StaticString, _ arguments: CVarArg...) { + self.log(message, log: logInfo, type: .info, arguments) + } + + public func debug(_ message: StaticString, _ arguments: CVarArg...) { + self.log(message, log: logInfo, type: .debug, arguments) + } + + public func error(_ message: StaticString, _ arguments: CVarArg...) { + self.log(message, log: logInfo, type: .error, arguments) + } + + public func fault(_ message: StaticString, _ arguments: CVarArg...) { + self.log(message, log: logInfo, type: .fault, arguments) + } +} + +private extension String { + static let defaultSubsystem = Bundle.main.bundleIdentifier +} diff --git a/TILogging/Sources/LoggerRepresentable.swift b/TILogging/Sources/LoggerRepresentable.swift new file mode 100644 index 00000000..c5a95beb --- /dev/null +++ b/TILogging/Sources/LoggerRepresentable.swift @@ -0,0 +1,5 @@ +import os + +public protocol LoggerRepresentable { + func log(_ message: StaticString, log: OSLog?, type: OSLogType, _ arguments: CVarArg...) +} diff --git a/TILogging/TILogging.podspec b/TILogging/TILogging.podspec new file mode 100644 index 00000000..cbcd20ef --- /dev/null +++ b/TILogging/TILogging.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |s| + s.name = 'TILogging' + s.version = '1.27.0' + s.summary = 'Logging API' + s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { 'petropavel13' => 'ivan.smolin@touchin.ru' } + s.source = { :git => 'https://github.com/TouchInstinct/LeadKit.git', :tag => s.version.to_s } + + s.ios.deployment_target = '10.0' + s.swift_versions = ['5.3'] + + s.source_files = s.name + '/Sources/**/*' + +end