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
ddce21d2
authored
Nov 27, 2019
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
592de3c0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
3 deletions
cmd/dong/main.go
internal/logic/mylog.go
cmd/dong/main.go
View file @
ddce21d2
...
...
@@ -6,13 +6,14 @@ import (
"kaopu-server/internal/service"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/logic"
"time"
"fmt"
"os"
)
func
main
()
{
logic
.
Loginfo
(
"逾期统计开始"
,
"_yuqilv_"
);
//获取输入参数
var
mod
int
;
...
...
@@ -54,11 +55,10 @@ func main() {
}
//初始化日志目录
log
.
Init
(
&
log
.
Config
{
Dir
:
"logs"
})
log
.
Init
(
&
log
.
Config
{
Dir
:
"logs
/
"
})
defer
log
.
Close
()
log
.
Info
(
"caipu-server start"
)
}
internal/logic/mylog.go
0 → 100644
View file @
ddce21d2
package
logic
import
(
"io"
"os"
"time"
)
func
check
(
e
error
)
{
if
e
!=
nil
{
panic
(
e
)
}
}
/**
* 判断文件是否存在 存在返回 true 不存在返回false
*/
func
checkFileIsExist
(
filename
string
)
bool
{
var
exist
=
true
if
_
,
err
:=
os
.
Stat
(
filename
);
os
.
IsNotExist
(
err
)
{
exist
=
false
}
return
exist
}
/*
@param writeString 写入文件字符串
@param file_pre 附加文件前缀
eg: logic.Loginfo("逾期统计开始","_yuqilv_");
*/
func
Loginfo
(
writeString
string
,
file_pre
string
)
{
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
date2
:=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
var
filename
=
"./logs/"
+
date
+
file_pre
+
".txt"
var
f
*
os
.
File
var
err1
error
if
checkFileIsExist
(
filename
)
{
//如果文件存在
f
,
err1
=
os
.
OpenFile
(
filename
,
os
.
O_APPEND
,
0666
)
//打开文件
}
else
{
f
,
err1
=
os
.
Create
(
filename
)
//创建文件
}
check
(
err1
)
io
.
WriteString
(
f
,
"
\r\n
---"
+
date2
+
"----"
+
writeString
)
//写入文件(字符串)
}
/**
from: http://www.isharey.com/?p=143
*/
//
//func main() {
//
// var wireteString = "测试n"
// var filename = "./output1.txt"
//
// fmt.Print(filename)
//
//
// var f *os.File
// var err1 error
// /***************************** 第一种方式: 使用 io.WriteString 写入文件 ***********************************************/
// if checkFileIsExist(filename) { //如果文件存在
// f, err1 = os.OpenFile(filename, os.O_APPEND, 0666) //打开文件
// fmt.Println("文件存在")
// } else {
// f, err1 = os.Create(filename) //创建文件
// fmt.Println("文件不存在")
// }
// check(err1)
// n, err1 := io.WriteString(f, wireteString) //写入文件(字符串)
// check(err1)
// fmt.Printf("写入 %d 个字节n", n)
//
// /***************************** 第二种方式: 使用 ioutil.WriteFile 写入文件 ***********************************************/
// var d1 = []byte(wireteString)
// err2 := ioutil.WriteFile("./output2.txt", d1, 0666) //写入文件(字节数组)
// check(err2)
//
// /***************************** 第三种方式: 使用 File(Write,WriteString) 写入文件 ***********************************************/
// f, err3 := os.Create("./output3.txt") //创建文件
// check(err3)
// defer f.Close()
// n2, err3 := f.Write(d1) //写入文件(字节数组)
// check(err3)
// fmt.Printf("写入 %d 个字节n", n2)
// n3, err3 := f.WriteString("writesn") //写入文件(字节数组)
// fmt.Printf("写入 %d 个字节n", n3)
// f.Sync()
//
// /***************************** 第四种方式: 使用 bufio.NewWriter 写入文件 ***********************************************/
// w := bufio.NewWriter(f) //创建新的 Writer 对象
// n4, err3 := w.WriteString("bufferedn")
// fmt.Printf("写入 %d 个字节n", n4)
// w.Flush()
// f.Close()
//}
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