Open dequanLi opened 4 years ago
Now,the backup file name is generated by the following function,the format only be “name-timestamp-ext”, but i need other format,Such as “name-ext-timestamp”.How should i do?
func backupName(name string, local bool) string { dir := filepath.Dir(name) filename := filepath.Base(name) ext := filepath.Ext(filename) prefix := filename[:len(filename)-len(ext)] t := currentTime() if !local { t = t.UTC() } timestamp := t.Format(backupTimeFormat) return filepath.Join(dir, fmt.Sprintf("%s-%s%s", prefix, timestamp, ext)) }
me too
At least make the timestamp configurable please. :)
At least make the timestamp configurable please. :)
The problem with making it configurable is that it is too easy to screw up in non-obvious ways. The timestamp is what makes the backup files unique, and it is how lumberjack figures out when a file was created (granted this last part could just use the os timestamp).
Really, there's no reason why anyone should care what the timestamp looks like. It's just a backup file.
Hi, @natefinch. Thanks for reply.
The problem with making it configurable is that it is too easy to screw up in non-obvious ways. The timestamp is what makes the backup files unique, and it is how lumberjack figures out when a file was created (granted this last part could just use the os timestamp).
Yeah, you are right. Some things might be confused for some developers. But I'm pretty sure that every developer must understand what his doing.
Really, there's no reason why anyone should care what the timestamp looks like. It's just a backup file.
In my case I have a script that pushes archived logs to my own storage data. On my side it is not just backup file and I really need make name of archive file is configurable. Because I have many logs from many services and I want to have one format for logs and archived file.
If TimeFormat
was added finally, the rotate logic should base on file ture
modified time nor time field of filename. https://github.com/natefinch/lumberjack/blob/v2.0/lumberjack.go#L400
Because if user change time format in a new application version (e.g. "2020-11-27" to "Nov-11-2020"), the rotate will be buggy. my phuslu/log was reported by this issue and fixed it just now
@natefinch For collecting the current log to a remote storage, we want the current and backups have different ext. Currently, turn on compress is the only way, so customization is wanted.
Now,the backup file name is generated by the following function,the format only be “name-timestamp-ext”, but i need other format,Such as “name-ext-timestamp”.How should i do?
func backupName(name string, local bool) string { dir := filepath.Dir(name) filename := filepath.Base(name) ext := filepath.Ext(filename) prefix := filename[:len(filename)-len(ext)] t := currentTime() if !local { t = t.UTC() } timestamp := t.Format(backupTimeFormat) return filepath.Join(dir, fmt.Sprintf("%s-%s%s", prefix, timestamp, ext)) }
i also has the requierment for self define the bakcup file name.
if the TZ was just aded to the BACK, and not the ext moved, it would've solved other problems.
Now,the backup file name is generated by the following function,the format only be “name-timestamp-ext”, but i need other format,Such as “name-ext-timestamp”.How should i do?