|
@@ -38,6 +38,9 @@ func NewFileWriter(opts ...Option) (*FileWriter, error) {
|
|
|
log.Fatalf("[file] create dir error: %s", err.Error())
|
|
log.Fatalf("[file] create dir error: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if p.opts.timeFormat == "" {
|
|
|
|
|
+ p.opts.timeFormat = timeFormat
|
|
|
|
|
+ }
|
|
|
var filename string
|
|
var filename string
|
|
|
var err error
|
|
var err error
|
|
|
for {
|
|
for {
|
|
@@ -84,7 +87,7 @@ func (p *FileWriter) write() {
|
|
|
|
|
|
|
|
func (p *FileWriter) checkFile() {
|
|
func (p *FileWriter) checkFile() {
|
|
|
info, _ := p.file.Stat()
|
|
info, _ := p.file.Stat()
|
|
|
- if strings.Index(p.file.Name(), time.Now().Format(timeFormat)) < 0 ||
|
|
|
|
|
|
|
+ if strings.Index(p.file.Name(), time.Now().Format(p.opts.timeFormat)) < 0 ||
|
|
|
(p.opts.cap > 0 && uint(info.Size()) > p.opts.cap) {
|
|
(p.opts.cap > 0 && uint(info.Size()) > p.opts.cap) {
|
|
|
//生成新文件
|
|
//生成新文件
|
|
|
if uint(info.Size()) > p.opts.cap {
|
|
if uint(info.Size()) > p.opts.cap {
|
|
@@ -122,12 +125,12 @@ func (p *FileWriter) getFilename() string {
|
|
|
if p.opts.cap == 0 {
|
|
if p.opts.cap == 0 {
|
|
|
return filepath.Join(p.opts.path,
|
|
return filepath.Join(p.opts.path,
|
|
|
fmt.Sprintf("%s.%s",
|
|
fmt.Sprintf("%s.%s",
|
|
|
- time.Now().Format(timeFormat),
|
|
|
|
|
|
|
+ time.Now().Format(p.opts.timeFormat),
|
|
|
p.opts.suffix))
|
|
p.opts.suffix))
|
|
|
}
|
|
}
|
|
|
return filepath.Join(p.opts.path,
|
|
return filepath.Join(p.opts.path,
|
|
|
fmt.Sprintf("%s_%d.%s",
|
|
fmt.Sprintf("%s_%d.%s",
|
|
|
- time.Now().Format(timeFormat),
|
|
|
|
|
- p.num,
|
|
|
|
|
|
|
+ time.Now().Format(p.opts.timeFormat),
|
|
|
|
|
+ p.num+1,
|
|
|
p.opts.suffix))
|
|
p.opts.suffix))
|
|
|
}
|
|
}
|