Skip to content

Commit 33f2817

Browse files
committed
First commit
0 parents  commit 33f2817

File tree

11 files changed

+1087
-0
lines changed

11 files changed

+1087
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
9+
.swiftpm/xcode/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Tech Artists Agency
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.resolved

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2025 Tech Artists Agency
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
// swift-tools-version: 6.0
26+
// The swift-tools-version declares the minimum version of Swift required to build this package.
27+
28+
import PackageDescription
29+
30+
let package = Package(
31+
name: "SwiftLogFileLogHandler",
32+
platforms: [ .iOS(.v14), .macOS(.v10_13)],
33+
products: [
34+
// Products define the executables and libraries a package produces, making them visible to other packages.
35+
.library(
36+
name: "SwiftLogFileLogHandler",
37+
targets: ["SwiftLogFileLogHandler"]),
38+
],
39+
dependencies: [
40+
.package(
41+
url: "https://github.com/apple/swift-log.git",
42+
from: "1.6.1"
43+
)
44+
],
45+
targets: [
46+
.target(
47+
name: "SwiftLogFileLogHandler",
48+
dependencies: [
49+
.product(name: "Logging", package: "swift-log")
50+
]
51+
),
52+
.testTarget(
53+
name: "SwiftLogFileLogHandlerTests",
54+
dependencies: ["SwiftLogFileLogHandler"]
55+
),
56+
]
57+
)

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# SwiftLogFileLogHandler
2+
3+
**SwiftLogFileLogHandler** is a file-based logging backend for Apple’s [swift-log](https://github.com/apple/swift-log). It provides automatic log file rotation and structured metadata handling.
4+
5+
---
6+
7+
## Features
8+
9+
- **File-based Logging**: Persist logs to files for later analysis.
10+
- **Automatic Log Rotation**: Ensures that log files are managed efficiently.
11+
- **Metadata Support**: Includes structured metadata with each log entry.
12+
13+
---
14+
15+
## Installation
16+
17+
### Swift Package Manager
18+
19+
To include **SwiftLogFileLogHandler** in your project, add it to your `Package.swift` file:
20+
21+
```swift
22+
let package = Package(
23+
name: "YourProject",
24+
platforms: [
25+
.iOS(.v14),
26+
.macOS(.v10_13)
27+
],
28+
dependencies: [
29+
.package(
30+
url: "git@github.com:TechArtists/ios-swift-log-file-log-handler.git",
31+
from: "1.0.0"
32+
)
33+
],
34+
targets: [
35+
.target(
36+
name: "YourTarget",
37+
dependencies: [
38+
.product(name: "SwiftLogFileLogHandler", package: "ios-swift-log-file-log-handler")
39+
]
40+
)
41+
]
42+
)
43+
```
44+
45+
Alternatively, to add the package using Xcode:
46+
47+
1. Navigate to File > Add Packages.
48+
2. Enter the repository URL: `git@github.com:YourRepo/SwiftLogFileLogHandler.git`.
49+
3. Add the package to your target.
50+
51+
## Usage
52+
53+
### Basic Logging Example
54+
55+
```swift
56+
import Logging
57+
import SwiftLogFileLogHandler
58+
59+
let logger = Logger(label: "com.yourapp.main") { label in
60+
SwiftLogFileLogHandler(label: label)
61+
}
62+
63+
logger.info("Application started successfully.")
64+
logger.warning("Low disk space detected.")
65+
```
66+
67+
### Accessing Log Files
68+
69+
To retrieve the current log file or combined stashed logs:
70+
71+
```swift
72+
if let logFileURL = logger.getCurrentLogFileURL() {
73+
print("Current log file located at: \(logFileURL)")
74+
}
75+
76+
if let combinedLogsURL = logger.getCombinedStashedLogFilesURL() {
77+
print("Combined log file at: \(combinedLogsURL)")
78+
}
79+
80+
let stashedCount = logger.getCurrentStashedCount()
81+
print("Number of stashed log files: \(stashedCount)")
82+
```
83+
84+
## License
85+
86+
This project is licensed under the MIT License. See the LICENSE file for more details.

0 commit comments

Comments
 (0)