-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copied latest version from Planetary
- Loading branch information
Showing
18 changed files
with
321 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,7 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## User settings | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
*.xcscmblueprint | ||
*.xccheckout | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
build/ | ||
DerivedData/ | ||
*.moved-aside | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
|
||
## App packaging | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
# *.xcodeproj | ||
# | ||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
# hence it is not needed unless you have added a package configuration file to your project | ||
# .swiftpm | ||
|
||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
# | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build/ | ||
|
||
# Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. | ||
# Instead, use fastlane to re-generate the screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ | ||
|
||
# MacOS | ||
# | ||
# Taken from https://github.com/github/gitignore/blob/master/Global/macOS.gitignore | ||
|
||
## General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
## Icon must end with two \r | ||
Icon | ||
|
||
## Thumbnails | ||
._* | ||
|
||
## Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
## Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
# Logger | ||
|
||
A description of this package. | ||
---- | ||
|
||
`Logger` is a simple logging utility to output messages with the following features: | ||
|
||
- Print messages to different levels such as info and error | ||
- Auto-rolling of log files | ||
|
||
## Usage | ||
|
||
Import the `Logger` module and use any functions declared in the `Log` class. Just some examples: | ||
|
||
```swift | ||
import Logger | ||
|
||
Log.optional(error) | ||
Log.info("This is important, display it everytime") | ||
Log.debug("Display this just when debugging") | ||
Log.unexpected(.apiError) | ||
Log.fatal(.missingValue) | ||
Log.error("Something bad happened") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// Log.swift | ||
// | ||
// | ||
// Created by Martin Dutra on 10/2/22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// The Log class provides a simple logging utility that you can use to output messages | ||
/// | ||
/// The levels are as follows: | ||
/// - FATAL: An unhandleable error that results in a program crash. | ||
/// - ERROR or UNEXPECTED: A handleable error condition. | ||
/// - INFO: Generic (useful) information about system operation. | ||
/// - DEBUG: Low-level information for developers. | ||
public class Log: LogProtocol { | ||
|
||
public static let shared = Log() | ||
|
||
var service: LoggerService | ||
|
||
init(service: LoggerService = LoggerServiceAdapter(fileLoggerService: CocoaLumberjackService())) { | ||
self.service = service | ||
} | ||
|
||
public var fileUrls: [URL] { | ||
service.fileUrls | ||
} | ||
|
||
@discardableResult | ||
public func optional(_ error: Error?, _ detail: String? = nil) -> Bool { | ||
service.optional(error, detail) | ||
} | ||
|
||
public func info(_ string: String) { | ||
service.info(string) | ||
} | ||
|
||
public func debug(_ string: String) { | ||
service.debug(string) | ||
} | ||
|
||
public func error(_ string: String) { | ||
service.unexpected(string, nil) | ||
} | ||
|
||
public func unexpected(_ reason: Reason, _ detail: String?) { | ||
service.unexpected(reason.rawValue, detail) | ||
} | ||
|
||
public func fatal(_ reason: Reason, _ detail: String?) { | ||
service.fatal(reason.rawValue, detail) | ||
} | ||
} | ||
|
||
public extension Log { | ||
|
||
/// URLs in the device's filesystem that contain what was logged in this and previous sessions | ||
static var fileUrls: [URL] { | ||
shared.fileUrls | ||
} | ||
|
||
/// Log a ERROR message | ||
/// - Returns: True if an error could be unwrapped | ||
/// | ||
/// Convenience function that unwraps the error (if exists) and logs its description | ||
@discardableResult | ||
static func optional(_ error: Error?, _ detail: String? = nil) -> Bool { | ||
shared.optional(error, detail) | ||
} | ||
|
||
/// Log a INFO message | ||
static func info(_ string: String) { | ||
shared.info(string) | ||
} | ||
|
||
/// Log a DEBUG message | ||
static func debug(_ string: String) { | ||
shared.debug(string) | ||
} | ||
|
||
/// Log a ERROR message | ||
/// | ||
/// Convencience function that categorize common errors that the app can handle | ||
static func unexpected(_ reason: Reason, _ detail: String?) { | ||
shared.unexpected(reason, detail) | ||
} | ||
|
||
/// Log a FATAL message | ||
/// | ||
/// Convencience function that categorize common errors that the app cannot handle | ||
static func fatal(_ reason: Reason, _ detail: String?) { | ||
shared.fatal(reason, detail) | ||
} | ||
|
||
/// Log a ERROR message | ||
/// | ||
/// Convenience function that unwraps an error and a response from a network call | ||
static func optional(_ error: Error?, from response: URLResponse?) { | ||
guard let error = error else { return } | ||
guard let response = response else { return } | ||
let path = response.url?.path ?? "unknown path" | ||
let detail = "\(path) \(error)" | ||
shared.unexpected(.apiError, detail) | ||
} | ||
|
||
/// Log a ERROR message | ||
static func error(_ message: String) { | ||
shared.error(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// LogProtocol.swift | ||
// | ||
// | ||
// Created by Martin Dutra on 26/4/22. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol LogProtocol { | ||
|
||
/// URLs in the device's filesystem that contain what was logged in this and previous sessions | ||
var fileUrls: [URL] { get } | ||
|
||
/// Log a ERROR message | ||
/// - Returns: True if an error could be unwrapped | ||
/// | ||
/// Convenience function that unwraps the error (if exists) and logs its description | ||
@discardableResult | ||
func optional(_ error: Error?, _ detail: String?) -> Bool | ||
|
||
/// Log a INFO message | ||
func info(_ string: String) | ||
|
||
/// Log a DEBUG message | ||
func debug(_ string: String) | ||
|
||
/// Log a ERROR message | ||
func error(_ string: String) | ||
|
||
/// Log a ERROR message | ||
/// | ||
/// Convencience function that categorize common errors that the app can handle | ||
func unexpected(_ reason: Reason, _ detail: String?) | ||
|
||
/// Log a FATAL message | ||
/// | ||
/// Convencience function that categorize common errors that the app cannot handle | ||
func fatal(_ reason: Reason, _ detail: String?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Reason.swift | ||
// | ||
// | ||
// Created by Martin Dutra on 26/4/22. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum Reason: String { | ||
case apiError | ||
case botError | ||
case missingValue | ||
case incorrectValue | ||
} |
Oops, something went wrong.