Swiftpack.co -  ITzTravelInTime/SwiftLoggedPrint as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ITzTravelInTime/SwiftLoggedPrint
Swift Library for logged and better prints.
.package(url: "https://github.com/ITzTravelInTime/SwiftLoggedPrint.git", from: "3.0.1")

SwiftLoggedPrint

Swift Library for better prints and to log prints.

Usage

The source code is well documented, for some help here is some example usage:

(See also the playground included with the project)


import Foundation
import SwiftLoggedPrint

//The usage of a subclass is recommended sice it allows for a shorter name in the code and to customize the prefix
class Log: LoggedPrinter{
    override class var prefix: String{
        return "[My App]"
    }
    
    override class var debugPrefix: String{
        return "[Debug]"
    }
}

for i in 0...1{
    
Log.displayPrintTime = i == 1 //The first time the log should display without the date, the second time with the date
Log.trackPrintTime = i == 1 //The first time the log will not keep track of the time, the second time it will
    
Log.debug("This should print and be visible in the log")
Log.print("Hello this is my app!") //this will print and show up in the log

Log.allowsLogging = false

Log.debug("This should print and not be visible in the log")
Log.print("Hello this is my app!") //This will print and not show up in the log

Log.enabled = false

Log.print("This should not print and not be visible in the log")

Log.enabled = true
Log.allowsLogging = true

}

Log.readLoggedDebugLines = false

print(" ----- Here is the log so far [excluding debug lines]: \n\n\(Log.readAllLog() ?? "")")

Log.readLoggedDebugLines = true

print(" ---- Here is the log so far [with debug lines]: \n\n\(Log.readAllLog() ?? "")")

print(" ---- Here is the RAW log so far: \n\n\(Log.getCompleteLog().json(prettyPrinted: true) ?? "")")

Who should use this Library?

This library should be used by Swift apps/programs that needs better printing management compared to what Swift's Foundation library provvides and that needs some logs to provvide.

Requirements

This code should work for almost any platform/target that has the Swift Foundation library or any equivalent one that's named the same, and that provvides the same basic types and functionalities.

About the project

This code was created as part of my TINU project (https://github.com/ITzTravelInTime/TINU) and has been separated and made into it's own library to make the main project's source less complex and more focused on it's aim.

Also having this as it's own library allows for code to be updated separately and so various versions of the main TINU app will be able to be compiled all with the latest version of this library.

Credits

  • ITzTravelInTime (Pietro Caruso) - Project creator

Contacts

Copyright

Copyright (C) 2021 Pietro Caruso

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

GitHub

link
Stars: 1
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Build 3.0.1
2 weeks ago
  • Added print time tracking and printing
  • Added a playground to try the library
  • Added an option to put the prefix in front of all the printed lines of a single message
  • Now every LoggedPrinterProtocol type will support having it's own log storage struct
  • Added extensions to Date , Encodable and Decodable to provvide needed features and provvide some useful things to users of this library
  • The printerID for LoggedPrinter is now set by default to the current bundle identifier
  • Added printTime to LoggedLine
  • Renamed LoggedLine.id to LoggedLine.printerID for better understandability
  • Added a LoggedPrintStorage to let LoggedPrinterProtocol types manage their own log storage
  • Added DefaultLogMemory struct to provvide a ready-made LoggedPrinterProtocol type for usage
  • Updated the README example
  • Updated platform requirements

Tested to work on iOS, tvOS and macOS.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API