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
2efe7c4c
Commit
2efe7c4c
authored
Feb 02, 2016
by
youngsterxyf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge multi commit
parent
c71ac743
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
24 deletions
+55
-24
config.go
config.go
+2
-2
log.go
logs/log.go
+53
-22
No files found.
config.go
View file @
2efe7c4c
...
@@ -15,11 +15,11 @@
...
@@ -15,11 +15,11 @@
package
beego
package
beego
import
(
import
(
"fmt"
"html/template"
"html/template"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
"fmt"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/session"
"github.com/astaxie/beego/session"
...
@@ -299,7 +299,7 @@ func parseConfig(appConfigPath string) (err error) {
...
@@ -299,7 +299,7 @@ func parseConfig(appConfigPath string) (err error) {
}
}
//init log
//init log
BeeLogger
.
Close
()
BeeLogger
.
Reset
()
for
adaptor
,
config
:=
range
BConfig
.
Log
.
Outputs
{
for
adaptor
,
config
:=
range
BConfig
.
Log
.
Outputs
{
err
=
BeeLogger
.
SetLogger
(
adaptor
,
config
)
err
=
BeeLogger
.
SetLogger
(
adaptor
,
config
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
logs/log.go
View file @
2efe7c4c
...
@@ -98,8 +98,8 @@ type BeeLogger struct {
...
@@ -98,8 +98,8 @@ type BeeLogger struct {
loggerFuncCallDepth
int
loggerFuncCallDepth
int
asynchronous
bool
asynchronous
bool
msgChan
chan
*
logMsg
msgChan
chan
*
logMsg
signalChan
chan
string
signalChan
chan
string
wg
sync
.
WaitGroup
wg
sync
.
WaitGroup
outputs
[]
*
nameLogger
outputs
[]
*
nameLogger
}
}
...
@@ -111,7 +111,7 @@ type nameLogger struct {
...
@@ -111,7 +111,7 @@ type nameLogger struct {
type
logMsg
struct
{
type
logMsg
struct
{
level
int
level
int
msg
string
msg
string
when
time
.
Time
when
time
.
Time
}
}
var
logMsgPool
*
sync
.
Pool
var
logMsgPool
*
sync
.
Pool
...
@@ -125,7 +125,6 @@ func NewLogger(channelLen int64) *BeeLogger {
...
@@ -125,7 +125,6 @@ func NewLogger(channelLen int64) *BeeLogger {
bl
.
loggerFuncCallDepth
=
2
bl
.
loggerFuncCallDepth
=
2
bl
.
msgChan
=
make
(
chan
*
logMsg
,
channelLen
)
bl
.
msgChan
=
make
(
chan
*
logMsg
,
channelLen
)
bl
.
signalChan
=
make
(
chan
string
,
1
)
bl
.
signalChan
=
make
(
chan
string
,
1
)
bl
.
wg
.
Add
(
1
)
return
bl
return
bl
}
}
...
@@ -137,6 +136,7 @@ func (bl *BeeLogger) Async() *BeeLogger {
...
@@ -137,6 +136,7 @@ func (bl *BeeLogger) Async() *BeeLogger {
return
&
logMsg
{}
return
&
logMsg
{}
},
},
}
}
bl
.
wg
.
Add
(
1
)
go
bl
.
startLogger
()
go
bl
.
startLogger
()
return
bl
return
bl
}
}
...
@@ -236,6 +236,7 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
...
@@ -236,6 +236,7 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
// 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
()
{
gameOver
:=
false
for
{
for
{
select
{
select
{
case
bm
:=
<-
bl
.
msgChan
:
case
bm
:=
<-
bl
.
msgChan
:
...
@@ -243,26 +244,19 @@ func (bl *BeeLogger) startLogger() {
...
@@ -243,26 +244,19 @@ func (bl *BeeLogger) startLogger() {
logMsgPool
.
Put
(
bm
)
logMsgPool
.
Put
(
bm
)
case
sg
:=
<-
bl
.
signalChan
:
case
sg
:=
<-
bl
.
signalChan
:
// Now should only send "flush" or "close" to bl.signalChan
// Now should only send "flush" or "close" to bl.signalChan
for
{
bl
.
flush
()
if
len
(
bl
.
msgChan
)
>
0
{
bm
:=
<-
bl
.
msgChan
bl
.
writeToLoggers
(
bm
.
when
,
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
continue
}
break
}
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Flush
()
}
if
sg
==
"close"
{
if
sg
==
"close"
{
for
_
,
l
:=
range
bl
.
outputs
{
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Destroy
()
l
.
Destroy
()
}
}
bl
.
outputs
=
nil
bl
.
outputs
=
nil
gameOver
=
true
}
}
bl
.
wg
.
Done
()
bl
.
wg
.
Done
()
}
}
if
gameOver
{
break
}
}
}
}
}
...
@@ -370,16 +364,53 @@ func (bl *BeeLogger) Trace(format string, v ...interface{}) {
...
@@ -370,16 +364,53 @@ func (bl *BeeLogger) Trace(format string, v ...interface{}) {
// Flush flush all chan data.
// Flush flush all chan data.
func
(
bl
*
BeeLogger
)
Flush
()
{
func
(
bl
*
BeeLogger
)
Flush
()
{
bl
.
signalChan
<-
"flush"
if
bl
.
asynchronous
{
bl
.
wg
.
Wait
()
bl
.
signalChan
<-
"flush"
bl
.
wg
.
Add
(
1
)
bl
.
wg
.
Wait
()
bl
.
wg
.
Add
(
1
)
return
}
bl
.
flush
()
}
}
// Close close logger, flush all chan data and destroy all adapters in BeeLogger.
// Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func
(
bl
*
BeeLogger
)
Close
()
{
func
(
bl
*
BeeLogger
)
Close
()
{
bl
.
signalChan
<-
"close"
if
bl
.
asynchronous
{
bl
.
wg
.
Wait
()
bl
.
signalChan
<-
"close"
bl
.
wg
.
Add
(
1
)
bl
.
wg
.
Wait
()
}
else
{
bl
.
flush
()
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Destroy
()
}
bl
.
outputs
=
nil
}
close
(
bl
.
msgChan
)
close
(
bl
.
signalChan
)
}
// Reset close all outputs, and set bl.outputs to nil
func
(
bl
*
BeeLogger
)
Reset
()
{
bl
.
Flush
()
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Destroy
()
}
bl
.
outputs
=
nil
}
func
(
bl
*
BeeLogger
)
flush
()
{
for
{
if
len
(
bl
.
msgChan
)
>
0
{
bm
:=
<-
bl
.
msgChan
bl
.
writeToLoggers
(
bm
.
when
,
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
continue
}
break
}
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Flush
()
}
}
}
func
formatLogTime
(
when
time
.
Time
)
string
{
func
formatLogTime
(
when
time
.
Time
)
string
{
...
...
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