Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
195f5f7b
Commit
195f5f7b
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
Commented exported functions
parent
c285ebf9
No related branches found
No related tags found
2 merge requests
!41
Resolve "Enhanced Logging"
,
!18
Develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
log/logger.go
+30
-2
30 additions, 2 deletions
log/logger.go
with
30 additions
and
2 deletions
log/logger.go
+
30
−
2
View file @
195f5f7b
...
...
@@ -22,7 +22,7 @@ type Logger struct {
func
get
()
*
Logger
{
once
.
Do
(
func
()
{
logger
=
&
Logger
{
Out
:
os
.
Std
out
,
Out
:
os
.
Std
err
,
Loglevel
:
INFO
,
lock
:
sync
.
Mutex
{},
}
...
...
@@ -30,6 +30,8 @@ func get() *Logger {
return
logger
}
//Loglevel sets the verbosity of the logger
//Defaults to INFO
func
Loglevel
(
level
Level
)
{
l
:=
get
()
l
.
lock
.
Lock
()
...
...
@@ -37,6 +39,8 @@ func Loglevel(level Level) {
l
.
Loglevel
=
level
}
//Output defines the output of the logger
//Defaults to os.Stderr
func
Output
(
out
io
.
Writer
)
{
l
:=
get
()
l
.
lock
.
Lock
()
...
...
@@ -44,38 +48,62 @@ func Output(out io.Writer) {
l
.
Out
=
out
}
//Debug passes the DEBUG flag and a
//message to the logger
func
Debug
(
args
...
interface
{})
{
log
(
DEBUG
,
args
...
)
}
//Debug passes the DEBUG flag and a
//message to the logger
func
Info
(
args
...
interface
{})
{
log
(
INFO
,
args
...
)
}
//Warn passes the WARNING flag and a
//message to the logger
func
Warn
(
args
...
interface
{})
{
log
(
WARNING
,
args
...
)
}
//Error passes the ERROR flag and a
//message to the logger
func
Error
(
args
...
interface
{})
{
log
(
ERROR
,
args
...
)
}
//Fatal passes the FATAL flag and a
//message to the logger and calls
//os.Exit(1)
func
Fatal
(
args
...
interface
{})
{
log
(
FATAL
,
args
...
)
os
.
Exit
(
1
)
}
//Panic passes the PANIC flag and a
//message to the logger
//Also calls builtin.panic()
func
Panic
(
args
...
interface
{})
{
log
(
PANIC
,
args
...
)
panic
(
args
)
}
func
log
(
level
Level
,
args
...
interface
{})
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
fmt
.
Println
(
"Recovered in f"
,
r
)
}
}()
l
:=
get
()
l
.
lock
.
Lock
()
defer
l
.
lock
.
Unlock
()
if
level
<=
l
.
Loglevel
{
msg
:=
fmt
.
Sprint
(
args
...
)
logMessage
:=
time
.
Now
()
.
Format
(
time
.
RFC3339
)
+
"
\t
"
+
prefix
(
level
)
+
"
\t
"
+
msg
+
"
\n
"
l
.
Out
.
Write
([]
byte
(
logMessage
))
_
,
err
:=
l
.
Out
.
Write
([]
byte
(
logMessage
))
if
err
!=
nil
{
panic
(
err
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment