-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0653d1a
commit ed93533
Showing
36 changed files
with
1,219 additions
and
54 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
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
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,103 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1500" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Log" | ||
BuildableName = "Log" | ||
BlueprintName = "Log" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "LogTests" | ||
BuildableName = "LogTests" | ||
BlueprintName = "LogTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
codeCoverageEnabled = "YES" | ||
onlyGenerateCoverageForSpecifiedTargets = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
<CodeCoverageTargets> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Log" | ||
BuildableName = "Log" | ||
BlueprintName = "Log" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</CodeCoverageTargets> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "LogTests" | ||
BuildableName = "LogTests" | ||
BlueprintName = "LogTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Log" | ||
BuildableName = "Log" | ||
BlueprintName = "Log" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
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,2 +1,12 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
All notable changes to this project will be documented in this file. | ||
|
||
#### 1.x Releases | ||
- `1.0.x` Releases - [1.0.0](#100) | ||
|
||
## [1.0.0](https://github.com/space-code/log/releases/tag/1.0.0) | ||
Released on 2023-10-18. | ||
|
||
#### Added | ||
- Initial release of log. | ||
- Added by [Nikita Vasilev](https://github.com/nik3212). |
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,31 +1,23 @@ | ||
// swift-tools-version: 5.7 | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Log", | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "Log", | ||
targets: ["Log"] | ||
), | ||
platforms: [ | ||
.macOS(.v10_15), | ||
.iOS(.v13), | ||
.watchOS(.v7), | ||
.tvOS(.v13), | ||
.visionOS(.v1), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
products: [ | ||
.library(name: "Log", targets: ["Log"]), | ||
], | ||
dependencies: [], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "Log", | ||
dependencies: [] | ||
), | ||
.testTarget( | ||
name: "LogTests", | ||
dependencies: ["Log"] | ||
), | ||
.target(name: "Log", dependencies: []), | ||
.testTarget(name: "LogTests", dependencies: ["Log"]), | ||
] | ||
) |
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,24 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
// swiftlint:disable all | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Log", | ||
platforms: [ | ||
.macOS(.v10_15), | ||
.iOS(.v13), | ||
.watchOS(.v7), | ||
.tvOS(.v13), | ||
], | ||
products: [ | ||
.library(name: "Log", targets: ["Log"]), | ||
], | ||
dependencies: [], | ||
targets: [ | ||
.target(name: "Log", dependencies: []), | ||
.testTarget(name: "LogTests", dependencies: ["Log"]), | ||
] | ||
) | ||
// swiftlint:enable all |
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,5 @@ | ||
![Log: A lightweight logging framework written in Swift](https://raw.githubusercontent.com/space-code/log/dev/Resources/log.png) | ||
|
||
<h1 align="center" style="margin-top: 0px;">log</h1> | ||
|
||
<p align="center"> | ||
|
@@ -8,7 +10,7 @@ | |
</p> | ||
|
||
## Description | ||
`Log` description. | ||
`Log` is a lightweight logging framework written in Swift. | ||
|
||
- [Usage](#usage) | ||
- [Requirements](#requirements) | ||
|
@@ -20,7 +22,61 @@ | |
|
||
## Usage | ||
|
||
### Create a logger instance | ||
|
||
First, you need to create an instance of `IPrinter` that prints messages to a specific output, such as XCode's console or the `Console` app. | ||
The `log` package provides predefined printers for printing messages in the XCode console (`ConsolePrinter`) and the system console (`OSPrinter`). You can also create your own printer. To do this, your object must conform to `IPrinterStrategy` and implement the necessary methods. | ||
|
||
```swift | ||
import Log | ||
|
||
let osPrinter = OSPrinter() | ||
let consolePrinter = ConsolePrinter() | ||
``` | ||
|
||
Second, create a `Logger` instance and pass these printers as initialization parameters while defining a log level. The log level determines the level of log messages to print. If the log level is set to a specific level, all messages with different log levels will be ignored. To print all messages, use `.all`. | ||
|
||
```swift | ||
let log = Logger( | ||
printers: [osPrinter, consolePrinter], | ||
logLevel: .all | ||
) | ||
log.error(message: "test message") | ||
``` | ||
|
||
### Formatting a message | ||
|
||
Each instance of `IPrinter` has an array of formatters that are responsible for formatting input messages. The `log` package provides predefined prefix and timestamp formatters. To use these, you need to pass them to an initializer of a printer. | ||
|
||
```swift | ||
let osPrinter = OSPrinter(formatters: [PrefixFormatter(name: "your prefix here")]) | ||
... | ||
log.fault(message: "message") // "🚨🚨🚨 [your prefix here] => message" | ||
``` | ||
|
||
Here is a list of predefined formatters: | ||
|
||
| **Formatters** | **Description** | | ||
|----------------------------|-------------------------------------------------------------------------------------| | ||
| **PrefixLogFormatter** | Add a specified prefix to a printed message | | ||
| **TimestampLogFormatter** | Add a timestamp before a printed message based on a date format | | ||
|
||
### Custom formatters | ||
|
||
If you want to create a custom message formatter, your object must conform to the `ILogFormatter` protocol and implement the necessary methods. | ||
|
||
```swift | ||
struct MyCustomMessageFormatter: ILogFormatter { | ||
func format(message: String, with logLevel: LogLevel) -> String { | ||
// your implementation here | ||
} | ||
} | ||
``` | ||
|
||
## Requirements | ||
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ / visionOS 1.0+ | ||
- Xcode 14.0 | ||
- Swift 5.7 | ||
|
||
## Installation | ||
### Swift Package Manager | ||
|
@@ -53,4 +109,4 @@ Please feel free to help out with this project! If you see something that could | |
Nikita Vasilev, [email protected] | ||
|
||
## License | ||
log is available under the MIT license. See the LICENSE file for more info. | ||
log is available under the MIT license. See the LICENSE file for more info. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
Sources/Log/Classes/Core/Formatters/Interfaces/ILogFormatter.swift
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,16 @@ | ||
// | ||
// log | ||
// Copyright © 2023 Space Code. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Specifies the format to be used in the log message | ||
public protocol ILogFormatter { | ||
/// Concatenates the specified attributes and generates the final log message | ||
/// | ||
/// - Parameters: | ||
/// - message: A `String` value that contains the message. | ||
/// - logLevel: A `LogLevel` value that contains the logging level. | ||
func format(message: String, with logLevel: LogLevel) -> String | ||
} |
Oops, something went wrong.