mirror of
https://github.com/log-chipper/chipper.git
synced 2026-06-11 09:13:23 -05:00
feat: first init
- Simple unix daemon - Python, Go, and C client
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package chipper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
conn *net.UnixConn
|
||||
service string
|
||||
source string
|
||||
}
|
||||
|
||||
func NewClient(socketPath, service, source string) (*Client, error) {
|
||||
addr := &net.UnixAddr{Name: socketPath, Net: "unixgram"}
|
||||
conn, err := net.DialUnix("unixgram", nil, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{
|
||||
conn: conn,
|
||||
service: service,
|
||||
source: source,
|
||||
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Log(level, msg string) error {
|
||||
line := fmt.Sprintf(
|
||||
"level=%s service=%s source=%s msg=\"%s\"",
|
||||
level, c.service, c.source, msg,
|
||||
)
|
||||
_, err := c.conn.Write([]byte(line))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user