Emcee

Форк
0
/
NSLogLikeLogEntryTextFormatter.swift 
38 строк · 1.3 Кб
1
import Foundation
2

3
public final class NSLogLikeLogEntryTextFormatter: LogEntryTextFormatter {
4
    
5
    // 2018-03-29 19:05:01.994
6
    public static let logDateFormatter: DateFormatter = {
7
        let logFormatter = DateFormatter()
8
        logFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
9
        logFormatter.timeZone = TimeZone.autoupdatingCurrent
10
        return logFormatter
11
    }()
12
    
13
    public init() {}
14
    
15
    public func format(logEntry: LogEntry) -> String {
16
        let timeStamp = NSLogLikeLogEntryTextFormatter.logDateFormatter.string(from: logEntry.timestamp)
17
        
18
        let filename = (logEntry.file as NSString).lastPathComponent
19
        
20
        // [LEVEL] 2018-03-29 19:05:01.994 <file:line> <coordinate1> [<coordinate2> [...]]: <mesage>
21
        var result = "[\(logEntry.verbosity.stringCode)] \(timeStamp) \(filename):\(logEntry.line)"
22
        if !logEntry.coordinates.isEmpty {
23
            result += " " + logEntry.coordinates.map { "\($0.stringValue)" }.joined(separator: " ")
24
        }
25
        result += ": " + logEntry.message
26
        return result
27
    }
28
}
29

30
extension LogEntryCoordinate {
31
    public var stringValue: String {
32
        var result = name
33
        if let value = value {
34
            result += ":\(value)"
35
        }
36
        return result
37
    }
38
}
39

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.