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
1b94f63b
Commit
1b94f63b
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
added *f logging functions and some comment formatting
parent
21eddd61
Branches
Branches containing commit
No related tags found
3 merge requests
!90
Develop
,
!61
Resolve "Logger with formatting directives"
,
!53
V.0.1.0 Codename Threadbare
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
log/logger.go
+56
-25
56 additions, 25 deletions
log/logger.go
log/loglevel.go
+1
-2
1 addition, 2 deletions
log/loglevel.go
with
57 additions
and
27 deletions
log/logger.go
+
56
−
25
View file @
1b94f63b
...
@@ -58,8 +58,8 @@ func get() *Logger {
...
@@ -58,8 +58,8 @@ func get() *Logger {
return
logger
return
logger
}
}
//Loglevel sets the verbosity of the logger
//
Loglevel sets the verbosity of the logger
//Defaults to INFO
//
Defaults to INFO
func
Loglevel
(
level
Level
)
{
func
Loglevel
(
level
Level
)
{
l
:=
get
()
l
:=
get
()
l
.
lock
.
Lock
()
l
.
lock
.
Lock
()
...
@@ -67,8 +67,8 @@ func Loglevel(level Level) {
...
@@ -67,8 +67,8 @@ func Loglevel(level Level) {
l
.
Loglevel
=
level
l
.
Loglevel
=
level
}
}
//Output defines the output of the logger
//
Output defines the output of the logger
//Defaults to os.Stderr
//
Defaults to os.Stderr
func
Output
(
out
io
.
Writer
)
{
func
Output
(
out
io
.
Writer
)
{
l
:=
get
()
l
:=
get
()
l
.
lock
.
Lock
()
l
.
lock
.
Lock
()
...
@@ -76,8 +76,8 @@ func Output(out io.Writer) {
...
@@ -76,8 +76,8 @@ func Output(out io.Writer) {
l
.
DefaultWriter
=
out
l
.
DefaultWriter
=
out
}
}
//LoglevelOutput defines a special output
//
LoglevelOutput defines a special output
//for a certain log level
//
for a certain log level
func
LoglevelOutput
(
level
Level
,
out
io
.
Writer
)
{
func
LoglevelOutput
(
level
Level
,
out
io
.
Writer
)
{
l
:=
get
()
l
:=
get
()
l
.
lock
.
Lock
()
l
.
lock
.
Lock
()
...
@@ -88,44 +88,77 @@ func LoglevelOutput(level Level, out io.Writer) {
...
@@ -88,44 +88,77 @@ func LoglevelOutput(level Level, out io.Writer) {
}
}
}
}
//Debug passes the DEBUG flag and a
//
Debug passes the DEBUG flag and a
//message to the logger
//
message to the logger
func
Debug
(
args
...
interface
{})
{
func
Debug
(
args
...
interface
{})
{
log
(
DEBUG
,
args
...
)
log
(
DEBUG
,
args
...
)
}
}
//Info passes the INFO flag and a
//
Info passes the INFO flag and a
//message to the logger
//
message to the logger
func
Info
(
args
...
interface
{})
{
func
Info
(
args
...
interface
{})
{
log
(
INFO
,
args
...
)
log
(
INFO
,
args
...
)
}
}
//Warn passes the WARNING flag and a
//
Warn passes the WARNING flag and a
//message to the logger
//
message to the logger
func
Warn
(
args
...
interface
{})
{
func
Warn
(
args
...
interface
{})
{
log
(
WARNING
,
args
...
)
log
(
WARNING
,
args
...
)
}
}
//Error passes the ERROR flag and a
//
Error passes the ERROR flag and a
//message to the logger
//
message to the logger
func
Error
(
args
...
interface
{})
{
func
Error
(
args
...
interface
{})
{
log
(
ERROR
,
args
...
)
log
(
ERROR
,
args
...
)
}
}
//Fatal passes the FATAL flag and a
//
Fatal passes the FATAL flag and a
//message to the logger and calls
//
message to the logger and calls
//os.Exit(1)
//
os.Exit(1)
func
Fatal
(
args
...
interface
{})
{
func
Fatal
(
args
...
interface
{})
{
log
(
FATAL
,
args
...
)
log
(
FATAL
,
args
...
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
//Panic passes the PANIC flag and a
// Debugf passes the DEBUG flag,
//message to the logger
// a formatted string and a
//Also calls builtin.panic()
// message to the logger
func
Panic
(
args
...
interface
{})
{
func
Debugf
(
format
string
,
args
...
interface
{})
{
log
(
PANIC
,
args
...
)
logf
(
DEBUG
,
format
,
args
...
)
panic
(
args
)
}
// Infof passes the INFO flag,
// a formatted string and and a
// message to the logger
func
Infof
(
format
string
,
args
...
interface
{})
{
logf
(
INFO
,
format
,
args
...
)
}
// Warnf passes the WARNING flag,
// a formatted string and and a
// message to the logger
func
Warnf
(
format
string
,
args
...
interface
{})
{
logf
(
WARNING
,
format
,
args
...
)
}
// Errorf passes the ERROR flag,
// a formatted string and and a
// message to the logger
func
Errorf
(
format
string
,
args
...
interface
{})
{
logf
(
ERROR
,
format
,
args
...
)
}
// Fatalf passes the FATAL flag,
// a formatted string and and a
// message to the logger and calls
// os.Exit(1)
func
Fatalf
(
format
string
,
args
...
interface
{})
{
logf
(
FATAL
,
format
,
args
...
)
os
.
Exit
(
1
)
}
func
logf
(
level
Level
,
format
string
,
args
...
interface
{})
{
log
(
level
,
fmt
.
Sprintf
(
format
,
args
...
))
}
}
func
log
(
level
Level
,
args
...
interface
{})
{
func
log
(
level
Level
,
args
...
interface
{})
{
...
@@ -164,8 +197,6 @@ func callers() (string, int) {
...
@@ -164,8 +197,6 @@ func callers() (string, int) {
func
prefix
(
level
Level
)
string
{
func
prefix
(
level
Level
)
string
{
switch
level
{
switch
level
{
case
PANIC
:
return
"PANIC"
case
FATAL
:
case
FATAL
:
return
"FATAL"
return
"FATAL"
case
ERROR
:
case
ERROR
:
...
...
This diff is collapsed.
Click to expand it.
log/loglevel.go
+
1
−
2
View file @
1b94f63b
...
@@ -7,8 +7,7 @@ type Level uint8
...
@@ -7,8 +7,7 @@ type Level uint8
// Constants for more verbose integer
// Constants for more verbose integer
// values
// values
const
(
const
(
PANIC
Level
=
iota
FATAL
Level
=
iota
FATAL
ERROR
ERROR
WARNING
WARNING
INFO
INFO
...
...
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