Skip to content
Egor Badmaev edited this page Dec 5, 2022 · 6 revisions

Logger

A utility for writing string messages in debug mode.

log(_:logType:shouldLogContext:file:function:line:)

Writes a message to the log using the specified log type.

Signature:

public static func log(_ message: @autoclosure () -> String, logType: LogType, shouldLogContext: Bool = true, file: String = #fileID, function: String = #function, line: Int = #line)

Parameters:

  • message: log message
  • logType: log type.
  • shouldLogContext: defines whether to log Context or not.
  • file: The name of the file and module in which it appears.
  • function: The name of the declaration in which it appears.
  • line: The line number on which it appears.

message is a closure in order to add the ability to create a string to log inside method's calling.

It is @autoclosure in order to simplify usage. More on Swift Docs

createLog(logType:shouldLogContext:context:)

Creates log with provided information.

Signature:

static func createLog(logType: LogType, message: @autoclosure () -> String, shouldLogContext: Bool, context: Context = Context()) -> String

Parameters:

  • message: log message
  • logType: log type.
  • shouldLogContext: defines whether to log Context or not.
  • file: The name of the file and module in which it appears.
  • function: The name of the declaration in which it appears.
  • line: The line number on which it appears.

This method has internal access-level in order to call it inside unit-tests.

debugPrint(message:)

Prints message when debug mode is active.

Signature:

private static func debugPrint(_ message: String)

Parameters:

  • message: log message with String type to print