Skip to content

A light lib that helps and centralize logs in your application.

License

Notifications You must be signed in to change notification settings

Badge87/BadgeLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BadgeLog

CI Status Version License Platform

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

Installation

BadgeLog is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BadgeLog'

Configure

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.

Log Format

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 requested
  • L -> the LogLevel type (VERBOSE, DEBUG, INFO....)
  • l -> the line number of the file where the log has been requested
  • f -> the file name, fullpath, where the log has been requested
  • C -> the color(emoji) assigned to the LogLevel type
  • c -> the file name, without path, where the log has been requested
  • e -> the NSError of the log, if present.
  • T -> the date of the log, formatted with var dateFormat of the LogDestination.
  • " " -> empty space.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Compiled with swift 5
  • Deployment target 15.0

License

BadgeLog is available under the MIT license. See the LICENSE file for more info.

About

A light lib that helps and centralize logs in your application.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published