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
13557f1d
Commit
13557f1d
authored
Aug 25, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysql加入连接配置
parent
1ebe242b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
16 deletions
+31
-16
logger.go
log/logger.go
+29
-14
RedisClient.go
redis/RedisClient.go
+2
-2
No files found.
log/logger.go
View file @
13557f1d
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
const
(
const
(
LevelDebug
=
"Debug"
LevelDebug
=
"Debug"
LevelInfo
=
"Info"
LevelInfo
=
"Info"
LevelWarn
=
"Warn"
LevelError
=
"Error"
LevelError
=
"Error"
)
)
...
@@ -41,7 +42,7 @@ func Debug(msg string) {
...
@@ -41,7 +42,7 @@ func Debug(msg string) {
}
}
if
ok
{
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
"Debug"
,
msg
,
file
,
line
)
print
(
LevelDebug
,
msg
,
file
,
line
)
}
}
}
}
...
@@ -49,15 +50,28 @@ func Info(msg string) {
...
@@ -49,15 +50,28 @@ func Info(msg string) {
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
case
strings
.
ToLower
(
LevelDebug
)
:
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
ok
=
true
break
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
LevelInfo
,
msg
,
file
,
line
)
}
}
func
Warn
(
msg
string
)
{
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
case
strings
.
ToLower
(
LevelInfo
)
:
case
strings
.
ToLower
(
LevelInfo
)
:
case
strings
.
ToLower
(
LevelWarn
)
:
ok
=
true
ok
=
true
break
break
}
}
if
ok
{
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
"Info"
,
msg
,
file
,
line
)
print
(
LevelWarn
,
msg
,
file
,
line
)
}
}
}
}
...
@@ -65,23 +79,18 @@ func Error(msg string) {
...
@@ -65,23 +79,18 @@ func Error(msg string) {
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
LevelDebug
)
:
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
break
case
strings
.
ToLower
(
LevelInfo
)
:
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
case
strings
.
ToLower
(
LevelWarn
)
:
break
case
strings
.
ToLower
(
LevelError
)
:
case
strings
.
ToLower
(
LevelError
)
:
ok
=
true
ok
=
true
break
break
}
}
if
ok
{
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
print
(
"Error"
,
msg
,
file
,
line
)
print
(
LevelError
,
msg
,
file
,
line
)
}
}
}
}
// Colors
// Colors
const
(
const
(
reset
=
"
\0
33[0m"
reset
=
"
\0
33[0m"
...
@@ -101,12 +110,18 @@ const (
...
@@ -101,12 +110,18 @@ const (
func
print
(
tag
,
msg
string
,
file
string
,
line
int
)
{
func
print
(
tag
,
msg
string
,
file
string
,
line
int
)
{
str
:=
"%s %s [%d] %s %d %s"
str
:=
"%s %s [%d] %s %d %s"
if
conf
.
LogColorful
{
if
conf
.
LogColorful
{
if
tag
==
"Error"
{
switch
tag
{
str
=
"%s %s [%d] %s %d "
+
red
+
"%s"
+
reset
case
strings
.
ToLower
(
LevelDebug
)
:
}
else
if
tag
==
"Info"
{
str
=
"%s %s [%d] %s %d "
+
yellow
+
"%s"
+
reset
}
else
{
str
=
"%s %s [%d] %s %d "
+
green
+
"%s"
+
reset
str
=
"%s %s [%d] %s %d "
+
green
+
"%s"
+
reset
break
case
strings
.
ToLower
(
LevelInfo
)
:
break
case
strings
.
ToLower
(
LevelWarn
)
:
str
=
"%s %s [%d] %s %d "
+
yellow
+
"%s"
+
reset
break
case
strings
.
ToLower
(
LevelError
)
:
str
=
"%s %s [%d] %s %d "
+
red
+
"%s"
+
reset
break
}
}
}
}
file
=
file
[
strings
.
LastIndex
(
file
,
"/"
)
+
1
:
]
file
=
file
[
strings
.
LastIndex
(
file
,
"/"
)
+
1
:
]
...
...
redis/RedisClient.go
View file @
13557f1d
...
@@ -70,7 +70,7 @@ func Get(key string) []byte {
...
@@ -70,7 +70,7 @@ func Get(key string) []byte {
r
:=
getDb
()
.
Get
(
key
)
r
:=
getDb
()
.
Get
(
key
)
rByte
,
err
:=
r
.
Bytes
()
rByte
,
err
:=
r
.
Bytes
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
fmt
.
Sprintf
(
"获取缓存错误:%s"
,
err
.
Error
()))
log
.
Warn
(
fmt
.
Sprintf
(
"获取缓存错误:%s"
,
err
.
Error
()))
}
}
return
rByte
return
rByte
}
}
...
@@ -85,7 +85,7 @@ func Expire(k string, t int64) bool {
...
@@ -85,7 +85,7 @@ func Expire(k string, t int64) bool {
if
b
.
Val
()
{
if
b
.
Val
()
{
log
.
Debug
(
fmt
.
Sprintf
(
"设置缓存过期成功:%s %d"
,
k
,
t
))
log
.
Debug
(
fmt
.
Sprintf
(
"设置缓存过期成功:%s %d"
,
k
,
t
))
}
else
{
}
else
{
log
.
Debug
(
fmt
.
Sprintf
(
"设置缓存过期失败:%s %d"
,
k
,
t
))
log
.
Warn
(
fmt
.
Sprintf
(
"设置缓存过期失败:%s %d"
,
k
,
t
))
}
}
return
b
.
Val
()
return
b
.
Val
()
...
...
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