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
Copy file name to clipboardExpand all lines: README.md
+19-9Lines changed: 19 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ logger.info("Hello World!")
46
46
#### Default `Logger` behavior
47
47
48
48
`SwiftLog` provides for very basic console logging out-of-the-box by way of `StreamLogHandler`. It is possible to switch the default output to `stderr` like so:
@@ -196,16 +196,22 @@ In most cases, there is only one thing you need to remember: Always use _string
196
196
197
197
Good:
198
198
199
-
logger.info("hello world")
199
+
```swift
200
+
logger.info("hello world")
201
+
```
200
202
201
203
Bad:
202
204
203
-
let message = "hello world"
204
-
logger.info(message)
205
+
```swift
206
+
let message ="hello world"
207
+
logger.info(message)
208
+
```
205
209
206
210
If you have a `String` that you received from elsewhere, please use
207
211
208
-
logger.info("\(stringIAlreadyHave)")
212
+
```swift
213
+
logger.info("\(stringIAlreadyHave)")
214
+
```
209
215
210
216
For more details, have a look in the next section.
211
217
@@ -227,17 +233,21 @@ Swift 4.0 & 4.1 don't support `@inlinable`, so SwiftLog 0 can't use them.
227
233
Because all Swift 4 versions don't have a (non-deprecated) mechanism for a type to be `ExpressibleByStringInterpolation` we couldn't make `Logger.Message` expressible by string literals. Unfortunately, the most basic form of our logging API is `logger.info("Hello \(world)")`. For this to work however, `"Hello \(world)"` needs to be accepted and because we can't make `Logger.Message``ExpressibleByStringInterpolation` we added an overload for all the logging methods to also accept `String`. In most cases, you won't even notice that with SwiftLog 0 you're creating a `String` (which is then transformed to a `Logger.Message`) and with SwiftLog 1 you're creating a `Logger.Message` directly. That is because both `String` and `Logger.Message` will accept all forms of string literals and string interpolations.
228
234
Unfortunately, there is code that will make this seemingly small difference visible. If you write
229
235
230
-
let message = "Hello world"
231
-
logger.info(message)
236
+
```swift
237
+
let message ="Hello world"
238
+
logger.info(message)
239
+
```
232
240
233
241
then this will only work in SwiftLog 0 and not in SwiftLog 1. Why? Because SwiftLog 1 will want a `Logger.Message` but `let message = "Hello world"` will make `message` to be of type `String` and in SwiftLog 1, the logging methods don't accept `String`s.
234
242
235
243
So if you intend to be compatible with SwiftLog 0 and 1 at the same time, please make sure to always use a _string literal_ or a _string interpolation_ inside of the logging methods.
236
244
237
245
In the case that you already have a `String` handy that you want to log, don't worry at all, just use
238
246
239
-
let message = "Hello world"
240
-
logger.info("\(message)")
247
+
```swift
248
+
let message ="Hello world"
249
+
logger.info("\(message)")
250
+
```
241
251
242
252
and again, you will be okay with SwiftLog 0 and 1.
0 commit comments