Documentation ¶
Overview ¶
Package file implements a file writer which implements the Writer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockCipherMode ¶ added in v0.5.0
type BlockCipherMode int
The BlockCipherMode defines the type of block mode of AES.
const ( CFB BlockCipherMode = iota CTR OFB )
All available block modes here.
type Config ¶
type Config struct { // Path is the location to where logs output. // Shell expansion is NOT supported. // When it is modified in a file writer, a new log file will be created. // If Path is not specified, "." is used. Path string // Base is the first segment of the name of log files. // When it is modified in a file writer, a new log file will be created. // If Base is not specified, filepath.Base(os.Args[0]).<pid> is used. Base string // Ext is the extension name of log files. // When it is modified in a file writer, a new log file will be created. // If Ext is not specified, ".log" is used. Ext string // Separator is the segment separator of name of log files. // When it is modified in a file writer, a new log file will be created. // If Separator is not specified, "." is used. Separator string // DateStyle is the date format style for naming log files. // When it is modified in a file writer, a new log file will be created. // If DateStyle is not specified, DateCompact is used. DateStyle DateStyle // TimeStyle is the time format style for naming log files. // When it is modified in a file writer, a new log file will be created. // If TimeStyle is not specified, TimeCompact is used. TimeStyle TimeStyle // MaxFileSize is the max size of a log file BEFORE compression because // (*gzip.Writer).Write returns the count of bytes before compression. // If MaxFileSize is not specified, (20 * 1024 * 1024) is used. // It must NOT be negative. MaxFileSize int64 // CheckInterval is the time interval to check whether the current log file // still exists. If not, a new log file will be created. // It is useful when you want to remove all log files and do not want to // restart the process. // If CheckInterval is not specified, (time.Second * 5) is used. // For performance, it is better NOT to be less than 1s. CheckInterval time.Duration // GzipLevel is the level of gzip of log files. It will be handled by package // compress/gzip. It MUST be flate.DefaultCompression, flate.NoCompression, // flate.HuffmanOnly or any integer value between flate.BestSpeed and // flate.BestCompression inclusive. // When it is modified in a file writer, a new log file will be created. // If GzipLevel is not specified, flate.NoCompression is used. GzipLevel int // AESKey is a hexadecimal encoded AES key. It MUST be either empty, 128 bits, // 192 bits or 256 bits, e.g. 70856575b161fbcca8fc12e1f70fc1c8. // If it is not empty, the AES encryption is enabled. Each log file will have // an independent initialization vector. // When it is modified in a file writer, a new log file will be created. AESKey string // BlockMode is the block mode of AES. It MUST be either CFB, CTR or OFB. // When it is modified in a file writer, a new log file will be created. // If BlockMode is not specified, CFB is used. BlockMode BlockCipherMode // ErrorHandler will be called when an error occurs if it is not nil. ErrorHandler writer.ErrorHandler // DirPerm represents the permission bits of created directories. // If DirPerm is not specified, 0700 is used. DirPerm os.FileMode // NoDirForDays specifies NOT to create a new directory each day. // If NoDirForDays is true, the pattern of name of log files is // <base><sep><date><sep><time><ext>, otherwise it is <base><sep><time><ext>. // When it is modified in a file writer, a new log file will be created. NoDirForDays bool }
A Config is used to configure a file writer.
type DateStyle ¶ added in v0.5.0
type DateStyle int
The DateStyle defines the type of date format style for naming log files.
type TimeStyle ¶ added in v0.5.0
type TimeStyle int
The TimeStyle defines the type of time format style for naming log files.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer implements the interface iface.Writer.
All methods of a Writer are concurrency safe. A Writer MUST be created with Open.
func (*Writer) SetConfig ¶ added in v0.3.0
SetConfig sets the config to the Writer. If the config is invalid, it returns an error and the Config of the Writer is left to be unchanged.
func (*Writer) UpdateConfig ¶ added in v0.3.0
UpdateConfig calls the fn with the Config of the Writer, and then sets the returned config to the Writer. The fn must NOT be nil. If the returned config is invalid, it returns an error and the Config of the Writer is left to be unchanged.
Do NOT call any method of the Writer or the Logger within the fn, or it may deadlock.