Skip to content

Commit

Permalink
v1.0.0 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
perseusrealdeal authored Oct 13, 2024
1 parent 34c6872 commit 7d4b100
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 45 deletions.
55 changes: 35 additions & 20 deletions APPROBATION.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
# Approbation Matrix / ConsolePerseusLogger v0.1.0
# Approbation Matrix / ConsolePerseusLogger v1.0.0

> Only GitHub CI build & tests status used to approve.
Approbated feature: Logging to Console on Mac.

## macOS

| macOS | Version | Result | Details |
| ----------- | -------- | :-----: | ------- |
| High Sierra | 10.13.6 | ?? | - |
| Mojave | 10.14.6 | ?? | - |
| Catalina | 10.15.7 | ?? | - |
| Big Sur | 11.7.10 | ?? | - |
| Monterey | 12.7.6 | ?? | - |
| Ventura | 13.6.9 | ?? | - |
| Sonoma | 14.6.1 | ?? | - |
| Sequoia | 15.nn.nn | ?? | - |
| High Sierra | 10.13.6 | ok | - |
| Mojave | 10.14.6 | ok | - |
| Catalina | 10.15.7 | ok | - |
| Big Sur | 11.7.10 | ok? | First start displayed not all messages, but all next shows all messages |
| Monterey | 12.7.6 | ok | - |
| Ventura | 13.6.9 | ok? | First start displayed not all messages, but all next shows all messages |
| Sonoma | 14.6.1 | ok | - |
| Sequoia | 15.0 | ok | - |

## iOS

| iOS | Simulator | Device | Result | Details |
| ------ | --------- | --------------------- | :-----: | ------- |
| iOS 11 | | | ?? | - |
| iOS 12 | - | iPad Air / iOS 12.5.7 | ?? | - |
| iOS 13 | | | ?? | - |
| iOS 14 | | | ?? | - |
| iOS 15 | | | ?? | - |
| iOS 16 | | | ?? | - |
| iOS 17 | | | ?? | - |
| iOS 18 | | | ?? | - |
> macOS Monterey 12.7.6 / Xcode 14.2
<table>
<tr>
<th>iOS</th>
<th>Simulator</th>
<th>Device</th>
<th>Result</th>
<th>Details</th>
</tr>
<tr>
<td nowrap>iOS 12.5.7</td>
<td>-</td>
<td nowrap>iPad Air / iOS 12.5.7</td>
<td>ok?</td>
<td>First start displayed not all messages, but all next shows all messages</td>
</tr>
<tr>
<td nowrap>iOS 16.2</td>
<td nowrap>iPhone SE (3rd gen)</td>
<td>-</td>
<td>ok??</td>
<td>Shows INFO messages not DEBUG</td>
</tr>
</table>
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Dates in this file meets Gregorian calendar. Date in format YYYY-MM-DD.

## [1.0.0] - [2024-10-13], Console Output

### Added

- Output to Console on Mac.

## [0.1.0] - [2024-10-06], PerseusLogger

### Added
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// swift-tools-version:5.7

