diff --git a/APPROBATION.md b/APPROBATION.md index a4645be..4701301 100644 --- a/APPROBATION.md +++ b/APPROBATION.md @@ -1,4 +1,4 @@ -# Approbation Matrix / PerseusGeoLocationKit 1.0.0 && 1.0.1 && 1.0.2 && 1.0.2 && 1.0.3 && 1.0.4 && 1.1.0 +# Approbation Matrix / PerseusGeoLocationKit 1.0.0 && 1.0.1 && 1.0.2 && 1.0.2 && 1.0.3 && 1.0.4 && 1.1.0 && 1.1.1 > NOTE: To catch all log messages Mac Console should be started first then after a little while the logged app. diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d2a7d..d51d5dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.1.1] - [2025-11-30], PGK + +### Updated + +- CPL dependency to v1.7.0. + ## [1.1.0] - [2025-10-30], PGK ### Added diff --git a/PGKStar.swift b/PGKStar.swift index 0b890b2..8becfe1 100644 --- a/PGKStar.swift +++ b/PGKStar.swift @@ -1,6 +1,6 @@ // // PerseusGeoKitStar.swift -// Version: 1.1.0 +// Version: 1.1.1 // // Standalone PerseusGeoKit // @@ -23,7 +23,7 @@ // Copyright © 7533 - 7534 PerseusRealDeal // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/PGKSupportingStar.swift b/PGKSupportingStar.swift index 3b92665..addb304 100644 --- a/PGKSupportingStar.swift +++ b/PGKSupportingStar.swift @@ -1,6 +1,6 @@ // // PGKSupportingStar.swift -// Version: 1.1.0 +// Version: 1.1.1 // // PerseusGeoKit Support Code // @@ -10,7 +10,7 @@ // Created by Mikhail Zhigulin of Novosibirsk in 7533. // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // // Unlicensed Free Software diff --git a/Package.swift b/Package.swift index 4671314..c48e7ec 100644 --- a/Package.swift +++ b/Package.swift @@ -1,7 +1,7 @@ // swift-tools-version:5.7 /* Package.swift - Version: 1.1.0 + Version: 1.1.1 For iOS and macOS only. Use Stars to adopt for the specifics you need. diff --git a/README.md b/README.md index 80c9f95..fa99975 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ [![Actions Status](https://github.com/perseusrealdeal/PerseusGeoKit/actions/workflows/main.yml/badge.svg)](https://github.com/perseusrealdeal/PerseusGeoKit/actions/workflows/main.yml) [![Style](https://github.com/perseusrealdeal/PerseusGeoKit/actions/workflows/swiftlint.yml/badge.svg)](https://github.com/perseusrealdeal/PerseusGeoKit/actions/workflows/swiftlint.yml) -[![Version](https://img.shields.io/badge/Version-1.1.0-green.svg)](/CHANGELOG.md) +[![Version](https://img.shields.io/badge/Version-1.1.1-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) [![License](http://img.shields.io/:License-MIT-blue.svg)](/LICENSE) -> Home-made product. The location manager wrapper for Location Services API. +> This is the great home-made product in Swift for easily managed `Location Services API`. > `1:` Be awared of Location Services Status.
> `2:` Request permission for Location Services.
@@ -25,7 +25,7 @@ ## Dependencies -[![ConsolePerseusLogger](http://img.shields.io/:ConsolePerseusLogger-1.6.0-green.svg)](https://github.com/perseusrealdeal/ConsolePerseusLogger.git) +[![ConsolePerseusLogger](http://img.shields.io/:ConsolePerseusLogger-1.7.0-green.svg)](https://github.com/perseusrealdeal/ConsolePerseusLogger.git) ## Support Code @@ -69,8 +69,8 @@ * [Current location](#Current-location) * [Location updates](#Location-updates) * [Points taken into account](#Points-taken-into-account) -* [License MIT](#License-MIT) - * [Other Required License Notices](#Other-Required-License-Notices) +* [License](#License) + * [Other required license notices](#Other-required-license-notices) * [Credits](#Credits) * [Author](#Author) @@ -115,7 +115,7 @@ | Type | Name | License | | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| Star | [ConsolePerseusLogger](https://github.com/perseusrealdeal/ConsolePerseusLogger) / [1.6.0](https://github.com/perseusrealdeal/ConsolePerseusLogger/releases/tag/1.6.0) | MIT | +| Star | [ConsolePerseusLogger](https://github.com/perseusrealdeal/ConsolePerseusLogger) / [1.7.0](https://github.com/perseusrealdeal/ConsolePerseusLogger/releases/tag/1.7.0) | MIT | # Third-party software @@ -492,15 +492,17 @@ GeoAgent.register(self, #selector(locationUpdatesHandler(_:)), .locationUpdates) - Preconfigured GitHub config [.gitignore](/.gitignore) - Preconfigured GitHub CI [main.yml](/.github/workflows/main.yml) -# License MIT +# License + +`License:` MIT Copyright © 7531 - 7534 Mikhail A. Zhigulin of Novosibirsk
Copyright © 7533 - 7534 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. +- September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. -## Other Required License Notices +## Other required license notices © 2025 The SwiftLint Contributors **for** SwiftLint
© GitHub **for** GitHub Action cirruslabs/swiftlint-action@v1
@@ -514,22 +516,22 @@ Copyright © 7533 - 7534 PerseusRealDeal Balance and Control kept by - Mikhail A. Zhigulin + Mikhail Zhigulin Source Code written by - Mikhail A. Zhigulin + Mikhail Zhigulin Documentation prepared by - Mikhail A. Zhigulin + Mikhail Zhigulin Product Approbation tested by - Mikhail A. Zhigulin + Mikhail Zhigulin diff --git a/Sources/PerseusGeoKit/CPLStar.swift b/Sources/PerseusGeoKit/CPLStar.swift index 9bb6c61..26ddbb1 100644 --- a/Sources/PerseusGeoKit/CPLStar.swift +++ b/Sources/PerseusGeoKit/CPLStar.swift @@ -1,6 +1,6 @@ // // CPLStar.swift -// Version: 1.6.0 +// Version: 1.7.0 // // Standalone ConsolePerseusLogger. // @@ -27,7 +27,7 @@ // Copyright © 7531 - 7534 PerseusRealDeal // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -62,6 +62,63 @@ protocol PerseusDelegatedMessage: AnyObject { var message: String { get set } } +public struct LogMessage { + + public let text: String + public let level: PerseusLogger.Level + public let localTime: PerseusLogger.LocalTime + public let owner: PerseusLogger.PIDandTID + public let user: PerseusLogger.User + public let fileline: PerseusLogger.Directives + + public func getMessage(mode: PerseusLogger.LineMode = .singleLine) -> String { + + var tags = "" + + // Type. + + let isTyped = + (log.format == .full) ? true : log.marks && (log.format != .textonly) + + tags = isTyped ? "\(level.tag)" : tags + + // Time. + + let isTimed = + (log.format == .full) ? true : log.marks && log.time && (log.format != .textonly) + + if isTimed { + let tag = "[\(localTime.date)] [\(localTime.time)]" + tags = tags.isEmpty ? "\(tag)" : "\(tags) \(tag)" + } + + // PID and TID. + + let withOwnerId = + (log.format == .full) ? true : log.owner && (log.format != .textonly) + + if withOwnerId { + let tag = "[\(owner.pid):\(owner.tid)]" + tags = tags.isEmpty ? "\(tag)" : "\(tags) \(tag)" + } + + // Path. + + let withPath = + (log.format == .full) ? true : log.directives && (log.format != .textonly) + + let messageText = + withPath ? "\(text), file: \(fileline.fileName), line: \(fileline.line)" : "\(text)" + + switch mode { + case .singleLine: + return tags.isEmpty ? "\(messageText)" : "\(tags) \(messageText)" + case .multiLine: + return tags.isEmpty ? "\(messageText)" : "\(tags)\r\n\(messageText)" + } + } +} + public class PerseusLogger { // MARK: - Typealiases @@ -71,9 +128,7 @@ public class PerseusLogger { public typealias PIDandTID = (pid: String, tid: String) // PID and Thread ID. public typealias Directives = (fileName: String, line: UInt) // #file and #line. - public typealias MessageDelegate = ( - (String, Level, LocalTime, PIDandTID, User, Directives) -> Void - ) + public typealias MessageDelegate = ((_ instance: LogMessage) -> Void) // MARK: - Constants @@ -90,7 +145,7 @@ public class PerseusLogger { public enum Output: String, Decodable, CaseIterable { case standard // In Use: Swift.print(""). case consoleapp // In Use: Logger structure from iOS 14.0, macOS 11.0, NSLog otherwise. - case custom // In Use: customActionOnMessage?(_:_:_:_:_:_:). + case custom // In Use: customActionOnMessage?(_:). } // log.message("Notification...", .notice, .custom, .enduser) @@ -187,6 +242,11 @@ public class PerseusLogger { // message } + public enum LineMode { + case singleLine + case multiLine + } + // MARK: - Properties public static var customActionOnMessage: PerseusLogger.MessageDelegate? @@ -207,6 +267,7 @@ public class PerseusLogger { // MARK: - Message Details Visibility Flags public static var format = MessageFormat.short + public static var linemode = LineMode.singleLine // [TYPE] [DATE] [TIME] [PID:TID] message, file: #, line: # public static var marks = true // [TYPE] @@ -270,52 +331,32 @@ public class PerseusLogger { return } - var message = "" - - // Path. + // Get message details. - let withDirectives = (format == .full) ? true : directives && (format != .textonly) - let fileName = (file.description as NSString).lastPathComponent - - if withDirectives { - message = "\(text()), file: \(fileName), line: \(line)" - } else { - message = "\(text())" - } - - // PID and TID. - - let withOwnerId = (format == .full) ? true : owner && (format != .textonly) - let idTuple = getPIDandTID() - - if withOwnerId { - message = "[\(idTuple.pid):\(idTuple.tid)] \(message)" - } - - // Time. - - let isTimed = (format == .full) ? true : marks && time && (format != .textonly) - let localTime = getLocalTime() - - if isTimed { - message = "[\(localTime.date)] [\(localTime.time)] \(message)" - } - - // Type. - - let isTyped = (format == .full) ? true : marks && (format != .textonly) - message = isTyped ? "\(type.tag) \(message)" : message + let details = LogMessage( + text: text(), + level: type, + localTime: getLocalTime(), + owner: getPIDandTID(), + user: user, + fileline: (fileName: (file.description as NSString).lastPathComponent, line: line) + ) // Print. if oput == .custom { - let directives: Directives = (fileName: fileName, line: line) - customActionOnMessage?(message, type, localTime, idTuple, user, directives) + customActionOnMessage?(details) } else { - print(message, type, oput) + print(details, type, oput) } } +} + +// MARK: - Contract for CPL json config profile + +extension PerseusLogger { + public static func loadConfig(_ profile: ProfileCPL) -> Bool { if let data = profile.json.data(using: .utf8) { if let jsonConfig = decodeJsonProfile(data) { @@ -345,12 +386,16 @@ public class PerseusLogger { log.message("CPL config file doesn't exist!", .error) return false } +} + +// MARK: - Implementation - // MARK: - Implementation +extension PerseusLogger { // swiftlint:disable:next cyclomatic_complexity - private static func print(_ text: String, _ type: Level, _ output: Output) { + private static func print(_ instance: LogMessage, _ type: Level, _ output: Output) { + let text = instance.getMessage(mode: log.linemode) let message = (text: text, type: type) if output == .standard { @@ -663,6 +708,11 @@ extension PerseusLogger { } public var text: String { report } + public var linemode: LineMode = .singleLine { + didSet { + removeMessages() + } + } // MARK: - Constants @@ -684,35 +734,32 @@ extension PerseusLogger { // MARK: - Contract - // swiftlint:disable:next function_parameter_count - public func report(_ text: String, - _ type: Level, - _ localTime: LocalTime, - _ owner: PIDandTID, - _ user: User, - _ dirs: Directives) { + public func report(_ instance: LogMessage) { - let text = text.replacingOccurrences(of: "\(type.tag) ", with: "") - lastMessage = "[\(localTime.date)] [\(localTime.time)] \(type.tag)\r\n\(text)" + lastMessage = instance.getMessage(mode: self.linemode) - if user == .enduser { - delegate?.message = text + if instance.user == .enduser { + delegate?.message = instance.text } } public func clear() { - report = "" + removeMessages() } // MARK: - Realization + private func removeMessages() { + report = "" + } + private func resizeReportIfNeeded() { let lmCount = lastMessage.count let nlCount = newLine.count // Can the last message be reported? - guard lmCount != 0, lmCount < limit else { + guard lmCount != 0, lmCount <= limit else { return } @@ -724,7 +771,7 @@ extension PerseusLogger { // What length to remove? let messages = report.components(separatedBy: newLine) - let messagesCount = messages.count - 1 + let messagesCount = messages.count var lengthToRemove = 0 var itemCount = 0 @@ -732,11 +779,11 @@ extension PerseusLogger { for item in messages { itemCount += 1 - let newLineLength = messagesCount == 0 ? 0 : nlCount + let newLineLength = messagesCount == 1 ? 0 : nlCount lengthToRemove += (item.count + newLineLength) - if itemCount == messagesCount, messagesCount > 2 { + if itemCount == messagesCount, messagesCount >= 2 { lengthToRemove -= nlCount // There's no new line in the report end } @@ -760,7 +807,7 @@ extension PerseusLogger { private func appendLastMessageToReport() { - guard lastMessage.isEmpty == false, lastMessage.count < limit else { + guard lastMessage.isEmpty == false, lastMessage.count <= limit else { return }