SimpleLogger is a centralised logging manager designed for Swift applications. It provides a flexible, environment-aware logging system that simplifies logging across different parts of an application. SimpleLogger supports conditional logging based on the development or production environment and incorporates privacy-aware logging practices.
- Environment-Specific Logging: Enables or disables logging based on the application's running environment — development or production.
- Privacy-Conscious: Supports privacy considerations in logging to protect sensitive data.
- Flexible Logging Levels: Includes support for multiple logging levels (info, debug, error, etc.).
- Category-Based Logging: Allows logs to be categorised for better organisation and filtering.
You can add PlatformChecker to your project via Swift Package Manager. Add the following dependency to your Package.swift
:
dependencies: [
.package(
url: "https://github.com/markbattistella/SimpleLogger.git",
from: "1.0.0"
)
]
Import SimpleLogger in the Swift file where you want to use the platform and device checks:
import SimpleLogger
Here are some examples of how you can use SimpleLogger in your project:
// Setup logger
let logger = LogManager.shared.getLogger(
environment: .production,
category: .network
)
// Use logger
logger.info("Network request completed successfully.")
Implement the LogCategoryRepresentable
to define custom log categories:
enum AppLogCategory: String, LogCategoryRepresentable {
case network, ui, database
var value: String { rawValue }
}
There is the parameter environment
in the getLogger(environment:category:)
function that allows you to filter when and if the logging should be stored.
If you set this parameter to .development
then it will only log if you run the app in #if DEBUG
, on a simulator, or in TestFlight.
Otherwise, if using .production
, the logging will occur for both environments.
Contributions are welcome! If you have suggestions or improvements, please fork the repository and submit a pull request.
PlatformChecker is released under the MIT license. See LICENSE for details.