forked from jiang4920/jd_seckill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ | |
/cookie.txt | ||
*.bak | ||
go.sum | ||
/同步代码.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package log | ||
|
||
import ( | ||
"github.com/gookit/color" | ||
"io" | ||
"log" | ||
"os" | ||
"time" | ||
) | ||
|
||
//重写log标准库,需要多少个方法就加多少个 | ||
|
||
var file = "./logs/jd_seckill_" + time.Now().Format("20060102") + ".log" | ||
|
||
//将日志同时输出到控制台和文件 | ||
func Println(v ...interface{}) { | ||
logFile, logErr := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) | ||
if logErr != nil { | ||
panic(logErr) | ||
} | ||
defer logFile.Close() | ||
mw := io.MultiWriter(os.Stdout, logFile) | ||
log.SetOutput(mw) | ||
//log.SetPrefix("[jd_seckill]") | ||
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds) | ||
log.Println(v...) | ||
} | ||
|
||
//将日志同时输出到控制台和文件 | ||
func ColorPrintln(color2 color.Color, v ...interface{}) { | ||
logFile, logErr := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) | ||
if logErr != nil { | ||
panic(logErr) | ||
} | ||
defer logFile.Close() | ||
log.SetOutput(logFile) | ||
//log.SetPrefix("[jd_seckill]") | ||
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds) | ||
log.Println(v...) | ||
color2.Light().Println(v...) | ||
} | ||
|
||
func Fatal(v ...interface{}) { | ||
log.Fatal(v...) | ||
} | ||
|
||
func Printf(format string, v ...interface{}) { | ||
log.Printf(format, v...) | ||
} | ||
|
||
func Success(v ...interface{}) { | ||
ColorPrintln(color.Green, v...) | ||
} | ||
|
||
func Info(v ...interface{}) { | ||
ColorPrintln(color.LightCyan, v...) | ||
} | ||
|
||
func Warning(v ...interface{}) { | ||
ColorPrintln(color.Yellow, v...) | ||
} | ||
|
||
func Error(v ...interface{}) { | ||
ColorPrintln(color.FgLightRed, v...) | ||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters