Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
d69a8e63
Commit
d69a8e63
authored
5 years ago
by
fangyincheng
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #271 from fangyincheng/develop
Add: add SetLoggerLevel
parents
3e96a64f
956c64f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/logger/logger.go
+26
-1
26 additions, 1 deletion
common/logger/logger.go
common/logger/logger_test.go
+16
-0
16 additions, 0 deletions
common/logger/logger_test.go
with
42 additions
and
1 deletion
common/logger/logger.go
+
26
−
1
View file @
d69a8e63
...
...
@@ -40,6 +40,11 @@ var (
logger
Logger
)
type
DubboLogger
struct
{
Logger
dynamicLevel
zap
.
AtomicLevel
}
type
Logger
interface
{
Info
(
args
...
interface
{})
Warn
(
args
...
interface
{})
...
...
@@ -109,7 +114,8 @@ func InitLogger(conf *zap.Config) {
zapLoggerConfig
=
*
conf
}
zapLogger
,
_
:=
zapLoggerConfig
.
Build
(
zap
.
AddCallerSkip
(
1
))
logger
=
zapLogger
.
Sugar
()
//logger = zapLogger.Sugar()
logger
=
&
DubboLogger
{
Logger
:
zapLogger
.
Sugar
(),
dynamicLevel
:
zapLoggerConfig
.
Level
}
// set getty log
getty
.
SetLogger
(
logger
)
...
...
@@ -123,3 +129,22 @@ func SetLogger(log Logger) {
func
GetLogger
()
Logger
{
return
logger
}
func
SetLoggerLevel
(
level
string
)
bool
{
if
l
,
ok
:=
logger
.
(
OpsLogger
);
ok
{
l
.
SetLoggerLevel
(
level
)
return
true
}
return
false
}
type
OpsLogger
interface
{
Logger
SetLoggerLevel
(
level
string
)
}
func
(
dl
*
DubboLogger
)
SetLoggerLevel
(
level
string
)
{
l
:=
new
(
zapcore
.
Level
)
l
.
Set
(
level
)
dl
.
dynamicLevel
.
SetLevel
(
*
l
)
}
This diff is collapsed.
Click to expand it.
common/logger/logger_test.go
+
16
−
0
View file @
d69a8e63
...
...
@@ -65,3 +65,19 @@ func TestInitLog(t *testing.T) {
Warnf
(
"%s"
,
"warn"
)
Errorf
(
"%s"
,
"error"
)
}
func
TestSetLevel
(
t
*
testing
.
T
)
{
err
:=
InitLog
(
"./log.yml"
)
assert
.
NoError
(
t
,
err
)
Debug
(
"debug"
)
Info
(
"info"
)
assert
.
True
(
t
,
SetLoggerLevel
(
"info"
))
Debug
(
"debug"
)
Info
(
"info"
)
SetLogger
(
GetLogger
()
.
(
*
DubboLogger
)
.
Logger
)
assert
.
False
(
t
,
SetLoggerLevel
(
"debug"
))
Debug
(
"debug"
)
Info
(
"info"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment