Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
a9a15e2c
Commit
a9a15e2c
authored
May 01, 2018
by
Waleed Gadelkareem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow log prefix
parent
bebd2c46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
log.go
logs/log.go
+16
-2
No files found.
logs/log.go
View file @
a9a15e2c
...
@@ -47,7 +47,7 @@ import (
...
@@ -47,7 +47,7 @@ import (
// RFC5424 log message levels.
// RFC5424 log message levels.
const
(
const
(
LevelEmergency
=
iota
LevelEmergency
=
iota
LevelAlert
LevelAlert
LevelCritical
LevelCritical
LevelError
LevelError
...
@@ -116,6 +116,7 @@ type BeeLogger struct {
...
@@ -116,6 +116,7 @@ type BeeLogger struct {
enableFuncCallDepth
bool
enableFuncCallDepth
bool
loggerFuncCallDepth
int
loggerFuncCallDepth
int
asynchronous
bool
asynchronous
bool
prefix
string
msgChanLen
int64
msgChanLen
int64
msgChan
chan
*
logMsg
msgChan
chan
*
logMsg
signalChan
chan
string
signalChan
chan
string
...
@@ -247,7 +248,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
...
@@ -247,7 +248,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
}
}
// writeMsg will always add a '\n' character
// writeMsg will always add a '\n' character
if
p
[
len
(
p
)
-
1
]
==
'\n'
{
if
p
[
len
(
p
)
-
1
]
==
'\n'
{
p
=
p
[
0
:
len
(
p
)
-
1
]
p
=
p
[
0
:
len
(
p
)
-
1
]
}
}
// set levelLoggerImpl to ensure all log message will be write out
// set levelLoggerImpl to ensure all log message will be write out
err
=
bl
.
writeMsg
(
levelLoggerImpl
,
string
(
p
))
err
=
bl
.
writeMsg
(
levelLoggerImpl
,
string
(
p
))
...
@@ -267,6 +268,9 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error
...
@@ -267,6 +268,9 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error
if
len
(
v
)
>
0
{
if
len
(
v
)
>
0
{
msg
=
fmt
.
Sprintf
(
msg
,
v
...
)
msg
=
fmt
.
Sprintf
(
msg
,
v
...
)
}
}
msg
=
bl
.
prefix
+
" "
+
msg
when
:=
time
.
Now
()
when
:=
time
.
Now
()
if
bl
.
enableFuncCallDepth
{
if
bl
.
enableFuncCallDepth
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
bl
.
loggerFuncCallDepth
)
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
bl
.
loggerFuncCallDepth
)
...
@@ -320,6 +324,11 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
...
@@ -320,6 +324,11 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
bl
.
enableFuncCallDepth
=
b
bl
.
enableFuncCallDepth
=
b
}
}
// set prefix
func
(
bl
*
BeeLogger
)
SetPrefix
(
s
string
)
{
bl
.
prefix
=
s
}
// start logger chan reading.
// start logger chan reading.
// when chan is not empty, write logs.
// when chan is not empty, write logs.
func
(
bl
*
BeeLogger
)
startLogger
()
{
func
(
bl
*
BeeLogger
)
startLogger
()
{
...
@@ -544,6 +553,11 @@ func SetLevel(l int) {
...
@@ -544,6 +553,11 @@ func SetLevel(l int) {
beeLogger
.
SetLevel
(
l
)
beeLogger
.
SetLevel
(
l
)
}
}
// SetPrefix sets the prefix
func
SetPrefix
(
s
string
)
{
beeLogger
.
SetPrefix
(
s
)
}
// EnableFuncCallDepth enable log funcCallDepth
// EnableFuncCallDepth enable log funcCallDepth
func
EnableFuncCallDepth
(
b
bool
)
{
func
EnableFuncCallDepth
(
b
bool
)
{
beeLogger
.
enableFuncCallDepth
=
b
beeLogger
.
enableFuncCallDepth
=
b
...
...
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