forked from g3n/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.go
42 lines (31 loc) · 803 Bytes
/
net.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
// Copyright 2016 The G3N Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logger
import (
"net"
)
// Net is a network writer used for logging.
type Net struct {
conn net.Conn
}
// NewNet creates and returns a pointer to a new Net object along with any error that occurred.
func NewNet(network string, address string) (*Net, error) {
n := new(Net)
conn, err := net.Dial(network, address)
if err != nil {
return nil, err
}
n.conn = conn
return n, nil
}
// Write writes the provided logger event to the network.
func (n *Net) Write(event *Event) {
n.conn.Write([]byte(event.fmsg))
}
// Clone closes the network connection.
func (n *Net) Close() {
n.conn.Close()
}
func (n *Net) Sync() {
}