You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -21,7 +21,7 @@ The easiest way to get started is by installing via Xcode. Just add Lumberjack a
21
21
22
22
If you're adding Lumberjack as a dependency of your own Swift package, just add a package entry to your dependencies.
23
23
24
-
```
24
+
```swift
25
25
.package(
26
26
name: "Lumberjack",
27
27
url: "https://github.com/mitchtreece/Lumberjack",
@@ -34,27 +34,283 @@ If you're adding Lumberjack as a dependency of your own Swift package, just add
34
34
Lumberjack is a lightweight Swift logging library built to help cut (🪓) down on development and (more importantly) debugging time.
35
35
Designed with customization & extensibility, Lumberjack can easily be integrated into any project / workflow.
36
36
37
-
### Get Started
37
+
### Getting Started
38
+
39
+
The easiest way to get started with Lumberjack, is by using the default logger. By default, all global logging functions use this target. The following are all equivalent:
Each one of these functions optionally takes in several arguments that can override / augment the output of logged messages. More on that later! 🙌🏼
77
+
78
+
### Global Settings & Configuration
79
+
80
+
The top-level `Lumberjack` object houses several global settings, as-well-as easy access to the default logger, custom loggers, associated configuration settings, & message publishers.
81
+
82
+
```swift
83
+
Lumberjack
84
+
.verbosity= .just(.error)
85
+
86
+
Lumberjack
87
+
.defaultLogger
88
+
.configuration
89
+
.timestampFormat="yyyy-MM-dd"
40
90
41
-
### Global Logging & Configuration
91
+
Lumberjack
92
+
.anyMessagePublisher
93
+
.sink { print($0.body(formatted: false)) }
94
+
.store(in: &self.bag)
95
+
```
96
+
97
+
You're also not limited to just one "default" logger. Custom loggers can also be created:
98
+
99
+
```swift
100
+
let logger =Logger(id: "custom")
42
101
43
-
TODO: Lumberjack global settings (i.e. verbosity) & loggers
As shown above, logger instances can be created as-needed. However, sometimes you don't need a logger to be globally registered. For example, you might want a logger tied to a specific view / view-controller in your project.
141
+
142
+
```swift
143
+
importUIKit
144
+
importLumberjack
145
+
146
+
classCustomViewController: UIViewController {
147
+
148
+
privatevar logger: Logger!
149
+
150
+
overridefuncviewDidLoad() {
151
+
152
+
super.viewDidLoad()
153
+
154
+
self.logger=Logger { make in
155
+
156
+
make.symbol= .just("📱")
157
+
make.category="CustomView"
158
+
make.components= .simple
159
+
160
+
}
161
+
162
+
}
163
+
164
+
overridefuncviewWillAppear(_animated: Bool) {
165
+
166
+
super.viewWillAppear(animated)
167
+
168
+
self.logger
169
+
.debug("view will appear!")
170
+
171
+
}
50
172
51
-
### Customization
173
+
}
174
+
```
175
+
176
+
#### Customization
177
+
178
+
Loggers can be customized in several different ways. At their core, they use a component-based system to determine what kind of info gets logged to the console. For example, the default message component set consists of the following:
The individual component values are determined based on the logger's configuration, as-well-as any passed in logging function overrides.
215
+
216
+
```swift
217
+
let logger =Logger { make in
218
+
219
+
make.symbol= .just("📱")
220
+
make.category="Example"
221
+
222
+
}
223
+
224
+
logger
225
+
.debug("no overrides")
226
+
227
+
// => "📱 [DEBUG] <Example> 2023-06-30T15:06:37.099 Demo.AppDelegate::46 ➡️ no overrides"
228
+
229
+
logger.info(
230
+
"some overrides",
231
+
symbol: "⭐️",
232
+
category: "Star"
233
+
)
234
+
235
+
// => "⭐️ [INFO] <Star> 2023-06-30T15:06:37.099 Demo.AppDelegate::46 ➡️ some overrides"
236
+
237
+
```
54
238
55
239
### Message Hooks
56
240
57
-
TODO: Message hooks, and the log chain
241
+
Besides logging to the console, sometimes you might need to do additional work with messages (i.e. uploading to a server, writing to disk, etc) - or prevent them from being logged at all. That's where the message hook system comes into play! A hook that persists messages to disk might look something like this:
A message hook simply receives a message, does whatever tasks it needs to with it, then returns a result indicating if the message should be passed on to downstream hooks, or stop and prevent the message from being logged.
287
+
288
+
Lumberjack's internal logging system is even implemented using a message hook similiar to the following:
0 commit comments