For the Android kotlin version, see this page
BadgeLog is an iOS Swift library that helps you manage logs within your application:
- Centralize all log management logic
- Print console logs in a nice way
- Ability to save logs to file and export them
BadgeLog is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BadgeLog'
Setting up the library is very quick and easy. You need to invoke the following method:
Logger.shared.setup()
I recommend to put it within the initialization of the App or in any case as soon as possible
@main
struct BadgeLog_ExampleApp: App {
init() {
Logger.shared.setup()
}
var body: some Scene {
WindowGroup {
NavigationView{
ContentView()
}
}
}
}
The library is ready to log in! to log in, simply call up:
Logger.shared.verbose("I'm a verbose log!")
Logger.shared.debug("I'm a debug log!")
Logger.shared.info("I'm a info log!")
Logger.shared.warning("I'm a warning log!")
Logger.shared.error("I'm an error log!")
Logger.shared.error("I'm an error log!", error: NSError(domain: "", code: 999, userInfo: [NSLocalizedDescriptionKey: "Fake Exception"]))
The detailed documentation is still in progress.
For each LogDestination, you can set the format in which they will display the logs. The format is a string that can contain custom characters and preset values. Insert your own custom character inside apex. The default format is
"T '-' L '-' '['c'.'m':'l']' M e"
2022-02-08T13:00:00Z - VERBOSE - [ContentView.body:18] I'm a log!
The default format for ConsoleDestination is:
"C L '['c'.'m':'l']' M e"
📣 VERBOSE [ContentView.body:18] I'm a log!
Preset Char (case sensitive) are:
M
-> the message of the log.m
-> the function name where the log has been requestedL
-> theLogLevel
type (VERBOSE, DEBUG, INFO....)l
-> the line number of the file where the log has been requestedf
-> the file name, fullpath, where the log has been requestedC
-> the color(emoji) assigned to theLogLevel
typec
-> the file name, without path, where the log has been requestede
-> the NSError of the log, if present.T
-> the date of the log, formatted with vardateFormat
of theLogDestination
.- " " -> empty space.
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Compiled with swift 5
- Deployment target 15.0
BadgeLog is available under the MIT license. See the LICENSE file for more info.