TraceLog


About TraceLog

TraceLog is a powerful logging framework for iOS and macOS applications. It provides developers with an easy-to-use and flexible logging solution, offering various features to enhance debugging and improve code maintenance.


Key Features

  • Flexible and customizable logging:
    • Easily add logging statements throughout your codebase.
    • Customize log levels, formats, and destinations.

  • Multiple log destinations:
    • Console: Output logs to the Xcode console.
    • File: Save logs to a file for later analysis.
    • Custom: Implement your own log destination.

  • Log filtering and masking:
    • Filter log messages based on severity level.
    • Mask sensitive information to protect user privacy.

  • Thread and queue information:
    • Track threads and queues for easy debugging.

  • Powerful logging options:
    • Enable/disable logging globally.
    • Toggle the verbosity of logs at runtime.

  • Extensible and lightweight:
    • Easy integration into new or existing projects.
    • No external dependencies.


Installation

To install TraceLog, follow these steps:

  1. Open your terminal.
  2. Navigate to your project directory.
  3. Run the following command to add TraceLog as a dependency using CocoaPods:
  4. pod 'TraceLog'

  5. Save the changes and run pod install in your terminal.
  6. Open the generated .xcworkspace file.
  7. You can now import and use TraceLog in your project.


Usage

To start using TraceLog in your application, you need to follow these steps:

  1. Import the TraceLog module in the files where you want to use it:
  2. import TraceLog

  3. Use the various logging functions provided:
  4. TraceLog.verbose("This is a verbose log message.")

  5. Customize log levels, formats, and destinations as per your requirements:
  6. TraceLog.logLevel = .info
    TraceLog.logFormat = .verbose
    TraceLog.logDestination = .console


Custom Log Formats

You can define custom log formats using placeholders to include additional information in the log output:

  • %d: Date and time of the log event.
  • %n: Name of the logger.
  • %l: Log level of the message.
  • %M: Method name where the log statement was invoked.
  • %F: File name where the log statement was invoked.
  • %L: Line number where the log statement was invoked.
  • %@: The log message.


Examples

Here are some examples to help you understand how to utilize the TraceLog framework effectively:

  • Simple log statement:
  • TraceLog.verbose("This is a verbose log message.")

  • Log statement with custom format:
  • TraceLog.logFormat = "[%d] [%l] %@" // Output: [2022-01-01 10:00:00] [VERBOSE] This is a verbose log message.

  • Filter log messages:
  • TraceLog.logLevel = .warning // Only logs with warning level or above will be displayed.

  • Save logs to a file:
  • TraceLog.logDestination = .file("logs.txt") // Logs will be saved to the specified file.


Conclusion

TraceLog is a robust and efficient logging framework that simplifies debugging for iOS and macOS applications. With its flexible configuration and powerful features, developers can efficiently track and analyze application behavior to identify and resolve issues.