Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
0bff097a
Commit
0bff097a
authored
Nov 07, 2015
by
Nick Owens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/log: implement syslog logger
parent
0a0a0776
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
pkg/log/syslog.go
+93
-0
No files found.
pkg/log/syslog.go
0 → 100644
View file @
0bff097a
package
log
import
(
"encoding/json"
"errors"
"log/syslog"
)
type
SyslogWriter
struct
{
syslog
*
syslog
.
Writer
Network
string
`json:"network"`
Address
string
`json:"address"`
Facility
string
`json:"facility"`
Tag
string
`json:"tag"`
}
func
NewSyslog
()
LoggerInterface
{
return
new
(
SyslogWriter
)
}
func
(
sw
*
SyslogWriter
)
Init
(
config
string
)
error
{
if
err
:=
json
.
Unmarshal
([]
byte
(
config
),
sw
);
err
!=
nil
{
return
err
}
prio
,
err
:=
parseFacility
(
sw
.
Facility
)
if
err
!=
nil
{
return
err
}
w
,
err
:=
syslog
.
Dial
(
sw
.
Network
,
sw
.
Address
,
prio
,
sw
.
Tag
)
if
err
!=
nil
{
return
err
}
sw
.
syslog
=
w
return
nil
}
func
(
sw
*
SyslogWriter
)
WriteMsg
(
msg
string
,
skip
,
level
int
)
error
{
var
err
error
switch
level
{
case
TRACE
,
DEBUG
:
err
=
sw
.
syslog
.
Debug
(
msg
)
case
INFO
:
err
=
sw
.
syslog
.
Info
(
msg
)
case
WARN
:
err
=
sw
.
syslog
.
Warning
(
msg
)
case
ERROR
:
err
=
sw
.
syslog
.
Err
(
msg
)
case
CRITICAL
:
err
=
sw
.
syslog
.
Crit
(
msg
)
case
FATAL
:
err
=
sw
.
syslog
.
Alert
(
msg
)
default
:
err
=
errors
.
New
(
"invalid syslog level"
)
}
return
err
}
func
(
sw
*
SyslogWriter
)
Destroy
()
{
sw
.
syslog
.
Close
()
}
func
(
sw
*
SyslogWriter
)
Flush
()
{}
var
facilities
=
map
[
string
]
syslog
.
Priority
{
"user"
:
syslog
.
LOG_USER
,
"daemon"
:
syslog
.
LOG_DAEMON
,
"local0"
:
syslog
.
LOG_LOCAL0
,
"local1"
:
syslog
.
LOG_LOCAL1
,
"local2"
:
syslog
.
LOG_LOCAL2
,
"local3"
:
syslog
.
LOG_LOCAL3
,
"local4"
:
syslog
.
LOG_LOCAL4
,
"local5"
:
syslog
.
LOG_LOCAL5
,
"local6"
:
syslog
.
LOG_LOCAL6
,
"local7"
:
syslog
.
LOG_LOCAL7
,
}
func
parseFacility
(
facility
string
)
(
syslog
.
Priority
,
error
)
{
prio
,
ok
:=
facilities
[
facility
]
if
!
ok
{
return
syslog
.
LOG_LOCAL0
,
errors
.
New
(
"invalid syslog facility"
)
}
return
prio
,
nil
}
func
init
()
{
Register
(
"syslog"
,
NewSyslog
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment