Skip to content

Commit

Permalink
Logger: toggle DEBUG and TRACE logs via process environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyl committed Jun 17, 2021
1 parent 53ff597 commit 51a5745
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/CornucopiaCore/Logging/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public extension Cornucopia.Core {
/// with loads of #if/#else/#endif – which is non-negotiable in my opinion.
struct Logger {

public static let includeDebug: Bool = ProcessInfo.processInfo.environment["LOGLEVEL"] == "DEBUG" || Self.includeTrace
public static let includeTrace: Bool = ProcessInfo.processInfo.environment["LOGLEVEL"] == "TRACE"

/// The log level.
public enum Level: String {
case trace
Expand Down Expand Up @@ -72,14 +75,14 @@ public extension Cornucopia.Core {
/// Log a trace message. Trace messages are only processed, if the preprocessor symbols DEBUG and TRACE are set.
@inlinable
public func trace(_ message: @autoclosure ()->String ) {
#if DEBUG && TRACE
guard Self.includeTrace else { return }
os_log("%s", log: oslog, type: .debug, message())
#endif
}

/// Log a debug message.
@inlinable
public func debug(_ message: @autoclosure () -> String) {
guard Self.includeDebug else { return }
os_log("%s", log: oslog, type: .debug, message())
}

Expand Down

0 comments on commit 51a5745

Please sign in to comment.