Skip to content

Commit 27da342

Browse files
authored
Add more syntax highlighting to the readme file (#114)
1 parent 3a9a783 commit 27da342

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ logger.info("Hello World!")
4646
#### Default `Logger` behavior
4747

4848
`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:
49-
```
49+
```swift
5050
LoggingSystem.bootstrap(StreamLogHandler.standardError)
5151
```
5252

@@ -196,16 +196,22 @@ In most cases, there is only one thing you need to remember: Always use _string
196196

197197
Good:
198198

199-
logger.info("hello world")
199+
```swift
200+
logger.info("hello world")
201+
```
200202

201203
Bad:
202204

203-
let message = "hello world"
204-
logger.info(message)
205+
```swift
206+
let message = "hello world"
207+
logger.info(message)
208+
```
205209

206210
If you have a `String` that you received from elsewhere, please use
207211

208-
logger.info("\(stringIAlreadyHave)")
212+
```swift
213+
logger.info("\(stringIAlreadyHave)")
214+
```
209215

210216
For more details, have a look in the next section.
211217

@@ -227,17 +233,21 @@ Swift 4.0 & 4.1 don't support `@inlinable`, so SwiftLog 0 can't use them.
227233
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.
228234
Unfortunately, there is code that will make this seemingly small difference visible. If you write
229235

230-
let message = "Hello world"
231-
logger.info(message)
236+
```swift
237+
let message = "Hello world"
238+
logger.info(message)
239+
```
232240

233241
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.
234242

235243
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.
236244

237245
In the case that you already have a `String` handy that you want to log, don't worry at all, just use
238246

239-
let message = "Hello world"
240-
logger.info("\(message)")
247+
```swift
248+
let message = "Hello world"
249+
logger.info("\(message)")
250+
```
241251

242252
and again, you will be okay with SwiftLog 0 and 1.
243253

0 commit comments

Comments
 (0)