Debian Codegraph @

README.md

raw symbols SCIP
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 ```bash
12 go get github.com/fluent/fluent-logger-golang/fluent@latest
13 ```
14
15 ## Usage
16
17 Install the package with `go get` and use `import` to include it in your project.
18
19 ```go
20 import "github.com/fluent/fluent-logger-golang/fluent"
21 ```
22
23 ## Example
24
25 ```go
26 package main
27
28 import (
29 "fmt"
30 "time"
31
32 "github.com/fluent/fluent-logger-golang/fluent"
33 )
34
35 func main() {
36 logger, err := fluent.New(fluent.Config{})
37 if err != nil {
38 fmt.Println(err)
39 }
40 defer logger.Close()
41 tag := "myapp.access"
42 data := map[string]string{
43 "foo": "bar",
44 "hoge": "hoge",
45 }
46 err = logger.Post(tag, data)
47 if err != nil {
48 panic(err)
49 }
50
51 err = logger.PostWithTime(tag, time.Now(), data)
52 if err != nil {
53 panic(err)
54 }
55 }
56 ```
57
58 `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.
59
60 ## Setting config values
61
62 ```go
63 f := fluent.New(fluent.Config{FluentPort: 80, FluentHost: "example.com"})
64 ```
65
66 ### FluentNetwork
67
68 Specify the network protocol. The supported values are:
69
70 * "tcp" (use `FluentHost` and `FluentPort`)
71 * "tls" (use`FluentHost` and `FluentPort`)
72 * "unix" (use `FluentSocketPath`)
73
74 The default is "tcp".
75
76 ### FluentHost
77
78 Specify a hostname or IP address as a string for the destination of the "tcp" protocol.
79 The default is "127.0.0.1".
80
81 ### FluentPort
82
83 Specify the TCP port of the destination. The default is 24224.
84
85 ### FluentSocketPath
86
87 Specify the unix socket path when `FluentNetwork` is "unix".
88
89 ### Timeout
90
91 Set the timeout value of `time.Duration` to connect to the destination.
92 The default is 3 seconds.
93
94 ### WriteTimeout
95
96 Sets the timeout value of `time.Duration` for Write call of `logger.Post`.
97 Since the default is zero value, Write will not time out.
98
99 ### BufferLimit
100
101 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.
102 The default is 8192.
103
104 ### RetryWait
105
106 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).
107 The default is 500.
108
109 ### MaxRetry
110
111 Sets the maximum number of retries. If the number of retries become larger than this value, the write/send operation will fail.
112 The default is 13.
113
114 ### MaxRetryWait
115
116 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.
117 The default is 60,000 (60 seconds).
118
119 ### TagPrefix
120
121 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).
122 The default is blank.
123
124 ### Async
125
126 Enable asynchronous I/O (connect and write) for sending events to Fluentd.
127 The default is false.
128
129 ### ForceStopAsyncSend
130
131 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)
132 The default is false.
133
134 ### AsyncResultCallback
135
136 When Async is enabled, if this is callback is provided, it will be called on every write to Fluentd. The callback function
137 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
138 delivery of the message was unsuccessful.
139
140 ### AsyncReconnectInterval
141 When async is enabled, this option defines the interval (ms) at which the connection
142 to the fluentd-address is re-established. This option is useful if the address
143 may resolve to one or more IP addresses, e.g. a Consul service address.
144
145 ### SubSecondPrecision
146
147 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.
148 The default is false.
149
150 ### MarshalAsJson
151
152 Enable Json data marshaling to send messages using Json format (instead of the standard MessagePack). It is supported by Fluentd `in_forward` plugin.
153 The default is false.
154
155 ### RequestAck
156
157 Sets whether to request acknowledgment from Fluentd to increase the reliability
158 of the connection. The default is false.
159
160 ### TlsInsecureSkipVerify
161
162 Skip verifying the server certificate. Useful for development and testing. The default is false.
163
164 ## FAQ
165
166 ### Does this logger support the features of Fluentd Forward Protocol v1?
167
168 "the features" includes heartbeat messages (for TCP keepalive), TLS transport and shared key authentication.
169
170 This logger doesn't support those features. Patches are welcome!
171
172 ### Is it allowed to call `Fluent.Post()` after connection close?
173
174 Before v1.8.0, the Fluent logger silently reopened connections whenever
175 `Fluent.Post()` was called.
176
177 ```go
178 logger, _ := fluent.New(fluent.Config{})
179 logger.Post(tag, data)
180 logger.Close()
181 logger.Post(tag, data) /* reopen connection */
182 ```
183
184 However, this behavior was confusing, in particular when multiple goroutines
185 were involved. Starting v1.8.0, the logger no longer accepts `Fluent.Post()`
186 after `Fluent.Close()`, and instead returns a "Logger already closed" error.
187
188 ## Tests
189
190 ```bash
191 go test
192 ```