mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
♻️ Added logger class
This commit is contained in:
@ -42,8 +42,8 @@ class Actions {
|
||||
availableVersions: [String],
|
||||
completed: @escaping () -> Void
|
||||
) {
|
||||
print("Switching to \(version) using Valet")
|
||||
print(valet("use php@\(version)"))
|
||||
Log.info("Switching to \(version) using Valet")
|
||||
Log.info(valet("use php@\(version)"))
|
||||
completed()
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ class Actions {
|
||||
availableVersions: [String],
|
||||
completed: @escaping () -> Void
|
||||
) {
|
||||
print("Switching to \(version), unlinking all versions...")
|
||||
Log.info("Switching to \(version), unlinking all versions...")
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
@ -80,14 +80,14 @@ class Actions {
|
||||
}
|
||||
|
||||
group.notify(queue: .global(qos: .userInitiated)) {
|
||||
print("All versions have been unlinked!")
|
||||
print("Linking the new version!")
|
||||
Log.info("All versions have been unlinked!")
|
||||
Log.info("Linking the new version!")
|
||||
|
||||
let formula = (version == PhpSwitcher.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
brew("link \(formula) --overwrite --force")
|
||||
brew("services start \(formula)", sudo: true)
|
||||
|
||||
print("The new version has been linked!")
|
||||
Log.info("The new version has been linked!")
|
||||
completed()
|
||||
}
|
||||
}
|
||||
|
52
phpmon-common/Core/Logger.swift
Normal file
52
phpmon-common/Core/Logger.swift
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// Logger.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 21/12/2021.
|
||||
// Copyright © 2021 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class Log {
|
||||
|
||||
enum Verbosity: Int {
|
||||
case error = 1,
|
||||
info = 2,
|
||||
warning = 3,
|
||||
performance = 4
|
||||
|
||||
public func isApplicable() -> Bool {
|
||||
return Log.shared.verbosity.rawValue >= self.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
static var shared = Log()
|
||||
|
||||
var verbosity: Verbosity = .info
|
||||
|
||||
static func info(_ item: Any) {
|
||||
if Verbosity.info.isApplicable() {
|
||||
print(item)
|
||||
}
|
||||
}
|
||||
|
||||
static func err(_ item: Any) {
|
||||
if Verbosity.error.isApplicable() {
|
||||
print(item)
|
||||
}
|
||||
}
|
||||
|
||||
static func warn(_ item: Any) {
|
||||
if Verbosity.warning.isApplicable() {
|
||||
print(item)
|
||||
}
|
||||
}
|
||||
|
||||
static func perf(_ item: Any) {
|
||||
if Verbosity.performance.isApplicable() {
|
||||
print(item)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user