//
//  Logger.swift
//  OneWeather
//
//  Created by Demid Merzlyakov on 18.01.2021.
//  Copyright © 2021 OneLouder, Inc. All rights reserved.
//

import Foundation

final class Logger {
    
    enum LogLevel {
        case debug
        case info
        case warning
        case error
    }
    
    static let prefix = "psm_1w"
    
    var componentName: String
    
    init(componentName: String) {
        self.componentName = componentName
    }
    
    func log(level: LogLevel, message: String) {
        #if DEBUG
        NSLog("\(Logger.prefix) \(componentName) [\(logLevelString(level: level))]: \(message)")
        #endif
    }
    
    func debug(_ message: String) {
        log(level: .debug, message: message)
    }
    
    func info(_ message: String) {
        log(level: .info, message: message)
    }
    
    func warning(_ message: String) {
        log(level: .warning, message: message)
    }
    
    func error(_ message: String) {
        log(level: .error, message: message)
    }
    
    private func logLevelString(level: LogLevel) -> String {
        switch level {
        case .debug:
            return "DEBUG"
        case .info:
            return "INFO"
        case .warning:
            return "WARN"
        case .error:
            return "ERROR"
        }
    }
}
