GoWorkers如何将日志存储到文件中

How can I store the logs which are coming from GoWorkers (docs) into a file. I show that there is a WorkersLogger interface but I don't understand how to use it.

At the moment I have this:

func main() {
  workers.Configure(map[string]string)
  workers.Middleware.Append(&midRetry{})
  workers.Process("imp", worker.InitJob, 30)
  workers.Run()
}

type midRetry struct{}
func (r *midRetry) Call(queue string, message *workers.Msg, next func() bool) (acknowledge bool) {
  acknowledge = next()
  return
}

I was thinking in creating a chan string in the midRetry struct, and inside Call send messages on the channel, and receive them in main, and then write them to file, but I feel that there is a better way.

The WorkerLogger interface is just an interface for a struct that implements the Println and Printf methods.

You can simply define a new log.Logger, give it an os.File as output (see the constructor), and set the global var workers.Logger to this new logger.

Example:

file, _ := os.Create("log.txt")
workers.Logger = log.New(file, "[worker] ", log.LstdFlags)