Skip to content

Commit

Permalink
feat: logging
Browse files Browse the repository at this point in the history
enable standard logging
  • Loading branch information
bsorrentino committed Oct 4, 2022
1 parent a4e38b4 commit 7e410d3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct FileCollector {

if let include = fileOptions?.include, !include.isEmpty {
searchPaths = ["."]
Logger.shared.info("paths will be ignored in favor of configuration (files:include: \(include.joined(separator: ", ")))")
logger.info("paths will be ignored in favor of configuration (files:include: \(include.joined(separator: ", ")))")
}

let allFiles = getFiles(for: searchPaths, in: directory)
Expand Down
77 changes: 2 additions & 75 deletions PlantUMLFramework/Sources/PlantUMLFramework/Logging/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,78 +1,5 @@
import Foundation
import OSLog

/// A log level can be used to make logging conditional, e.g. only errors with log level `error` but log infos, warning and errors with log level `info`
public enum LogLevel: Comparable {
/// error
case error
/// warning
case warning
/// info
case info
/// debug
case debug
}
public let logger = Logger(subsystem: "org.bsc.PlantUML", category: "main")

/// common interface for Loggers
public protocol Logging {
/// log an error
/// - Parameters:
/// - message: to be logged
/// - file: in which the message occurred
/// - function: in wich the message occurred
/// - line: line number in which the message occurred
/// - Parameter message: to be logged
func error(_ message: String, _ file: String, _ function: String, _ line: Int)

/// log a warning
/// - Parameters:
/// - message: to be logged
/// - file: in which the message occurred
/// - function: in wich the message occurred
/// - line: line number in which the message occurred
func warning(_ message: String, _ file: String, _ function: String, _ line: Int)

/// log an info
/// - Parameters:
/// - message: to be logged
/// - file: in which the message occurred
/// - function: in wich the message occurred
/// - line: line number in which the message occurred
func info(_ message: String, _ file: String, _ function: String, _ line: Int)

/// log debugging-related info
/// - Parameters:
/// - message: to be logged
/// - file: in which the message occurred
/// - function: in wich the message occurred
/// - line: line number in which the message occurred
func debug(_ message: String, _ file: String, _ function: String, _ line: Int)
}

/// :nodoc:
public extension Logging {
/// :nodoc:
func error(_ message: String, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
error(message, file, function, line)
}

/// :nodoc:
func warning(_ message: String, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
warning(message, file, function, line)
}

/// :nodoc:
func info(_ message: String, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
info(message, file, function, line)
}

/// :nodoc:
func debug(_ message: String, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
debug(message, file, function, line)
}
}

/// :nodoc:
public enum Logger {
/// singleton to access logger througout the SwiftPlantUMLFramework
public static var shared: Logging = NoLogger()
}
19 changes: 0 additions & 19 deletions PlantUMLFramework/Sources/PlantUMLFramework/Logging/NoLogger.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct PlantUMLScript : CustomStringConvertible {
@enduml
"""

Logger.shared.debug("PlantUML script created in \(Date().timeIntervalSince(methodStart)) seconds")
logger.trace("PlantUML script created in \(Date().timeIntervalSince(methodStart)) seconds")
}

/**
Expand Down

0 comments on commit 7e410d3

Please sign in to comment.