-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
59 lines (43 loc) · 1.67 KB
/
examples_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
package reactLog_test
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/MatejB/reactLog"
)
func ExampleDiscard() {
reactLogger := reactLog.New(os.Stdout) // use os.Stderr for default log functionality
reactLogger.AddReaction("INFO", &reactLog.Discard{})
logger := log.New(reactLogger, "", 0)
logger.Println("INFO this will NOT be written")
logger.Println("ERROR this will be written")
// Output: ERROR this will be written
}
func ExampleRedirect() {
logContainerForUser107 := &bytes.Buffer{} // it can be any io.Writer eq. file
reactLogger := reactLog.New(ioutil.Discard) // use os.Stderr for default log functionality
reactLogger.AddReaction("user ID 107", &reactLog.Redirect{logContainerForUser107})
logger := log.New(reactLogger, "", 0)
logger.Println("INFO dummy log 1")
logger.Println("ERROR dummy log 2")
logger.Println("Log concerning user ID 107 with extra data")
logger.Println("INFO dummy log 3")
logger.Println("ERROR dummy log 4")
fmt.Println(logContainerForUser107)
// Output: Log concerning user ID 107 with extra data
}
func ExampleCopy() {
logContainerForUser107 := &bytes.Buffer{} // it can be any io.Writer eq. file
reactLogger := reactLog.New(os.Stdout) // use os.Stderr for default log functionality
reactLogger.AddReaction("user ID 107", &reactLog.Copy{logContainerForUser107})
logger := log.New(reactLogger, "", 0)
logger.Println("Log concerning user ID 107 with extra data")
logger.Println("INFO dummy log")
fmt.Println(logContainerForUser107) // in logContainerForUser107 is copy of log just for USER_107
// Output:
// Log concerning user ID 107 with extra data
// INFO dummy log
// Log concerning user ID 107 with extra data
}