Skip to content

Swift Logger lib. macOS 10.13+, iOS 11+, Xcode 14.2+.

License

Notifications You must be signed in to change notification settings

perseusrealdeal/ConsolePerseusLogger

Repository files navigation

ConsolePerseusLogger — Xcode 14.2+

Light-weight logger in Swift. Hereinafter CPL stands for Console Perseus Logger.

Actions Status Style Version Platforms Xcode 14.2 Swift 5.7 License

Integration Capabilities

Standalone Swift Package Manager compatible

Approbation Matrix

A3 Environment / Approbation Results / CHANGELOG for details.

In brief > Idea to use, the Why

USE LOGGER LIKE A VARIABLE ANYWHERE YOU WANT.

Screenshot 2024-10-13 at 14 00 48

import ConsolePerseusLogger

log.message("[\(type(of: self))].\(#function)")
Level Message Type Purpose
5 DEBUG Debugging only
4 INFO Helpful, but not essential
3 NOTICE Might result in a failure
2 ERROR Errors seen during the code execution
1 FAULT Faults and bugs in the code

Manual

Setting the Logger for Work

Options used by default are different and depend on DEBUG/RELEASE.

Options Default in DEBUG Default in RELEASE Description
tuned .on .off If .off no matter what level no message will be passed
output .xcodedebug .consoleapp Message output target
level .debug .notice No any messages on any level above
short true true FALSE: Message goes with file name and line number
marks true true FALSE: Message text, TRUE: [LOG] [DEBUG] Message text
logObject nil nil Mac Console Subsystem and Category values group
debugIsInfo true true Only if Simulator. TRUE: DEBUG is INFO with DEBUG text

NOTE: If logObject is nil CPL uses default values for Subsystem "Perseus" and Category "Logger" accordingly.

//
//  main.swift
//

import ConsolePerseusLogger

// MARK: - Log to Mac Console

log.logObject = ("MyApp", "MyLogger") // Subsystem and Category.

log.output = .consoleapp
log.turned = .on

log.level = .debug
log.message("The app's start point...", .info)

Getting access to the Logger of Submodule

In case if CPL used as a standalone file in submodule (package).

//
//  main.swift
//

import ConsolePerseusLogger

import class SubmoduleA.PerseusLogger
import class SubmoduleB.PerseusLogger

typealias sublogA = SubmoduleA.PerseusLogger
typealias sublogB = SubmoduleB.PerseusLogger

// MARK: - Subloggers

sublogA.turned = .off
sublogB.turned = .off

// MARK: - Logger

log.level = .debug
log.message("The app's start point...", .info)

Console on Mac and Simulator

Just a matter of fact that Console on Mac doesn't show any DEBUG message from any app running on Simulator ("Include Debug Messages" tapped).

Console Perseus Logger running on Simulator doesn't pass DEBUG message, instead it passes INFO message with text of DEBUG message, so, a passed message being INFO looks like a DEBUG and it works perfactly well.

If for some reasons Simulator must pass DEBUG like a DEBUG message there is an option exists (it's true by default if Simulator):

#if targetEnvironment(simulator)
    log.debugIsInfo = false // Use Case: Mac Console in use to redirect logs to file on disk.
#endif

Build system requirements

Third-party software

Points taken into account

License MIT

Copyright © 7531 - 7533 Mikhail A. Zhigulin of Novosibirsk
Copyright © 7531 - 7533 PerseusRealDeal

  • The year starts from the creation of the world according to a Slavic calendar.
  • September, the 1st of Slavic year. It means that "Sep 01, 2024" is the beginning of 7533.

LICENSE for details.

Credits

Balance and Control kept by Mikhail A. Zhigulin
Source Code written by Mikhail A. Zhigulin
Documentation prepared by Mikhail A. Zhigulin
Product Approbation tested by Mikhail A. Zhigulin

Author

Mikhail A. Zhigulin of Novosibirsk.