Git Product home page Git Product logo

logr's Introduction

Logr

build unit test platforms codecov code size documentation

Simple logging library for iOS written in Swift

Features

  • Inferred log message tags
  • Swift Package Manager/Carthage/CocoaPods integration
  • Highly extensible
  • Logging to multiple targets/destination at the same time
  • Console logging out of the box via ConsoleTarget
  • File logging out of the box via FileTarget
  • Pure Swift 5
  • Optional file header for each file
  • Automatic file archive based on size or time span

Integration

Swift Package Manager

Once Swift package set up, add the following to your Package.swift:

dependencies: [
  .package(url: "https://github.com/nakkht/logr.git", exact: "0.11.0")
]

Usage

In your AppDelegate.swift file add:

import Logr

At the beginning of func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool configure logr service with wanted targets:

LogrService.init(with: Config(ConsoleTarget(), FileTarget()))

For more serious configuration in production, it is recommended to ommit ConsoleTarget. For example:

#if DEBUG
static let targets: [Target] = [ConsoleTarget(), FileTarget()]
#else
static let targets: [Target] = [FileTarget()]
#endif

static let config = Config(targets: targets)

LogrService.init(with: config)

The set targets will be used across the whole application.

To log messages, simply create Logr instance in class initializer and start logging. For example:

import Logr

class ViewController: UIViewController {

    private let logr = Logr()

    func logDebug() {
        logr.debug("debug message to be logged")
    }
}

Demo

Demo project can be access by opening Demo.workspace in Demo sub-folder.

Documentation

Author

Licence

This repository is under the Apache v2.0 license. Find it here.

Copyright 2021 Paulius Gudonis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

logr's People

Contributors

nakkht avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

logr's Issues

Log level support

Introduce log levels, including configuration options:

  • min level
  • max level
  • specific levels

Introduction of FileTarget

FileTarget for writing logs to a file.
Some of the configurations to consider:

  • File name
  • File rotation (based on day/file size)
  • File rotation suffixes (increments of one: 1, 2, 3, 4)
  • How many files to archive (keep last n files)

Carthage support

Motivation: In conjunction to CocoaPods and SPM, Carthage support should be added if plausible.

Dispatch queue for file target not configurable

FileTarget has a dispatch queue which is not configurable.
FileTargetConfig should allow setting dispatch queue explicitly. If not provided, it should default to the one provided by the library.

Add unit test

Unit tests for:

  • ConsoleTarget class

  • Logr class

  • LogrService class

  • Config class

Expose struct initialisers as public

Motivation: default initializer for struct is internal, which means it is inaccessible from outside library.
Initializer has to be reverted back to public.

Add more documentation

Further documentation on how to use the library:

  • Reference to the demo project
  • Manual integration
  • Cocoa pods intgration

Enable force archive action

Force archive action should give opportunity for the client to archive current log file regardless of the specified conditions in the configuration file.

Message introduction

Motivation: To enable easier extensibility, aggregates LogLevel, message and meta info into message struct.

Add logging style options

Available logging style options for targets:

  • Verbose (Full information is used in logging target - file/function/line/level title/message)
  • Minimal (Minimal information is used in logging target - level title/message)

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.