Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GelfWriter ¶
type GelfWriter struct {
Logger *Logger
}
GelfWriter Use the logger to write log messages
func (*GelfWriter) Write ¶
func (gw *GelfWriter) Write(p []byte) (n int, err error)
Write writes the log message to Graylog. It first unmarshals the log message into a map, and then retrieves the "message" key from the map. It ensures that the connection to Graylog is alive before writing the log message. If the connection is not alive, it calls the ensureConnection method to establish a new connection
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a logging client that connects to a Graylog server using TCP.
The Logger struct has the following fields: - conn: The network connection to the Graylog server. - connLock: A mutex used to ensure thread-safe access to the conn field. - address: The address of the Graylog server to connect to. - useTLS: A boolean value indicating whether to use TLS for the connection. - tslConfig: The TLS configuration to use if useTLS is true. - host: The hostname of the client machine.
The Logger struct provides the following methods: - connect: Establishes a connection to the Graylog server. - ensureConnection: Ensures that a connection to the Graylog server is established, reconnecting if necessary. - Log: Sends a log message to the Graylog server.
func NewLogger ¶
func NewLogger(address string, useTSL bool, tslConfig *tls.Config, baseLogProcessor func(fields map[string]interface{}) (int, float64, []byte, error)) (*Logger, error)
NewLogger creates a new Logger.
Example with TLS:
// Load our Root CA certificate caCert, err := os.ReadFile("/path/to/ca.crt") if err != nil { log.Fatal(err) } caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) // Create the credentials and return it config := &tls.Config{ RootCAs: caCertPool, InsecureSkipVerify: true, // Other fields can be filled in as necessary } writer, err := NewLogger("localhost:1234", true, config)
This creates a new Logger that will use TLS when connecting to the specified address.