//listen will listen for log messages and write them
listen will listen for log messages and write them
// listen will listen for log messages and write them
func (log *FileLog) listen() {
	logDir := filepath.Dir(log.path)
	if _, err := os.Stat(logDir); os.IsNotExist(err) {
		if err = os.MkdirAll(logDir, os.ModePerm); err != nil {
			log.err <- fmt.Errorf("could not initialize log directory: %v", err)
			return
		}
	} else if err != nil {
		log.err <- fmt.Errorf("unknown filesystem error: %v", err)
		return
	}
	file, err := os.OpenFile(log.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, os.FileMode(0664))
	if err != nil {
		log.err <- fmt.Errorf("could not open log file: %v", err)
		return
	}
	log.err <- nil
	for {
		msg, ok := <-log.io
		if !ok {
			break
		}
		if (uint8(log.level) & uint8(msg.level)) > 0 {
			fmt.Fprintf(file, LOG_FORMAT,
				time.Now().Format("2006-01-02 15:04:05"), msg.level, msg.message,
			)
		}
	}
	err = file.Close()
	if err != nil {
		log.err <- fmt.Errorf("could not close log file: %v", err)
		return
	}
	log.err <- nil
}
func ( log * FileLog ) listen ( ) { logDir := filepath . Dir ( log . path ) if _ , err := os . Stat ( logDir ) ; os . IsNotExist ( err ) { if err = os . MkdirAll ( logDir , os . ModePerm ) ; err != nil { log . err <- fmt . Errorf ( " " , err ) return } } else if err != nil { log . err <- fmt . Errorf ( " " , err ) return } file , err := os . OpenFile ( log . path , os . O_APPEND | os . O_CREATE | os . O_WRONLY , os . FileMode ( 0664 ) ) if err != nil { log . err <- fmt . Errorf ( " " , err ) return } log . err <- nil for { msg , ok := <- log . io if ! ok { break } if ( uint8 ( log . level ) & uint8 ( msg . level ) ) > 0 { fmt . Fprintf ( file , LOG_FORMAT , time . Now ( ) . Format ( " " ) , msg . level , msg . message , ) } } err = file . Close ( ) if err != nil { log . err <- fmt . Errorf ( " " , err ) return } log . err <- nil }
listen will listen for log messages and write them
listen will listen for log messages and write them