CCLog

public class CCLog

The Log class provides generic logging functionality with overridable closures to be used for redirecting log output.

The logger provides closures for overriding various behaviors: Logging proceeds through the following path: CCLog.x –> xPrint –> xFormatter –> defaultLogPrint - CCLog.x : - Log entry point for all logging. Static, cannot be overriden. - xPrint : - Calls the formatter to obtain the log format, then defaultLogPrint on the proper queue to perform the logging. - Debug (.d, dPrint) and Test (.t, tPrint) calls are compiler flagged out using the DEBUG flag - This is a static var containing a closure. Assign your own closure at runtime to override the default behavior, for example if you want the debug or test log statements to occur without the DEBUG flag set. - If you do override, please ensure that you spin off your logging onto the dispatchQueue (note the lowercase…) for optimal performance. defaultLogPrint will correct the queue if you forget, but this will involve an extra call. - xFormatter: - Processes the provided inputs into the formatted string for output on screen. - This is a static var containing a closure. Assign your own closure at runtime to override the default behavior, for example to remove the [TEST] or DEBUG formatting. - defaultLogPrint: - Final log function, which iterates through the user assigned log handlers and finally prints to console. Static, cannot be overriden. - addLogHandler: - Log handlers are called every time a CCLog.x call is made (inside defaultLogPrint). - Called from the dispatchQueue (lowercase…) queue. - Returns an integer which can be used to remove the log handler in the future (for example once your ViewController closes). Contains weak references to the handlers, but if you don’t tell us to remove the handler it will still cost cycles to iterate over the no longer valid handlers. - removeLogHandler: - Removes a log handler using the integer index returned from addLogHandler - timeStampEnabled: - When true, a timestamp will be added to the beginning of every statement (default false) - dateFormatter: - The formatter used to provide the time stamp for timeStampEnabled. - Set the format at runtime to change the time stamp format. - verbosePrinting: - When true, logs are printed in full - When false, logs are truncated to the maxPrintingLength (default) - maxPrintingLength: - The maximum length of logs printed when verbsePrinting is false

By default, Debug and Test level logs do nothing unless the DEBUG compiler flag is set.

  • true: a timestamp will be added to the beggining of the log statments. Defaults to false.

    Declaration

    Swift

    public static var timestampEnabled: Bool
  • false: log statements are truncated to the length specified in maxPrintingLength true: log statements are not truncated

    Declaration

    Swift

    public static var verbosePrinting: Bool
  • when verbosePrinting is set to false, all log statements will be truncated to this length

    Declaration

    Swift

    public static var maxPrintingLength: Int
  • the DateFormatter used to print the timestamp on log statements. Default format is “yyyy-MM-dd HH:mm:ss.SSS”.

    Declaration

    Swift

    public static var dateFormatter: DateFormatter
  • Debug level print statement Calls dPrint with the arguments provided

    Declaration

    Swift

    public static func d(_ format: String, args: CVarArg..., line: Int = #line, file: String = #file)
  • Test level print statement Calls tPrint with the arguments provided

    Declaration

    Swift

    public static func t(_ format: String, args: CVarArg..., line: Int = #line, file: String = #file)
  • Warning level print statement Calls wPrint with the arguments provided

    Declaration

    Swift

    public static func w(_ format: String, args: CVarArg..., line: Int = #line, file: String = #file)
  • Serious level print statement Calls sPrint with the arguments provided

    Declaration

    Swift

    public static func s(_ format: String, args: CVarArg..., line: Int = #line, file: String = #file)
  • Override point for debug level print statements Calls dFormatter to obtain the formatted string Calls defaultLogPrint on the dispatchQueue By default does not run unless the DEBUG compiler flag is set

    Declaration

    Swift

    public static var dPrint: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> ()
  • Override point for test level print statements Calls tFormatter to obtain the formatted string Calls defaultLogPrint on the dispatchQueue By default does not run unless the DEBUG compiler flag is set

    Declaration

    Swift

    public static var tPrint: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> ()
  • Override point for warning level print statements Calls wFormatter to obtain the formatted string Calls defaultLogPrint on the dispatchQueue

    Declaration

    Swift

    public static var wPrint: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> ()
  • Override point for serious level print statements Calls sFormatter to obtain the formatted string Calls defaultLogPrint on the dispatchQueue

    Declaration

    Swift

    public static var sPrint: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> ()
  • Override point for debug level print statement formatting Without overriding, prints with the format “LineNumber : FileName DEBUG

    Declaration

    Swift

    public static var dFormatter: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> (String)
  • Override point for test level print statement formatting Without overriding, prints with the format “LineNumber : FileName [TEST]

    Declaration

    Swift

    public static var tFormatter: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> (String)
  • Override point for warning level print statement formatting Without overriding, prints with the format “LineNumber : FileName ! WARNING !

    Declaration

    Swift

    public static var wFormatter: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> (String)
  • Override point for severe level print statement formatting Without overriding, prints with the format “LineNumber : FileName !! SEVERE !!

    Declaration

    Swift

    public static var sFormatter: (_ format: String, _ args: [CVarArg], _ line: Int, _ file: String) -> (String)
  • Declaration

    Swift

    public static var dispatchQueue: DispatchQueue
  • the default logger - always call this last if you override xPrint. always call on the dispatchQueue thread.

    Declaration

    Swift

    public static func defaultLogPrint(_ string: String, respawn: Bool = true)
  • Add a custom log handler to receive callbacks whenever a Log.x statement is posted. Returns the index value for use in removing your handler at a later time Log handlers will be called from a background thread

    Declaration

    Swift

    public static func addLogHandler(handler: @escaping (_ string: String) -> ()) -> Int
  • Removes a log handler from the system. Pass in the index value you received when you called addLogHandler.

    Declaration

    Swift

    public static func removeLogHandler(handlerIndex: Int)