Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
1077109e
Commit
1077109e
authored
Jan 21, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JsonLogger type
parent
ed7d7b40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
backend.go
eth/backend.go
+9
-0
loggers.go
logger/loggers.go
+26
-0
No files found.
eth/backend.go
View file @
1077109e
...
...
@@ -44,6 +44,7 @@ type Config struct {
}
var
logger
=
ethlogger
.
NewLogger
(
"SERV"
)
var
jsonlogger
=
ethlogger
.
NewJsonLogger
()
type
Ethereum
struct
{
// Channel for shutting down the ethereum
...
...
@@ -221,6 +222,14 @@ func (s *Ethereum) MaxPeers() int {
// Start the ethereum
func
(
s
*
Ethereum
)
Start
(
seed
bool
)
error
{
evd
:=
map
[
string
]
interface
{}{
"version_string"
:
s
.
ClientIdentity
()
.
String
(),
"guid"
:
ethutil
.
Bytes2Hex
(
s
.
ClientIdentity
()
.
Pubkey
()),
"level"
:
"debug"
,
"coinbase"
:
ethutil
.
Bytes2Hex
(
s
.
KeyManager
()
.
Address
()),
"eth_version"
:
ProtocolVersion
,
}
jsonlogger
.
Log
(
"starting"
,
evd
)
err
:=
s
.
net
.
Start
()
if
err
!=
nil
{
return
err
...
...
logger/loggers.go
View file @
1077109e
...
...
@@ -13,8 +13,10 @@ logging of mutable state.
package
logger
import
(
"encoding/json"
"fmt"
"os"
"time"
)
type
LogLevel
uint32
...
...
@@ -112,3 +114,27 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) {
Flush
()
os
.
Exit
(
0
)
}
type
JsonLogger
struct
{}
func
NewJsonLogger
()
*
JsonLogger
{
return
&
JsonLogger
{}
}
func
(
logger
*
JsonLogger
)
Log
(
msgname
string
,
dict
map
[
string
]
interface
{})
{
if
_
,
ok
:=
dict
[
"ts"
];
!
ok
{
dict
[
"ts"
]
=
time
.
Now
()
.
Local
()
.
Format
(
time
.
RFC3339Nano
)
}
// FIX
if
_
,
ok
:=
dict
[
"level"
];
!
ok
{
dict
[
"level"
]
=
"debug"
}
obj
:=
map
[
string
]
interface
{}{
msgname
:
dict
,
}
jsontxt
,
_
:=
json
.
Marshal
(
obj
)
logMessageC
<-
message
{
JsonLevel
,
fmt
.
Sprintf
(
"%s"
,
jsontxt
)}
}
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