/* Package.swift
Version: 0.1.0
Version: 1.0.0

Created by Mikhail Zhigulin in 7533.

Expand Down
117 changes: 107 additions & 10 deletions PerseusLoggerStar.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//
// PerseusLoggerStar.swift
// Version: 0.1.0
// Version: 1.0.0
//
// PLATFORMS: macOS 10.12+ | iOS 10.0+
//
// SWIFT: 5.7 / Xcode 14.2+
//
// DESC: USE LOGGER LIKE A VARIABLE ANYWHERE YOU WANT.
//
// Created by Mikhail Zhigulin in 7531.
//
Expand Down Expand Up @@ -38,47 +44,95 @@
//

import Foundation
import os

// swiftlint:disable type_name
public typealias log = PerseusLogger
// swiftlint:enable type_name

public typealias ConsoleObject = (subsystem: String, category: String)

public class PerseusLogger {

public static let SUBSYSTEM = "Perseus"
public static let CATEGORY = "Logger"

public enum Status {
case on
case off
}

public enum Output {
case xcodedebug
case consoleapp
// case outputfile
}

public enum Level: Int, CustomStringConvertible {

public var description: String {
switch self {
case .info:
return "INFO"
case .debug:
return "DEBUG"
case .info:
return "INFO"
case .notice:
return "NOTICE"
case .error:
return "ERROR"
case .fault:
return "FAULT"
}
}

case info = 3
case debug = 2 // Default.
case error = 1
case debug = 5
case info = 4
case notice = 3 // Default.
case error = 2
case fault = 1
}

#if DEBUG
public static var turned = Status.on
public static var output = Output.xcodedebug
#else
public static var turned = Status.off
public static var output = Output.consoleapp
#endif

public static var level = Level.debug
public static var level = Level.notice
public static var short = true
public static var marks = true

public static var logObject: ConsoleObject? { // Custom Log Object for Console on Mac.
didSet {

guard let obj = logObject else {

if #available(iOS 14.0, macOS 11.0, *) {
consoleLogger = nil
}

consoleOSLog = nil

return
}

if #available(iOS 14.0, macOS 11.0, *) {
consoleLogger = Logger(subsystem: obj.subsystem, category: obj.category)
} else {
consoleOSLog = OSLog(subsystem: obj.subsystem, category: obj.category)
}
}
}

@available(iOS 14.0, macOS 11.0, *)
private(set) static var consoleLogger: Logger?
private(set) static var consoleOSLog: OSLog?

private(set) static var message = "" // Last one.

// swiftlint:disable:next cyclomatic_complexity
public static func message(_ text: @autoclosure () -> String,
_ type: Level = .debug,
_ file: StaticString = #file,
Expand All @@ -87,12 +141,55 @@ public class PerseusLogger {
guard turned == .on, type.rawValue <= level.rawValue else { return }

if short {
message = "\(type): \(text())"
message = "\(text())"
} else {
let fileName = (file.description as NSString).lastPathComponent
message = "\(type): \(text()), file: \(fileName), line: \(line)"
message = "\(text()), file: \(fileName), line: \(line)"

}

print(message) // DispatchQueue.main.async { print(message) }
message = marks ? "[LOG] [\(type)] \(message)" : message

if output == .xcodedebug {

print(message) // DispatchQueue.main.async { print(message) }

} else if output == .consoleapp {

if #available(iOS 14.0, macOS 11.0, *) {

let logger = consoleLogger ?? Logger(subsystem: SUBSYSTEM, category: CATEGORY)

switch type {
case .debug:
logger.debug("\(message, privacy: .public)")
case .info:
logger.info("\(message, privacy: .public)")
case .notice:
logger.notice("\(message, privacy: .public)")
case .error:
logger.error("\(message, privacy: .public)")
case .fault:
logger.fault("\(message, privacy: .public)")
}

return
}

let consoleLog = consoleOSLog ?? OSLog(subsystem: SUBSYSTEM, category: CATEGORY)

switch type {
case .debug:
os_log("%{public}@", log: consoleLog, type: .debug, message)
case .info:
os_log("%{public}@", log: consoleLog, type: .info, message)
case .notice:
os_log("%{public}@", log: consoleLog, type: .default, message)
case .error:
os_log("%{public}@", log: consoleLog, type: .error, message)
case .fault:
os_log("%{public}@", log: consoleLog, type: .fault, message)
}
}
}
}
83 changes: 81 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Actions Status](https://github.com/perseusrealdeal/ConsolePerseusLogger/actions/workflows/main.yml/badge.svg)](https://github.com/perseusrealdeal/ConsolePerseusLogger/actions/workflows/main.yml)
[![Style](https://github.com/perseusrealdeal/ConsolePerseusLogger/actions/workflows/swiftlint.yml/badge.svg)](https://github.com/perseusrealdeal/ConsolePerseusLogger/actions/workflows/swiftlint.yml)
[![Version](https://img.shields.io/badge/Version-0.1.0-green.svg)](/CHANGELOG.md)
[![Version](https://img.shields.io/badge/Version-1.0.0-green.svg)](/CHANGELOG.md)
[![Platforms](https://img.shields.io/badge/Platforms-macOS%2010.13+_|_iOS%2011.0+-orange.svg)](https://en.wikipedia.org/wiki/List_of_Apple_products)
[![Xcode 14.2](https://img.shields.io/badge/Xcode-14.2+-red.svg)](https://en.wikipedia.org/wiki/Xcode)
[![Swift 5.7](https://img.shields.io/badge/Swift-5.7-red.svg)](https://www.swift.org)
Expand All @@ -19,6 +19,8 @@

> USE LOGGER LIKE A VARIABLE ANYWHERE YOU WANT.<br/>
![Screenshot 2024-10-13 at 14 00 48](https://github.com/user-attachments/assets/98b8eb7d-06cc-4c3a-ab7a-4997a844bc74)

```ruby

import ConsolePerseusLogger
Expand All @@ -27,11 +29,85 @@ log.message("[\(type(of: self))].\(#function)")

```

| Types | Message default | Level default | Purpose |
| :------ | :-------------: | :-----------: | :------------------------------------ |
| DEBUG | Default | | Debugging only |
| INFO | | | Helpful, but not essential |
| NOTICE | | Default | Might result in a failure |
| ERROR | | | Errors seen during the code execution |
| FAULT | | | Faults and bugs in the code |

# Manual
## Setting the Logger for Work

> Options used by default are different and depends on DEBUG/RELEASE if do not set explicitly.
| 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 | .notice | .notice | No messages on any level above |
| short | true | true | If false a message goes with file name and line number |
| marks | true | true | [LOG] [DEBUG] Message text |

```ruby

//
// main.swift
//

import ConsolePerseusLogger

// MARK: - Logger

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

```

### Subsystem and Category Logging

> By default values for Subsystem and Category are "Perseus" and "Logger".
```ruby

log.logObject = ("MyApp", "MyLogger")

```

### Getting access to the Logger of Submodule

```ruby

//
// 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)

```

## Approbation Matrix

> [A3 Environment](https://docs.google.com/document/d/1K2jOeIknKRRpTEEIPKhxO2H_1eBTof5uTXxyOm5g6nQ/edit?usp=sharing) / [Approbation Results](/APPROBATION.md) / [CHANGELOG](/CHANGELOG.md) for details.
# Build system requirements
## Build system requirements

- [macOS Monterey 12.7.6+](https://apps.apple.com/by/app/macos-monterey/id1576738294) / [Xcode 14.2+](https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_14.2/Xcode_14.2.xip)

Expand Down Expand Up @@ -84,6 +160,9 @@ Copyright © 7531 - 7533 PerseusRealDeal
</tr>
</table>

- Language support: [Reverso](https://www.reverso.net/)
- Git client: [SmartGit](https://syntevo.com/)

# Author

> Mikhail A. Zhigulin of Novosibirsk.
Loading

0 comments on commit 7d4b100

Please sign in to comment.