Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
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
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
zhengqiuyun
rym-util
Commits
b6be637a
Commit
b6be637a
authored
Oct 11, 2022
by
yemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整格式化日志打印时不能反映调用者的问题
logEnd方法开放
parent
a3b2e002
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
14 deletions
+68
-14
Response.go
getWay/Response.go
+9
-9
logger.go
log/logger.go
+59
-5
No files found.
getWay/Response.go
View file @
b6be637a
...
...
@@ -38,7 +38,7 @@ func FailGetWay(c *gin.Context, state State, subCode, subMsg string) {
resp
:=
responseSub
(
state
,
subCode
,
subMsg
)
c
.
JSON
(
http
.
StatusBadGateway
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
func
FailAndMsg
(
c
*
gin
.
Context
,
subCode
,
subMsg
string
)
{
...
...
@@ -46,7 +46,7 @@ func FailAndMsg(c *gin.Context, subCode, subMsg string) {
resp
:=
ServerResponse
{
Code
:
BusinessError
,
Msg
:
"业务错误"
,
SubCode
:
subCode
,
SubMsg
:
subMsg
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
// FailAndMsgNoTx 不带事务
...
...
@@ -54,7 +54,7 @@ func FailAndMsgNoTx(c *gin.Context, subCode, subMsg string) {
resp
:=
ServerResponse
{
Code
:
BusinessError
,
Msg
:
"业务错误"
,
SubCode
:
subCode
,
SubMsg
:
subMsg
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
// Success 有事务的用这个
...
...
@@ -63,7 +63,7 @@ func Success(c *gin.Context) {
resp
:=
response
(
OK
)
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
// SuccessNoTx 不带事务提交
...
...
@@ -71,7 +71,7 @@ func SuccessNoTx(c *gin.Context) {
resp
:=
response
(
OK
)
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
// SuccessData 有事务的用这个
...
...
@@ -80,7 +80,7 @@ func SuccessData(c *gin.Context, data interface{}) {
resp
:=
ServerDataResponse
{
response
(
OK
),
data
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
// SuccessDataNoTx 不带事务提交
...
...
@@ -88,16 +88,16 @@ func SuccessDataNoTx(c *gin.Context, data interface{}) {
resp
:=
ServerDataResponse
{
response
(
OK
),
data
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
l
ogEnd
(
c
,
resp
)
L
ogEnd
(
c
,
resp
)
}
func
SuccessString
(
c
*
gin
.
Context
,
data
string
)
{
c
.
String
(
http
.
StatusOK
,
data
)
c
.
Abort
()
l
ogEnd
(
c
,
data
)
L
ogEnd
(
c
,
data
)
}
func
l
ogEnd
(
c
*
gin
.
Context
,
data
interface
{})
{
func
L
ogEnd
(
c
*
gin
.
Context
,
data
interface
{})
{
esSwitch
:=
redis
.
SwitchOpen
(
redis
.
ES日志开关
+
conf
.
ServerName
)
startTime
:=
GetStartTime
(
c
)
endTime
:=
time
.
Now
()
.
UnixNano
()
...
...
log/logger.go
View file @
b6be637a
...
...
@@ -34,7 +34,16 @@ func IsDebug() bool {
}
func
Debugf
(
format
string
,
msg
...
interface
{})
{
Debug
(
fmt
.
Sprintf
(
format
,
msg
...
))
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
LevelDebug
,
file
,
line
,
fmt
.
Sprintf
(
format
,
msg
...
))
}
}
func
Debug
(
msg
interface
{})
{
...
...
@@ -51,7 +60,19 @@ func Debug(msg interface{}) {
}
func
Infof
(
format
string
,
msg
...
interface
{})
{
Info
(
fmt
.
Sprintf
(
format
,
msg
...
))
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
LevelInfo
,
file
,
line
,
fmt
.
Sprintf
(
format
,
msg
...
))
}
}
func
Info
(
msg
interface
{})
{
...
...
@@ -71,7 +92,22 @@ func Info(msg interface{}) {
}
func
Warnf
(
format
string
,
msg
...
interface
{})
{
Warn
(
fmt
.
Sprintf
(
format
,
msg
...
))
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelWarn
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
LevelWarn
,
file
,
line
,
fmt
.
Sprintf
(
format
,
msg
...
))
}
}
func
Warn
(
msg
interface
{})
{
...
...
@@ -89,12 +125,30 @@ func Warn(msg interface{}) {
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
LevelWarn
,
file
,
line
,
msg
)
print
(
LevelWarn
,
file
,
line
,
msg
)
}
}
func
Errorf
(
format
string
,
msg
...
interface
{})
{
Error
(
fmt
.
Sprintf
(
format
,
msg
...
))
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelWarn
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelError
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
LevelError
,
file
,
line
,
fmt
.
Sprintf
(
format
,
msg
...
))
}
}
func
Error
(
msg
interface
{})
{
...
...
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