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
2bad25f5
Commit
2bad25f5
authored
Aug 09, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
5e325a41
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
72 deletions
+66
-72
writer.go
log/a/writer.go
+0
-61
logger.go
log/logger.go
+66
-11
No files found.
log/a/writer.go
deleted
100644 → 0
View file @
5e325a41
package
a
import
(
"bytes"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"runtime"
"strconv"
"strings"
"time"
)
const
(
DebugL
=
"Debug"
InfoL
=
"Info"
ErrorL
=
"Error"
)
// Colors
const
(
Reset
=
"
\0
33[0m"
Red
=
"
\0
33[31m"
Green
=
"
\0
33[32m"
Yellow
=
"
\0
33[33m"
Blue
=
"
\0
33[34m"
Magenta
=
"
\0
33[35m"
Cyan
=
"
\0
33[36m"
White
=
"
\0
33[37m"
BlueBold
=
"
\0
33[34;1m"
MagentaBold
=
"
\0
33[35;1m"
RedBold
=
"
\0
33[31;1m"
YellowBold
=
"
\0
33[33;1m"
)
func
Print
(
tag
,
msg
string
,
file
string
,
line
int
)
{
str
:=
"%s %s [%d] %s %d %s"
if
conf
.
LogColorful
{
if
tag
==
"Error"
{
str
=
"%s %s [%d] %s %d "
+
Red
+
"%s"
+
Reset
}
else
if
tag
==
"Info"
{
str
=
"%s %s [%d] %s %d "
+
Yellow
+
"%s"
+
Reset
}
else
{
str
=
"%s %s [%d] %s %d "
+
Green
+
"%s"
+
Reset
}
}
file
=
file
[
strings
.
LastIndex
(
file
,
"/"
)
+
1
:
]
fmt
.
Println
(
fmt
.
Sprintf
(
str
,
FormatDateMillTime
(
time
.
Now
()),
tag
,
getGID
(),
file
,
line
,
msg
))
}
func
FormatDateMillTime
(
dataTime
time
.
Time
)
string
{
return
dataTime
.
Format
(
"2006-01-02 15:04:05.000000"
)
}
func
getGID
()
uint64
{
b
:=
make
([]
byte
,
64
)
b
=
b
[
:
runtime
.
Stack
(
b
,
false
)]
b
=
bytes
.
TrimPrefix
(
b
,
[]
byte
(
"goroutine "
))
b
=
b
[
:
bytes
.
IndexByte
(
b
,
' '
)]
n
,
_
:=
strconv
.
ParseUint
(
string
(
b
),
10
,
64
)
return
n
}
log/logger.go
View file @
2bad25f5
package
log
package
log
import
(
import
(
"bytes"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/log/a"
"runtime"
"runtime"
"strconv"
"strings"
"strings"
"time"
)
const
(
LevelDebug
=
"Debug"
LevelInfo
=
"Info"
LevelError
=
"Error"
)
)
func
DebugDo
(
f
func
())
{
func
DebugDo
(
f
func
())
{
...
@@ -16,7 +25,7 @@ func DebugDo(f func()) {
...
@@ -16,7 +25,7 @@ func DebugDo(f func()) {
func
IsDebug
()
bool
{
func
IsDebug
()
bool
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
a
.
DebugL
)
:
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
ok
=
true
break
break
}
}
...
@@ -26,47 +35,93 @@ func IsDebug() bool {
...
@@ -26,47 +35,93 @@ func IsDebug() bool {
func
Debug
(
msg
string
)
{
func
Debug
(
msg
string
)
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
a
.
DebugL
)
:
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
ok
=
true
break
break
}
}
if
ok
{
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
a
.
P
rint
(
"Debug"
,
msg
,
file
,
line
)
p
rint
(
"Debug"
,
msg
,
file
,
line
)
}
}
}
}
func
Info
(
msg
string
)
{
func
Info
(
msg
string
)
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
a
.
DebugL
)
:
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
ok
=
true
break
break
case
strings
.
ToLower
(
a
.
InfoL
)
:
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
ok
=
true
break
break
}
}
if
ok
{
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
a
.
P
rint
(
"Info"
,
msg
,
file
,
line
)
p
rint
(
"Info"
,
msg
,
file
,
line
)
}
}
}
}
func
Error
(
msg
string
)
{
func
Error
(
msg
string
)
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
a
.
DebugL
)
:
case
strings
.
ToLower
(
LevelDebug
)
:
ok
=
true
ok
=
true
break
break
case
strings
.
ToLower
(
a
.
InfoL
)
:
case
strings
.
ToLower
(
LevelInfo
)
:
ok
=
true
ok
=
true
break
break
case
strings
.
ToLower
(
a
.
ErrorL
)
:
case
strings
.
ToLower
(
LevelError
)
:
ok
=
true
ok
=
true
break
break
}
}
if
ok
{
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
a
.
P
rint
(
"Error"
,
msg
,
file
,
line
)
p
rint
(
"Error"
,
msg
,
file
,
line
)
}
}
}
}
// Colors
const
(
reset
=
"
\0
33[0m"
red
=
"
\0
33[31m"
green
=
"
\0
33[32m"
yellow
=
"
\0
33[33m"
blue
=
"
\0
33[34m"
magenta
=
"
\0
33[35m"
cyan
=
"
\0
33[36m"
white
=
"
\0
33[37m"
blueBold
=
"
\0
33[34;1m"
magentaBold
=
"
\0
33[35;1m"
redBold
=
"
\0
33[31;1m"
yellowBold
=
"
\0
33[33;1m"
)
func
print
(
tag
,
msg
string
,
file
string
,
line
int
)
{
str
:=
"%s %s [%d] %s %d %s"
if
conf
.
LogColorful
{
if
tag
==
"Error"
{
str
=
"%s %s [%d] %s %d "
+
red
+
"%s"
+
reset
}
else
if
tag
==
"Info"
{
str
=
"%s %s [%d] %s %d "
+
yellow
+
"%s"
+
reset
}
else
{
str
=
"%s %s [%d] %s %d "
+
green
+
"%s"
+
reset
}
}
file
=
file
[
strings
.
LastIndex
(
file
,
"/"
)
+
1
:
]
fmt
.
Println
(
fmt
.
Sprintf
(
str
,
formatDateMillTime
(
time
.
Now
()),
tag
,
getGID
(),
file
,
line
,
msg
))
}
func
formatDateMillTime
(
dataTime
time
.
Time
)
string
{
return
dataTime
.
Format
(
"2006-01-02 15:04:05.000000"
)
}
func
getGID
()
uint64
{
b
:=
make
([]
byte
,
64
)
b
=
b
[
:
runtime
.
Stack
(
b
,
false
)]
b
=
bytes
.
TrimPrefix
(
b
,
[]
byte
(
"goroutine "
))
b
=
b
[
:
bytes
.
IndexByte
(
b
,
' '
)]
n
,
_
:=
strconv
.
ParseUint
(
string
(
b
),
10
,
64
)
return
n
}
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