Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
kaopu-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
994aa870
authored
Dec 24, 2019
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改文件类型
parent
1f7a8e7d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
3 deletions
cmd/main.go
internal/logic/mylog.go
cmd/main.go
View file @
994aa870
package
main
import
"fmt"
import
(
"kaopu-server/internal/logic"
)
func
main
()
{
fmt
.
Print
(
123
)
logic
.
LogEs
(
"123113131"
)
logic
.
LogEs
(
"4567889"
)
logic
.
LogEs
(
"09876"
)
}
...
...
internal/logic/mylog.go
View file @
994aa870
package
logic
import
(
"encoding/json"
"fmt"
"io"
"os"
"time"
)
/*
{
"msg": msg, 错误信息 字符串
"msgCode": msg_code, 自定义错误码 六位数字字符串 etc "100000"
"ts": ts, 10位整形 时间戳
"dateStr": "", # 日期 2018-06-28 21:24:09 字符串
"app": "", 应用名称 字符串
"serverIp": "", 服务器ip 字符串
"fileName": "", 文件名 字符串
"lineNo": "", 行数 整形数字
"method": "", 函数名 字符串
}
*/
type
EsLogJson
struct
{
Msg
string
`json:"msg"`
Email
string
`json:"msgCode"`
Ts
int64
`json:"ts"`
DateStr
string
`json:"dateStr"`
App
string
`json:"app"`
ServerIp
string
`json:"serverIp"`
FileName
string
`json:"fileName"`
LineNo
int64
`json:"lineNo"`
Method
string
`json:"method"`
}
func
check
(
e
error
)
{
if
e
!=
nil
{
panic
(
e
)
...
...
@@ -55,9 +81,42 @@ func LogWrite(log1 string,log_pre string,is_write int) {
Loginfo
(
log1
,
log_pre
)
}
func
LogEs
(
content
string
)
{
var
esLog
EsLogJson
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
dateTime
:=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
strTotime
:=
time
.
Now
()
.
Unix
()
filename
:=
"./logs/"
+
date
+
"err.log"
esLog
.
App
=
"kaopu-server"
esLog
.
DateStr
=
dateTime
esLog
.
Email
=
""
esLog
.
FileName
=
filename
esLog
.
LineNo
=
1
esLog
.
ServerIp
=
"172.18.137.41"
esLog
.
Method
=
"easy"
esLog
.
Ts
=
strTotime
esLog
.
Msg
=
content
var
f
*
os
.
File
if
!
checkFileIsExist
(
filename
)
{
//如果文件存在
f
,
_
=
os
.
Create
(
filename
)
//创建文件
}
f
,
_
=
os
.
OpenFile
(
filename
,
os
.
O_WRONLY
|
os
.
O_APPEND
,
0666
)
writeContent
,
_
:=
json
.
Marshal
(
esLog
)
f
.
Write
([]
byte
(
"
\n
"
+
string
(
writeContent
)))
defer
f
.
Close
()
}
func
CheckErr
(
err
error
)
{
if
err
!=
nil
{
Log
info
(
err
.
Error
(),
"error"
)
Log
Es
(
err
.
Error
()
)
}
}
...
...
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