Skip to content

Commit

Permalink
Copied latest version from Planetary
Browse files Browse the repository at this point in the history
  • Loading branch information
mplorentz committed Mar 7, 2023
1 parent 5b669c2 commit 30bb72d
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 265 deletions.
124 changes: 5 additions & 119 deletions .gitignore
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
22 changes: 5 additions & 17 deletions .swiftpm/xcode/xcshareddata/xcschemes/Logger.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -20,28 +20,14 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "LoggerTests"
BuildableName = "LoggerTests"
BlueprintName = "LoggerTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
codeCoverageEnabled = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -53,7 +39,9 @@
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
skipped = "NO"
parallelizable = "YES"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "LoggerTests"
Expand Down
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -25,9 +25,12 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Logger",
dependencies: [.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack")]),
dependencies: [.product(name: "CocoaLumberjackSwift",
package: "CocoaLumberjack")],
path: "Sources"),
.testTarget(
name: "LoggerTests",
dependencies: ["Logger"]),
dependencies: ["Logger"],
path: "Tests"),
]
)
22 changes: 21 additions & 1 deletion README.md
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")
```
112 changes: 112 additions & 0 deletions Sources/Delivery/Log.swift
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)
}
}
40 changes: 40 additions & 0 deletions Sources/Delivery/Models/LogProtocol.swift
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?)
}
15 changes: 15 additions & 0 deletions Sources/Delivery/Models/Reason.swift
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
}
Loading

0 comments on commit 30bb72d

Please sign in to comment.