timed_file_handler.go
func (handler *TimedFileHandler) Handle(record *Record) (err error) {
	handler.lock.Lock()
	defer handler.lock.Unlock()

	if handler.FilenameLayout == "" {
		handler.FilenameLayout = "2006-01-02"
	}
	timestamp := record.Time.Format(handler.FilenameLayout)
	if handler.timestamp != timestamp || handler.file == nil {
		filename := filepath.Join(handler.Directory, timestamp)
		if handler.FileExtension != "" {

			filename += handler.FileExtension
		}
		if handler.DirectoryMode == 0 {
			handler.DirectoryMode = 0750
		}
		if err = os.MkdirAll(filepath.Dir(filename), handler.DirectoryMode); err != nil {
			return err
		}
		if handler.FileMode == 0 {
			handler.FileMode = 0640
		}
		handler.file, err = os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, handler.FileMode)
		if err != nil {
			return err
		}
	}

	msg := handler.Formatter.Format(record) + "\n"

	_, err = handler.file.Write([]byte(msg))
	return
}
func (handler *TimedFileHandler) Handle(record *Record) (err error) {
	handler.lock.Lock()
	defer handler.lock.Unlock()

	if handler.FilenameLayout == "" {
		handler.FilenameLayout = "2006-01-02"
	}
	timestamp := record.Time.Format(handler.FilenameLayout)
	if handler.timestamp != timestamp || handler.file == nil {
		filename := filepath.Join(handler.Directory, timestamp)
		if handler.FileExtension != "" {

			filename += handler.FileExtension
		}
		if handler.DirectoryMode == 0 {
			handler.DirectoryMode = 0750
		}
		if err = os.MkdirAll(filepath.Dir(filename), handler.DirectoryMode); err != nil {
			return err
		}
		if handler.FileMode == 0 {
			handler.FileMode = 0640
		}
		handler.file, err = os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, handler.FileMode)
		if err != nil {
			return err
		}
	}

	msg := handler.Formatter.Format(record) + "\n"

	_, err = handler.file.Write([]byte(msg))
	return
}
// Handle writes message from log record into file.