Skip to content

Commit 633babd

Browse files
committed
Update logging example
1 parent be94c56 commit 633babd

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

README.md

+50-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This guide full of examples is intended for people learning Go that are coming f
2121
- [Examples](#examples)
2222
- [comments](#comments)
2323
- [printing](#printing)
24+
- [logging](#logging)
2425
- [variables](#variables)
2526
- [types](#types)
2627
- [bool](#types)
@@ -190,17 +191,59 @@ func main() {
190191
#### Node.js
191192

192193
```node
193-
console.log('hello world')
194-
console.log('hello %s', 'world')
195-
console.log('hello %d %s', 5, 'worlds')
194+
console.log('print to stdout')
195+
console.log('format %s %d', 'example', 1)
196+
console.error('print to stderr')
196197
```
197198

198199
Output
199200

200201
```bash
201-
hello world
202-
hello world
203-
hello 5 worlds
202+
print to stdout
203+
format example 1
204+
print to stderr
205+
```
206+
207+
#### Go
208+
209+
```go
210+
package main
211+
212+
import (
213+
"fmt"
214+
"os"
215+
)
216+
217+
func main() {
218+
fmt.Println("print to stdout")
219+
fmt.Printf("format %s %v\n", "example", 1)
220+
fmt.Fprintf(os.Stderr, "print to stderr")
221+
}
222+
```
223+
224+
Output
225+
226+
```bash
227+
print to stdout
228+
format example 1
229+
print to stderr
230+
```
231+
232+
**[⬆ back to top](#contents)**
233+
234+
### logging
235+
---
236+
237+
#### Node.js
238+
239+
```node
240+
console.log((new Date()).toISOString(), 'hello world')
241+
```
242+
243+
Output
244+
245+
```bash
246+
2021-04-11T20:55:07.451Z hello world
204247
```
205248

206249
#### Go
@@ -212,17 +255,13 @@ import "log"
212255

213256
func main() {
214257
log.Println("hello world")
215-
log.Printf("hello %s\n", "world")
216-
log.Printf("hello %d %s\n", 5, "worlds")
217258
}
218259
```
219260

220261
Output
221262

222263
```bash
223-
hello world
224-
hello world
225-
hello 5 worlds
264+
2021/04/11 13:55:07 hello world
226265
```
227266

228267
**[⬆ back to top](#contents)**

examples/logging.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "log"
4+
5+
func main() {
6+
log.Println("hello world")
7+
}

examples/logging.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log((new Date()).toISOString(), 'hello world')

examples/print.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"os"
6+
)
47

58
func main() {
6-
fmt.Println("hello world")
7-
fmt.Printf("hello %s\n", "world")
8-
fmt.Printf("hello %d %s\n", 5, "worlds")
9+
fmt.Println("print to stdout")
10+
fmt.Printf("format %s %v\n", "example", 1)
11+
fmt.Fprintf(os.Stderr, "print to stderr")
912
}

examples/print.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
console.log('hello world')
2-
console.log('hello %s', 'world')
3-
console.log('hello %d %s', 5, 'worlds')
1+
console.log('print to stdout')
2+
console.log('format %s %d', 'example', 1)
3+
console.error('print to stderr')

0 commit comments

Comments
 (0)