美文网首页
【转】自定义print

【转】自定义print

作者: Sonoface | 来源:发表于2020-11-16 17:09 被阅读0次

转自:https://blog.csdn.net/bobbob32/article/details/104011204

public func Fprint(_ items: Any...,
                    separator: String = " ",
                   terminator: String = "\n",
                   _ file:String = #file,
                   _ function:String = #function,
                   _ line:Int = #line){
    var longStr:String = ""
    for value in items{
        var stringRepresentation:String = ""
        if let value = value as? CustomStringConvertible{
            stringRepresentation = value.description
        }else if let value = value as? CustomDebugStringConvertible{
            stringRepresentation = value.debugDescription
        }else if let value = value as? LosslessStringConvertible{
            stringRepresentation = value.description
        } else{
            // fatalError("glog only work for values that conform to CustomStringConvertible or CustomDebugStringConvertible")
            // print(objct)
        }

        //longStr = longStr + "," + stringRepresentation
        ///下面 的方式更加符合原版的print
        longStr += stringRepresentation
        
    }
    
    let gFormatter = DateFormatter()
    gFormatter.dateFormat = "HH:mm:ss:SSS"
    let timeStamp = gFormatter.string(from: Date())
    let queue = Thread.isMainThread ? "UI":"BG"
    let fileUrl = NSURL(string: file)?.lastPathComponent ?? "Unknown file"
    
    if longStr.count > items.count{
        print("FM \(timeStamp) {\(queue)} \(fileUrl) > \(function)[\(line)]: \(longStr)")
    }else{
        print("FM \(timeStamp) {\(queue)} \(fileUrl) > \(function)[\(line)]: \(items)")
    }
}

参考 https://www.jianshu.com/p/de222deded93
感谢 🙏 前人种树 后人乘凉

相关文章

  • 【转】自定义print

    转自:https://blog.csdn.net/bobbob32/article/details/1040112...

  • Function 函数

    自定义函数 def say_hello():print("Hi, there!")print("Welcome t...

  • iOS - Description

    自定义 po 打印,print & NSLog 类的打印输出 description - print 日志输出 d...

  • 6.Dart-函数作用域

    /** * 内置方法/ 函数: * print() * * 自定义方法: * 自定义方法的基本格式 * 返回...

  • Swift5 Print相关

    1、Tips 自定义 print:CustomStringConvertible 协议;debugPrint:Cu...

  • 自定义Log

    实现的功能: 在需要print的时候,利用自定义Log输出当前print语句所在文件及代码所在行数. #if DE...

  • 入门(一)

    转自:crossin的编程教室 一. python 2 到 3 的新手坑 1. print() print("He...

  • Swift 自定义 Print()

    在项目中添加全局方法(可以直接创建一个swift文件,把方法拷贝就好了) 其中 ** DEBUGLOG** 是一个...

  • Dart中的函数-----上

    一、内置方法/函数 print(); 二、自定义方法 三、传参 方法的作用域

  • fasta文处理

    fastq 转fasta文件: awk '{if(NR%4 == 1){print ">" substr($0, ...

网友评论

      本文标题:【转】自定义print

      本文链接:https://www.haomeiwen.com/subject/bcjzbktx.html