@@ -21,6 +21,7 @@ This guide full of examples is intended for people learning Go that are coming f
21
21
- [Examples](#examples)
22
22
- [comments](#comments)
23
23
- [printing](#printing)
24
+ - [logging](#logging)
24
25
- [variables](#variables)
25
26
- [types](#types)
26
27
- [bool](#types)
@@ -190,17 +191,59 @@ func main() {
190
191
#### Node.js
191
192
192
193
```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 ')
196
197
```
197
198
198
199
Output
199
200
200
201
```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
204
247
```
205
248
206
249
#### Go
@@ -212,17 +255,13 @@ import "log"
212
255
213
256
func main() {
214
257
log.Println("hello world")
215
- log.Printf("hello %s\n", "world")
216
- log.Printf("hello %d %s\n", 5, "worlds")
217
258
}
218
259
```
219
260
220
261
Output
221
262
222
263
```bash
223
- hello world
224
- hello world
225
- hello 5 worlds
264
+ 2021/04/11 13:55:07 hello world
226
265
```
227
266
228
267
**[⬆ back to top](#contents)**
0 commit comments