Skip to content

Commit

Permalink
添加日志记录LogFile
Browse files Browse the repository at this point in the history
  • Loading branch information
2kil committed Sep 21, 2024
1 parent 44bc5d1 commit 1a6143d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
24 changes: 21 additions & 3 deletions 2kStar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 2Kil
* @Date: 2024-04-19 10:54:20
* @LastEditors: 2Kil
* @LastEditTime: 2024-08-22 16:01:10
* @LastEditTime: 2024-09-21 23:04:07
* @Description:tktar
*/
package tkstar
Expand All @@ -16,7 +16,6 @@ import (
"encoding/base64"
"fmt"
"io"
"log"
"math/rand"
"net"
"net/http"
Expand All @@ -28,6 +27,8 @@ import (
"strings"
"sync/atomic"
"time"

log "github.com/sirupsen/logrus"
)

/**
Expand Down Expand Up @@ -318,7 +319,7 @@ func NetProxyCurl(proxy, curlBash string) (int, string) {
client = &http.Client{
Transport: transport,
}
}else{
} else {
client = &http.Client{}
}

Expand Down Expand Up @@ -387,3 +388,20 @@ func NetParseCurlComd(curlCmd string) (string, string, http.Header, []byte, erro

return method, parsedURL.String(), headers, nil, nil
}

/**
* @description: 记录日志到文件,添加引用[log "github.com/sirupsen/logrus"]
* @param {string} logFIle
* @return {*}
*/
func LogFile(logFIle string) error {
// 创建一个文件用于写入日志
logFile, err := os.OpenFile(logFIle, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Println("error opening file: %v", err)
return err
}
defer logFile.Close()
log.SetOutput(logFile)
return nil
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/2Kil/tkstar

go 1.22.2

require github.com/sirupsen/logrus v1.9.3

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 1a6143d

Please sign in to comment.