Welcome to the documentation for jjSwiftLog, a Swift logging framework!
Table of Contents
- Introduction
- Installation
- Getting Started
- Logging
- Log Levels
- Using Formatters
- Defining Destinations
- Performing Log Actions
- Custom Destinations
- Advanced Usage
Installation
To install jjSwiftLog framework, you can use CocoaPods. Add the following line to your Podfile:
pod 'jjSwiftLog'
Getting Started
To get started with jjSwiftLog, follow the steps below:
- Import the jjSwiftLog module into your Swift file.
- Initialize the logger instance:
import jjSwiftLog
let logger = jjSwiftLog.shared
You are now ready to log messages using jjSwiftLog!
Logging
To log a message, call the appropriate function on the logger instance:
logger.debug("This is a debug message.")
logger.info("This is an informational message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
Log Levels
The log levels available in jjSwiftLog are:
Level | Description |
---|---|
Debug | For detailed debug information. |
Info | For general information. |
Warning | For warning messages. |
Error | For error messages. |
Using Formatters
To apply a formatter to your log messages, follow these steps:
- Create a formatter instance.
- Assign the formatter instance to the logger:
let formatter = MyFormatter()
logger.setFormatter(formatter)
Defining Destinations
Destinations determine where your log messages are displayed or stored. jjSwiftLog supports the following destinations:
Destination | Description |
---|---|
Console | Displays log messages in the console. |
File | Stores log messages in a file. |
Custom | Allows defining custom destinations. |
To set a destination, use the following methods:
logger.addConsoleDestination()
logger.addFileDestination(path: "/path/to/log/file.log")
logger.addCustomDestination(destination: myCustomDestination)
Performing Log Actions
jjsSwiftLog provides the following log actions:
log()
: Logs a single message with a specified log level.logMultiple()
: Logs multiple messages with the same log level.logDetails()
: Logs multiple messages with different log levels.logAsync()
: Logs a message asynchronously.flush()
: Flushes log messages to defined destinations.clear()
: Clears log messages from memory.
Custom Destinations
To create a custom destination, follow these steps:
- Create a class conforming to the
DestinationProtocol
protocol. - Implement the required functions of the protocol.
- Add the custom destination to jjSwiftLog using
logger.addCustomDestination(destination: myCustomDestination)
.
Advanced Usage
To further customize jjSwiftLog, you can:
- Create custom log levels using
LogLevel
enumeration. - Implement and assign custom formatters.
- Define custom destinations to suit specific logging requirements.
- Modify logger options and behavior.
Congratulations! You now have a solid understanding of jjSwiftLog and can start utilizing it for effective logging in your Swift projects!