Giter VIP home page Giter VIP logo

logbook's Introduction

Logbook

SPM Compatible Carthage Compatible

Logbook is a lightweight logging framework for iOS and iPadOS

Features

  • Levels: Debug -> Error
  • Categories
  • Extendable Log Handler

Basic usage

First setup Logbook by adding a LogSink

Logbook.add(sink: ConsoleLogSink())

Log some data

Logbook.debug("Hello Logbook")
Logbook.error("Hello Error")

Advanced usage

Create a global variable for faster access.

let log = Logbook.self
log.debug("Hello Logbook")

LogSinks

Filter logs by level.

ConsoleLogSink(level: .min(.warning))
ConsoleLogSink(level: .fix(.info))

Filter logs by category:

ConsoleLogSink(level: .min(.debug), categories: .include([.networking]))

or

ConsoleLogSink(level: .min(.debug), categories: .exclude([.networking]))

Add multiple sinks for different usecases:

// Log all with min level warning
Logbook.add(sink: ConsoleLogSink(level: .min(.warning)))

// Log only level error with category .networking
Logbook.add(sink: ConsoleLogSink(level: .fix(.error), categories: .include([.networking])))

Formatting

Add custom dateFormatter to sink

let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .none
dateFormatter.timeStyle = .short

let console = ConsoleLogSink(level: .min(.debug), categories: .exclude([.networking]))
console.dateFormatter = dateFormatter

Add logging format to ConsoleLogSink

console.format = "\(LogPlaceholder.category) \(LogPlaceholder.date): \(LogPlaceholder.messages)"

Custom LogSink

Create your custom sink by confirming LogSink protocol.

LogCategory

Extend LogCategory to create custom categories.

extension LogCategory {
    
    static let startup = LogCategory("startup", prefix: "๐Ÿšฆ")
    static let bluetooth = LogCategory("bluetooth", prefix: "๐Ÿ–ฒ")
    
}
log.debug("hello", category: .startup)

Carthage

Add the following line to your Cartfile.

github "allaboutapps/Logbook"

Then run carthage update.

Swift Package Manager

Use Xcode 11+: Go to Project > Swift Packages > + and enter https://github.com/allaboutapps/Logbook

Or update your Package.swift file manually:

dependencies: [
.package(url: "[email protected]:allaboutapps/Logbook.git", from: "1.1"),
    ....
],
targets: [
    .target(name: "YourApp", dependencies: ["Logbook"]),
]

Requirements

  • Swift 5+

Contributing

  • Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
  • Fork it
  • Create new branch to make your changes
  • Commit all your changes to your branch
  • Submit a pull request

logbook's People

Contributors

draskovits avatar mbuchetics avatar swieland avatar wieweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logbook's Issues

Only evaluate expressions when there is a sink for the log message

Creating log messages can be expansive (e.g. network response body mapping to string).
Currently the expressions for messages (on the caller sites) are already generated when calling the log message.

When wrapping the expression in a closure the closure can only be evaluated if there is a sink even consuming the the message.

with @autoclosure this doesn't change the way of interacting with logbook

CSV File Sink

It would be great to have a built-in file sink which saves to a CSV file, e.g. using https://github.com/dehesa/CodableCSV (needs to be an imperative writer). This would make it easy to inspect & analyze logs in tools such as Excel (group by category, etc.).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.