Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
sidecar
Commits
d0ffd216
Commit
d0ffd216
authored
Sep 17, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add log package
parent
3098180c
Pipeline
#8008
failed with stages
Changes
17
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
215 additions
and
17 deletions
+215
-17
sidecar.go
cmd/sidecar/sidecar.go
+2
-1
start.go
cmd/sidecar/start.go
+1
-1
config.go
hub/client/config.go
+2
-1
mock_client.go
hub/client/mock_client/mock_client.go
+2
-3
mock_executor.go
internal/appchain/mock_executor/mock_executor.go
+0
-1
mock_monitor.go
internal/appchain/mock_monitor/mock_monitor.go
+0
-1
loggers.go
internal/loggers/loggers.go
+1
-1
mock_peermgr.go
internal/peermgr/mock_peermgr/mock_peermgr.go
+0
-1
peermgr_test.go
internal/peermgr/peermgr_test.go
+1
-1
mock_router.go
internal/router/mock_router/mock_router.go
+0
-1
mock_syncer.go
internal/syncer/mock_syncer/mock_syncer.go
+1
-2
syncer_test.go
internal/syncer/syncer_test.go
+1
-1
config.go
pkg/log/config.go
+79
-0
hook.go
pkg/log/hook.go
+34
-0
log.go
pkg/log/log.go
+90
-0
mock_client.go
pkg/plugins/mock_client/mock_client.go
+0
-1
plugin.go
pkg/plugins/plugin.go
+1
-1
No files found.
cmd/sidecar/sidecar.go
View file @
d0ffd216
...
@@ -5,8 +5,9 @@ import (
...
@@ -5,8 +5,9 @@ import (
"time"
"time"
"github.com/fatih/color"
"github.com/fatih/color"
"github.com/meshplus/bitxhub-kit/log"
"github.com/urfave/cli"
"github.com/urfave/cli"
"github.com/link33/sidecar/pkg/log"
)
)
var
logger
=
log
.
NewWithModule
(
"cmd"
)
var
logger
=
log
.
NewWithModule
(
"cmd"
)
...
...
cmd/sidecar/start.go
View file @
d0ffd216
...
@@ -11,13 +11,13 @@ import (
...
@@ -11,13 +11,13 @@ import (
"syscall"
"syscall"
"time"
"time"
"github.com/meshplus/bitxhub-kit/log"
"github.com/urfave/cli"
"github.com/urfave/cli"
"github.com/link33/sidecar/internal"
"github.com/link33/sidecar/internal"
"github.com/link33/sidecar/internal/app"
"github.com/link33/sidecar/internal/app"
"github.com/link33/sidecar/internal/loggers"
"github.com/link33/sidecar/internal/loggers"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/pkg/log"
)
)
var
startCMD
=
cli
.
Command
{
var
startCMD
=
cli
.
Command
{
...
...
hub/client/config.go
View file @
d0ffd216
...
@@ -6,7 +6,8 @@ import (
...
@@ -6,7 +6,8 @@ import (
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/fileutil"
"github.com/meshplus/bitxhub-kit/fileutil"
"github.com/meshplus/bitxhub-kit/log"
"github.com/link33/sidecar/pkg/log"
)
)
const
(
const
(
...
...
hub/client/mock_client/mock_client.go
View file @
d0ffd216
...
@@ -9,11 +9,10 @@ import (
...
@@ -9,11 +9,10 @@ import (
reflect
"reflect"
reflect
"reflect"
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
crypto
"github.com/meshplus/bitxhub-kit/crypto"
types
"github.com/meshplus/bitxhub-kit/types"
rpcx
"github.com/link33/sidecar/hub/client"
rpcx
"github.com/link33/sidecar/hub/client"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
crypto
"github.com/meshplus/bitxhub-kit/crypto"
types
"github.com/meshplus/bitxhub-kit/types"
)
)
// MockClient is a mock of Client interface.
// MockClient is a mock of Client interface.
...
...
internal/appchain/mock_executor/mock_executor.go
View file @
d0ffd216
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
reflect
"reflect"
reflect
"reflect"
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
)
)
...
...
internal/appchain/mock_monitor/mock_monitor.go
View file @
d0ffd216
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
reflect
"reflect"
reflect
"reflect"
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
)
)
...
...
internal/loggers/loggers.go
View file @
d0ffd216
package
loggers
package
loggers
import
(
import
(
"github.com/meshplus/bitxhub-kit/log"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/pkg/log"
)
)
const
(
const
(
...
...
internal/peermgr/mock_peermgr/mock_peermgr.go
View file @
d0ffd216
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
peer
"github.com/libp2p/go-libp2p-core/peer"
peer
"github.com/libp2p/go-libp2p-core/peer"
peermgr
"github.com/link33/sidecar/internal/peermgr"
peermgr
"github.com/link33/sidecar/internal/peermgr"
port
"github.com/link33/sidecar/internal/port"
port
"github.com/link33/sidecar/internal/port"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
...
...
internal/peermgr/peermgr_test.go
View file @
d0ffd216
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
peer2
"github.com/libp2p/go-libp2p-core/peer"
peer2
"github.com/libp2p/go-libp2p-core/peer"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto/asym"
"github.com/meshplus/bitxhub-kit/crypto/asym"
"github.com/meshplus/bitxhub-kit/log"
network
"github.com/meshplus/go-lightp2p"
network
"github.com/meshplus/go-lightp2p"
ma
"github.com/multiformats/go-multiaddr"
ma
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
...
@@ -18,6 +17,7 @@ import (
...
@@ -18,6 +17,7 @@ import (
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/repo"
router2
"github.com/link33/sidecar/internal/router"
router2
"github.com/link33/sidecar/internal/router"
"github.com/link33/sidecar/model/pb"
"github.com/link33/sidecar/model/pb"
"github.com/link33/sidecar/pkg/log"
)
)
var
routerTmp
router2
.
Router
var
routerTmp
router2
.
Router
...
...
internal/router/mock_router/mock_router.go
View file @
d0ffd216
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
reflect
"reflect"
reflect
"reflect"
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
port
"github.com/link33/sidecar/internal/port"
port
"github.com/link33/sidecar/internal/port"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
)
)
...
...
internal/syncer/mock_syncer/mock_syncer.go
View file @
d0ffd216
...
@@ -8,10 +8,9 @@ import (
...
@@ -8,10 +8,9 @@ import (
reflect
"reflect"
reflect
"reflect"
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
appchain_mgr
"github.com/meshplus/bitxhub-core/appchain-mgr"
syncer
"github.com/link33/sidecar/internal/syncer"
syncer
"github.com/link33/sidecar/internal/syncer"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
appchain_mgr
"github.com/meshplus/bitxhub-core/appchain-mgr"
)
)
// MockSyncer is a mock of Syncer interface.
// MockSyncer is a mock of Syncer interface.
...
...
internal/syncer/syncer_test.go
View file @
d0ffd216
...
@@ -18,7 +18,6 @@ import (
...
@@ -18,7 +18,6 @@ import (
"github.com/meshplus/bitxhub-core/governance"
"github.com/meshplus/bitxhub-core/governance"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto/asym"
"github.com/meshplus/bitxhub-kit/crypto/asym"
"github.com/meshplus/bitxhub-kit/log"
"github.com/meshplus/bitxhub-kit/storage/leveldb"
"github.com/meshplus/bitxhub-kit/storage/leveldb"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-kit/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
...
@@ -28,6 +27,7 @@ import (
...
@@ -28,6 +27,7 @@ import (
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/model/constant"
"github.com/link33/sidecar/model/constant"
"github.com/link33/sidecar/model/pb"
"github.com/link33/sidecar/model/pb"
"github.com/link33/sidecar/pkg/log"
)
)
const
(
const
(
...
...
pkg/log/config.go
0 → 100644
View file @
d0ffd216
package
log
import
"time"
type
config
struct
{
reportCaller
bool
persist
bool
filePath
string
fileName
string
maxSize
int64
maxAge
time
.
Duration
rotationTime
time
.
Duration
}
type
Option
func
(
*
config
)
func
WithReportCaller
(
reportCaller
bool
)
Option
{
return
func
(
c
*
config
)
{
c
.
reportCaller
=
reportCaller
}
}
func
WithPersist
(
persist
bool
)
Option
{
return
func
(
c
*
config
)
{
c
.
persist
=
persist
}
}
func
WithFilePath
(
filePath
string
)
Option
{
return
func
(
c
*
config
)
{
c
.
filePath
=
filePath
}
}
func
WithFileName
(
fileName
string
)
Option
{
return
func
(
c
*
config
)
{
c
.
fileName
=
fileName
}
}
func
WithMaxSize
(
maxSize
int64
)
Option
{
return
func
(
c
*
config
)
{
c
.
maxSize
=
maxSize
}
}
func
WithMaxAge
(
maxAge
time
.
Duration
)
Option
{
return
func
(
c
*
config
)
{
c
.
maxAge
=
maxAge
}
}
func
WithRotationTime
(
rotationTime
time
.
Duration
)
Option
{
return
func
(
c
*
config
)
{
c
.
rotationTime
=
rotationTime
}
}
func
defaultConfig
()
*
config
{
return
&
config
{
reportCaller
:
false
,
persist
:
false
,
filePath
:
"./"
,
fileName
:
"log"
,
maxSize
:
2
*
1024
*
1024
,
maxAge
:
2
*
time
.
Hour
,
rotationTime
:
24
*
time
.
Hour
,
}
}
func
generateConfig
(
opts
...
Option
)
*
config
{
config
:=
defaultConfig
()
for
_
,
opt
:=
range
opts
{
opt
(
config
)
}
return
config
}
pkg/log/hook.go
0 → 100644
View file @
d0ffd216
package
log
import
(
"path"
"time"
rotatelogs
"github.com/lestrrat-go/file-rotatelogs"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
)
func
newRotateHook
(
logPath
string
,
logFileName
string
,
maxAge
time
.
Duration
,
rotationTime
time
.
Duration
)
*
lfshook
.
LfsHook
{
baseLogName
:=
path
.
Join
(
logPath
,
logFileName
)
writer
,
err
:=
rotatelogs
.
New
(
baseLogName
+
"%Y%m%d%H%M%S"
,
rotatelogs
.
WithLinkName
(
baseLogName
),
rotatelogs
.
WithMaxAge
(
maxAge
),
rotatelogs
.
WithRotationTime
(
rotationTime
),
)
if
err
!=
nil
{
logrus
.
Errorf
(
"config local file system logger error. %s"
,
err
)
return
nil
}
return
lfshook
.
NewHook
(
lfshook
.
WriterMap
{
logrus
.
DebugLevel
:
writer
,
logrus
.
InfoLevel
:
writer
,
logrus
.
WarnLevel
:
writer
,
logrus
.
ErrorLevel
:
writer
,
logrus
.
FatalLevel
:
writer
,
logrus
.
PanicLevel
:
writer
,
},
getTextFormatter
())
}
pkg/log/log.go
0 → 100644
View file @
d0ffd216
package
log
import
(
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/sirupsen/logrus"
)
type
loggerContext
struct
{
loggers
map
[
string
]
logrus
.
FieldLogger
config
*
config
hooks
[]
logrus
.
Hook
}
var
loggerCtx
=
defaultLoggerContext
()
func
defaultLoggerContext
()
*
loggerContext
{
return
&
loggerContext
{
loggers
:
make
(
map
[
string
]
logrus
.
FieldLogger
),
config
:
defaultConfig
(),
hooks
:
make
([]
logrus
.
Hook
,
0
),
}
}
func
New
()
*
logrus
.
Logger
{
logger
:=
logrus
.
New
()
formatter
:=
getTextFormatter
()
logger
.
SetFormatter
(
formatter
)
logger
.
SetReportCaller
(
loggerCtx
.
config
.
reportCaller
)
logger
.
SetOutput
(
os
.
Stdout
)
for
_
,
hook
:=
range
loggerCtx
.
hooks
{
logger
.
AddHook
(
hook
)
}
return
logger
}
func
NewWithModule
(
name
string
)
*
logrus
.
Entry
{
logger
:=
New
()
l
:=
logger
.
WithField
(
"module"
,
name
)
loggerCtx
.
loggers
[
name
]
=
l
return
l
}
func
ParseLevel
(
level
string
)
logrus
.
Level
{
lvl
,
err
:=
logrus
.
ParseLevel
(
level
)
if
err
!=
nil
{
lvl
=
logrus
.
ErrorLevel
}
return
lvl
}
// Initialize initializes a logger instance with given
// level, filepath, filename, maxSize, maxAge and rotationTime.
func
Initialize
(
opts
...
Option
)
error
{
config
:=
generateConfig
(
opts
...
)
loggerCtx
.
config
=
config
if
err
:=
os
.
MkdirAll
(
config
.
filePath
,
os
.
ModePerm
);
err
!=
nil
{
return
fmt
.
Errorf
(
"create file path: %w"
,
err
)
}
if
config
.
persist
{
rotation
:=
newRotateHook
(
config
.
filePath
,
config
.
fileName
,
config
.
maxAge
,
config
.
rotationTime
)
loggerCtx
.
hooks
=
append
(
loggerCtx
.
hooks
,
rotation
)
}
return
nil
}
func
getTextFormatter
()
logrus
.
Formatter
{
return
&
logrus
.
TextFormatter
{
FullTimestamp
:
true
,
TimestampFormat
:
"2006-01-02T15:04:05.000"
,
CallerPrettyfier
:
func
(
f
*
runtime
.
Frame
)
(
string
,
string
)
{
_
,
filename
:=
filepath
.
Split
(
f
.
File
)
return
""
,
fmt
.
Sprintf
(
"%12s:%-4d"
,
filename
,
f
.
Line
)
},
}
}
pkg/plugins/mock_client/mock_client.go
View file @
d0ffd216
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
reflect
"reflect"
reflect
"reflect"
gomock
"github.com/golang/mock/gomock"
gomock
"github.com/golang/mock/gomock"
pb
"github.com/link33/sidecar/model/pb"
pb
"github.com/link33/sidecar/model/pb"
plugins
"github.com/link33/sidecar/pkg/plugins"
plugins
"github.com/link33/sidecar/pkg/plugins"
)
)
...
...
pkg/plugins/plugin.go
View file @
d0ffd216
...
@@ -44,7 +44,7 @@ func (p *AppchainGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Serve
...
@@ -44,7 +44,7 @@ func (p *AppchainGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Serve
func
(
p
*
AppchainGRPCPlugin
)
GRPCClient
(
ctx
context
.
Context
,
broker
*
plugin
.
GRPCBroker
,
c
*
grpc
.
ClientConn
)
(
interface
{},
error
)
{
func
(
p
*
AppchainGRPCPlugin
)
GRPCClient
(
ctx
context
.
Context
,
broker
*
plugin
.
GRPCBroker
,
c
*
grpc
.
ClientConn
)
(
interface
{},
error
)
{
return
&
GRPCClient
{
return
&
GRPCClient
{
client
:
pb
.
NewAppchainPluginClient
(
c
),
// 创建gRPC客户端的方法是自动生成的
client
:
pb
.
NewAppchainPluginClient
(
c
),
// 创建gRPC客户端的方法是自动生成的
D
oneContext
:
ctx
,
d
oneContext
:
ctx
,
},
nil
},
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