<commit_before>//
//  SwiftLog.swift
//  SwiftLogDemo
//
//  Created by 童进 on 15/10/12.
//  Copyright © 2015年 qefee. All rights reserved.
//

import Foundation

public class SwiftLog {
    /// log level. Print logs which >= logLevel
    public var logLevel: LogLevel
    /// date format
    public var dateFormat: String = "yyyy-MM-dd HH:mm:ss.SSS"
    {
        didSet {
            dateFormatter.dateFormat = dateFormat
        }
    }
    /// date formatter
    private var dateFormatter: NSDateFormatter = NSDateFormatter()

    /**
    init with LogLevel.Debug
    */
    public convenience init() {
        self.init(logLevel: LogLevel.Debug)
    }

    public init(logLevel: LogLevel) {
        self.logLevel = logLevel
        self.dateFormatter.dateFormat = dateFormat
    }
    
    /**
    print verbose log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func v(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Verbose, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print debug log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func d(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Debug, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print info log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func i(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Info, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print warn log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func w(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Warn, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print error log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func e(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Error, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print assert log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func a(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Assert, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print log.
    If you want to custom log format, change this function.
    
    - parameter logLevel:     logLevel
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func printLog(logLevel: LogLevel, msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        if self.logLevel > logLevel {
            return
        }
        
        let date = dateFormatter.stringFromDate(NSDate())
        let file = NSString(string: fileName).lastPathComponent
        let fun = functionName
        let line = lineNum
        let col = columnNum
        let lvl = logLevel
        
        print("\(date) \(file) : \(fun) : \(line) : \(col) \(lvl) \(msg)")
    }
}

<commit_msg>add howToLog<commit_after>//
//  SwiftLog.swift
//  SwiftLogDemo
//
//  Created by 童进 on 15/10/12.
//  Copyright © 2015年 qefee. All rights reserved.
//

import Foundation

public class SwiftLog {
    /// how to log
    public var howToLog: ((logLevel: LogLevel, msg: String, fileName: String, functionName: String, lineNum: Int, columnNum: Int) -> Void)?
    /// log level. Print logs which >= logLevel
    public var logLevel: LogLevel
    /// date format
    public var dateFormat: String = "yyyy-MM-dd HH:mm:ss.SSS"
    {
        didSet {
            dateFormatter.dateFormat = dateFormat
        }
    }
    /// date formatter
    private var dateFormatter: NSDateFormatter = NSDateFormatter()

    /**
    init with LogLevel.Debug
    */
    public convenience init() {
        self.init(logLevel: LogLevel.Debug)
    }

    public init(logLevel: LogLevel) {
        self.logLevel = logLevel
        self.dateFormatter.dateFormat = dateFormat
    }
    
    /**
    print verbose log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func v(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Verbose, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print debug log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func d(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Debug, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print info log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func i(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Info, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print warn log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func w(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Warn, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print error log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func e(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Error, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    print assert log.
    
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func a(msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        printLog(LogLevel.Assert, msg: msg, fileName: fileName, functionName: functionName, lineNum: lineNum, columnNum: columnNum)
    }
    
    /**
    execute log.
    If you want to custom log format, change howToLog.
    
    - parameter logLevel:     logLevel
    - parameter msg:          msg
    - parameter fileName:     fileName
    - parameter functionName: functionName
    - parameter lineNum:      lineNum
    - parameter columnNum:    columnNum
    */
    public func printLog(logLevel: LogLevel, msg: String, fileName: String = #file, functionName: String = #function, lineNum: Int = #line, columnNum: Int = #column) {
        if self.logLevel > logLevel {
            return
        }
        
        let date = dateFormatter.stringFromDate(NSDate())
        let file = NSString(string: fileName).lastPathComponent
        let fun = functionName
        let line = lineNum
        let col = columnNum
        let lvl = logLevel
        
        if let h = howToLog {
            h(logLevel: lvl, msg: msg, fileName: file, functionName: fun, lineNum: line, columnNum: col)
        } else {
            print("\(date) \(file) : \(fun) : \(line) : \(col) \(lvl) \(msg)")
        }
    }
}


{'fraction_non_alphanumeric': 0.09916524187870863, 'fraction_numerical': 0.002011465352509303, 'mean_word_length': 2.345895020188425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4787171', 'n_tokens_mistral': 2824, 'n_tokens_neox': 2859, 'n_words': 858}