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
5dec3d12
Commit
5dec3d12
authored
Feb 02, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
colorful console only the terminal supports
parent
16b01c36
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
console.go
logs/console.go
+10
-7
No files found.
logs/console.go
View file @
5dec3d12
...
@@ -49,7 +49,7 @@ var colors = []brush{
...
@@ -49,7 +49,7 @@ var colors = []brush{
type
consoleWriter
struct
{
type
consoleWriter
struct
{
lg
*
log
.
Logger
lg
*
log
.
Logger
Level
int
`json:"level"`
Level
int
`json:"level"`
Color
bool
`json:"color"`
Color
ful
bool
`json:"color"`
//this filed is useful only when system's terminal supports color
}
}
// NewConsole create ConsoleWriter returning as LoggerInterface.
// NewConsole create ConsoleWriter returning as LoggerInterface.
...
@@ -57,7 +57,7 @@ func NewConsole() Logger {
...
@@ -57,7 +57,7 @@ func NewConsole() Logger {
cw
:=
&
consoleWriter
{
cw
:=
&
consoleWriter
{
lg
:
log
.
New
(
os
.
Stdout
,
""
,
0
),
lg
:
log
.
New
(
os
.
Stdout
,
""
,
0
),
Level
:
LevelDebug
,
Level
:
LevelDebug
,
Color
:
true
,
Color
ful
:
true
,
}
}
return
cw
return
cw
}
}
...
@@ -68,7 +68,11 @@ func (c *consoleWriter) Init(jsonConfig string) error {
...
@@ -68,7 +68,11 @@ func (c *consoleWriter) Init(jsonConfig string) error {
if
len
(
jsonConfig
)
==
0
{
if
len
(
jsonConfig
)
==
0
{
return
nil
return
nil
}
}
return
json
.
Unmarshal
([]
byte
(
jsonConfig
),
c
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonConfig
),
c
)
if
runtime
.
GOOS
==
"windows"
{
c
.
Colorful
=
false
}
return
err
}
}
// WriteMsg write message in console.
// WriteMsg write message in console.
...
@@ -77,12 +81,11 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
...
@@ -77,12 +81,11 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
return
nil
return
nil
}
}
msg
=
formatLogTime
(
when
)
+
msg
msg
=
formatLogTime
(
when
)
+
msg
if
runtime
.
GOOS
==
"windows"
||
!
c
.
Color
{
if
c
.
Colorful
{
c
.
lg
.
Println
(
colors
[
level
](
msg
))
}
else
{
c
.
lg
.
Println
(
msg
)
c
.
lg
.
Println
(
msg
)
return
nil
}
}
c
.
lg
.
Println
(
colors
[
level
](
msg
))
return
nil
return
nil
}
}
...
...
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