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
3f5fee2d
Commit
3f5fee2d
authored
Mar 25, 2014
by
asta.xie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logs support file & filenum
parent
c7f16b5d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
5 deletions
+37
-5
config.go
config.go
+5
-0
console_test.go
logs/console_test.go
+2
-0
log.go
logs/log.go
+30
-5
No files found.
config.go
View file @
3f5fee2d
...
...
@@ -60,6 +60,7 @@ var (
AdminHttpPort
int
FlashName
string
// name of the flash variable found in response header and cookie
FlashSeperator
string
// used to seperate flash key:value
EnableLogFuncCallDepth
bool
// enable the funcCallDeppth
)
func
init
()
{
...
...
@@ -133,6 +134,10 @@ func init() {
// init BeeLogger
BeeLogger
=
logs
.
NewLogger
(
10000
)
BeeLogger
.
SetLogger
(
"console"
,
""
)
if
EnableLogFuncCallDepth
{
BeeLogger
.
EnableFuncCallDepth
(
true
)
BeeLogger
.
SetLogFuncCallDepth
(
3
)
}
err
:=
ParseConfig
()
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
...
...
logs/console_test.go
View file @
3f5fee2d
...
...
@@ -6,6 +6,7 @@ import (
func
TestConsole
(
t
*
testing
.
T
)
{
log
:=
NewLogger
(
10000
)
log
.
EnableFuncCallDepth
(
true
)
log
.
SetLogger
(
"console"
,
""
)
log
.
Trace
(
"trace"
)
log
.
Info
(
"info"
)
...
...
@@ -23,6 +24,7 @@ func TestConsole(t *testing.T) {
func
BenchmarkConsole
(
b
*
testing
.
B
)
{
log
:=
NewLogger
(
10000
)
log
.
EnableFuncCallDepth
(
true
)
log
.
SetLogger
(
"console"
,
""
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
log
.
Trace
(
"trace"
)
...
...
logs/log.go
View file @
3f5fee2d
...
...
@@ -2,6 +2,8 @@ package logs
import
(
"fmt"
"path"
"runtime"
"sync"
)
...
...
@@ -43,10 +45,12 @@ func Register(name string, log loggerType) {
// BeeLogger is default logger in beego application.
// it can contain several providers and log message into all providers.
type
BeeLogger
struct
{
lock
sync
.
Mutex
level
int
msg
chan
*
logMsg
outputs
map
[
string
]
LoggerInterface
lock
sync
.
Mutex
level
int
enableFuncCallDepth
bool
loggerFuncCallDepth
int
msg
chan
*
logMsg
outputs
map
[
string
]
LoggerInterface
}
type
logMsg
struct
{
...
...
@@ -59,6 +63,7 @@ type logMsg struct {
// if the buffering chan is full, logger adapters write to file or other way.
func
NewLogger
(
channellen
int64
)
*
BeeLogger
{
bl
:=
new
(
BeeLogger
)
bl
.
loggerFuncCallDepth
=
2
bl
.
msg
=
make
(
chan
*
logMsg
,
channellen
)
bl
.
outputs
=
make
(
map
[
string
]
LoggerInterface
)
//bl.SetLogger("console", "") // default output to console
...
...
@@ -100,7 +105,17 @@ func (bl *BeeLogger) writerMsg(loglevel int, msg string) error {
}
lm
:=
new
(
logMsg
)
lm
.
level
=
loglevel
lm
.
msg
=
msg
if
bl
.
enableFuncCallDepth
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
bl
.
loggerFuncCallDepth
)
if
ok
{
_
,
filename
:=
path
.
Split
(
file
)
lm
.
msg
=
fmt
.
Sprintf
(
"[%s:%d] %s"
,
filename
,
line
,
msg
)
}
else
{
lm
.
msg
=
msg
}
}
else
{
lm
.
msg
=
msg
}
bl
.
msg
<-
lm
return
nil
}
...
...
@@ -111,6 +126,16 @@ func (bl *BeeLogger) SetLevel(l int) {
bl
.
level
=
l
}
// set log funcCallDepth
func
(
bl
*
BeeLogger
)
SetLogFuncCallDepth
(
d
int
)
{
bl
.
loggerFuncCallDepth
=
d
}
// enable log funcCallDepth
func
(
bl
*
BeeLogger
)
EnableFuncCallDepth
(
b
bool
)
{
bl
.
enableFuncCallDepth
=
b
}
// start logger chan reading.
// when chan is full, write logs.
func
(
bl
*
BeeLogger
)
StartLogger
()
{
...
...
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