-
Notifications
You must be signed in to change notification settings - Fork 31
/
example_test.go
82 lines (56 loc) · 1.81 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2016 Qiang Xue. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package log_test
import "github.com/go-ozzo/ozzo-log"
func ExampleLogger_Error() {
logger := log.NewLogger()
logger.Targets = append(logger.Targets, log.NewConsoleTarget())
logger.Open()
// log without formatting
logger.Error("a plain message")
// log with formatting
logger.Error("the value is: %v", 100)
}
func ExampleNewConsoleTarget() {
logger := log.NewLogger()
// creates a ConsoleTarget with color mode being disabled
target := log.NewConsoleTarget()
target.ColorMode = false
logger.Targets = append(logger.Targets, target)
logger.Open()
// ... logger is ready to use ...
}
func ExampleNewNetworkTarget() {
logger := log.NewLogger()
// creates a NetworkTarget which uses tcp network and address :10234
target := log.NewNetworkTarget()
target.Network = "tcp"
target.Address = ":10234"
logger.Targets = append(logger.Targets, target)
logger.Open()
// ... logger is ready to use ...
}
func ExampleNewMailTarget() {
logger := log.NewLogger()
// creates a MailTarget which sends emails to [email protected]
target := log.NewMailTarget()
target.Host = "smtp.example.com"
target.Username = "foo"
target.Password = "bar"
target.Subject = "log messages for foobar"
target.Sender = "[email protected]"
target.Recipients = []string{"[email protected]"}
logger.Targets = append(logger.Targets, target)
logger.Open()
// ... logger is ready to use ...
}
func ExampleNewFileTarget() {
logger := log.NewLogger()
// creates a FileTarget which keeps log messages in the app.log file
target := log.NewFileTarget()
target.FileName = "app.log"
logger.Targets = append(logger.Targets, target)
logger.Open()
// ... logger is ready to use ...
}