swift NSLog的Swift替代品

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift NSLog的Swift替代品相关的知识,希望对你有一定的参考价值。

Stuff.print("Just as the standard print but now with detailed information")
Stuff.print("Now it's a warning", .warn)
Stuff.print("Or even an error", .error)

Stuff.minimumLogLevel = .error
Stuff.print("Now you won't see normal log output")
Stuff.print("Only errors are shown", .error)

Stuff.minimumLogLevel = .none
Stuff.print("Or if it's disabled you won't see any log", .error)    
public class Stuff {

    public enum logLevel: Int {
        case info = 1
        case debug = 2
        case warn = 3
        case error = 4
        case fatal = 5
        case none = 6

        public func description() -> String {
            switch self {
            case .info:
                return "❓"
            case .debug:
                return "✳️"
            case .warn:
                return "⚠️"
            case .error:
                return "

以上是关于swift NSLog的Swift替代品的主要内容,如果未能解决你的问题,请参考以下文章

是否有NSLog的Swift替代方案(@“%s”,__ PRETTY_FUNCTION__)

Swift中使用NSLog的问题

Swift:摆脱时间戳 NSLog()

我可以将 NSLog 与 Swift 结构一起使用吗?

使用 NSLog 记录 Swift 枚举

在 Swift 项目中为生产禁用 NSLog