Debian Codegraph @

README.md

raw
1 fluent-logger-golang
2 ====
3
4 [![Build Status](https://github.com/fluent/fluent-logger-golang/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/fluent/fluent-logger-golang/actions)
5 [![GoDoc](https://godoc.org/github.com/fluent/fluent-logger-golang/fluent?status.svg)](https://godoc.org/github.com/fluent/fluent-logger-golang/fluent)
6
7 ## A structured event logger for Fluentd (Golang)
8
9 ## How to install
10
11 ```
12 go get github.com/fluent/fluent-logger-golang/fluent
13 ```
14
15 ## Usage
16
17 Install the package with `go get` and use `import` to include it in your project.
18
19 ```
20 import "github.com/fluent/fluent-logger-golang/fluent"
21 ```
22
23 ## Example
24
25 ```go
26 package main
27
28 import (
29 "github.com/fluent/fluent-logger-golang/fluent"
30 "fmt"
31 //"time"
32 )
33
34 func main() {
35 logger, err := fluent.New(fluent.Config{})
36 if err != nil {
37 fmt.Println(err)
38 }
39 defer logger.Close()
40 tag := "myapp.access"
41 var data = map[string]string{
42 "foo": "bar",
43 "hoge": "hoge",
44 }
45 error := logger.Post(tag, data)
46 // error := logger.PostWithTime(tag, time.Now(), data)
47 if error != nil {
48 panic(error)
49 }
50 }
51 ```
52
53 `data` must be a value like `map[string]literal`, `map[string]interface{}`, `struct` or [`msgp.Marshaler`](http://godoc.org/github.com/tinylib/msgp/msgp#Marshaler). Logger refers tags `msg` or `codec` of each fields of structs.
54
55 ## Setting config values
56
57 ```go
58 f := fluent.New(fluent.Config{FluentPort: 80, FluentHost: "example.com"})
59 ```
60
61 ### FluentNetwork
62
63 Specify the network protocol. The supported values are:
64
65 * "tcp" (use `FluentHost` and `FluentPort`)
66 * "tls" (use`FluentHost` and `FluentPort`)
67 * "unix" (use `FluentSocketPath`)
68
69 The default is "tcp".
70
71 ### FluentHost
72
73 Specify a hostname or IP address as a string for the destination of the "tcp" protocol.
74 The default is "127.0.0.1".
75
76 ### FluentPort
77
78 Specify the TCP port of the destination. The default is 24224.
79
80 ### FluentSocketPath
81
82 Specify the unix socket path when `FluentNetwork` is "unix".
83
84 ### Timeout
85
86 Set the timeout value of `time.Duration` to connect to the destination.
87 The default is 3 seconds.
88
89 ### WriteTimeout
90
91 Sets the timeout value of `time.Duration` for Write call of `logger.Post`.
92 Since the default is zero value, Write will not time out.
93
94 ### BufferLimit
95
96 Sets the number of events buffered on the memory. Records will be stored in memory up to this number. If the buffer is full, the call to record logs will fail.
97 The default is 8192.
98
99 ### RetryWait
100
101 Set the duration of the initial wait for the first retry, in milliseconds. The actual retry wait will be `r * 1.5^(N-1)` (r: this value, N: the number of retries).
102 The default is 500.
103
104 ### MaxRetry
105
106 Sets the maximum number of retries. If the number of retries become larger than this value, the write/send operation will fail.
107 The default is 13.
108
109 ### MaxRetryWait
110
111 The maximum duration of wait between retries, in milliseconds. If the calculated retry wait is larger than this value, the actual retry wait will be this value.
112 The default is 60,000 (60 seconds).
113
114 ### TagPrefix
115
116 Sets the prefix string of the tag. Prefix will be appended with a dot `.`, like `ppp.tag` (ppp: the value of this parameter, tag: the tag string specified in a call).
117 The default is blank.
118
119 ### Async
120
121 Enable asynchronous I/O (connect and write) for sending events to Fluentd.
122 The default is false.
123
124 ### ForceStopAsyncSend
125
126 When Async is enabled, immediately discard the event queue on close() and return (instead of trying MaxRetry times for each event in the queue before returning)
127 The default is false.
128
129 ### AsyncResultCallback
130
131 When Async is enabled, if this is callback is provided, it will be called on every write to Fluentd. The callback function
132 takes two arguments - a `[]byte` of the message that was to be sent and an `error`. If the `error` is not nil this means the
133 delivery of the message was unsuccessful.
134
135 ### AsyncReconnectInterval
136 When async is enabled, this option defines the interval (ms) at which the connection
137 to the fluentd-address is re-established. This option is useful if the address
138 may resolve to one or more IP addresses, e.g. a Consul service address.
139
140 ### SubSecondPrecision
141
142 Enable time encoding as EventTime, which contains sub-second precision values. The messages encoded with this option can be received only by Fluentd v0.14 or later.
143 The default is false.
144
145 ### MarshalAsJson
146
147 Enable Json data marshaling to send messages using Json format (instead of the standard MessagePack). It is supported by Fluentd `in_forward` plugin.
148 The default is false.
149
150 ### RequestAck
151
152 Sets whether to request acknowledgment from Fluentd to increase the reliability
153 of the connection. The default is false.
154
155 ### TlsInsecureSkipVerify
156
157 Skip verifying the server certificate. Useful for development and testing. The default is false.
158
159 ## FAQ
160
161 ### Does this logger support the features of Fluentd Forward Protocol v1?
162
163 "the features" includes heartbeat messages (for TCP keepalive), TLS transport and shared key authentication.
164
165 This logger doesn't support those features. Patches are welcome!
166
167 ### Is it allowed to call `Fluent.Post()` after connection close?
168
169 Before v1.8.0, the Fluent logger silently reopened connections whenever
170 `Fluent.Post()` was called.
171
172 ```go
173 logger, _ := fluent.New(fluent.Config{})
174 logger.Post(tag, data)
175 logger.Close()
176 logger.Post(tag, data) /* reopen connection */
177 ```
178
179 However, this behavior was confusing, in particular when multiple goroutines
180 were involved. Starting v1.8.0, the logger no longer accepts `Fluent.Post()`
181 after `Fluent.Close()`, and instead returns a "Logger already closed" error.
182
183 ## Tests
184 ```
185
186 go test
187 ```