title: Rotate log file in golang with systemd
body: <p>Was using default log from go but found two issues, which are log rotation and log wasn't being printed when run the program using systemd. 
  So I tried using libraries as follows:</p>
  
  <pre><code>https://github.com/alecthomas/log4go
  https://github.com/natefinch/lumberjack
  </code></pre>
  
  <p><strong>log4go</strong></p>
  
  <p>Seems a perfect library for logging because provides max size and line for rotation. However when set rotate to true, it did create new log file but with error then the app terminated.</p>
  
  <blockquote>
    <p>FileLogWriter("logs/app.log"): Rotate: rename logs/stream.log
    logs/app.log.2017-05-21.001: The process cannot access the file
    because it is being used by another process.</p>
  </blockquote>
  
  <p>Configurations:</p>
  
  <pre><code>logger:=log4go.NewDefaultLogger(log4go.DEBUG)
  logger.AddFilter("log", log4go.FINE,  log4go.NewFileLogWriter("/log/app.log", true))
  logger.Info("success")
  </code></pre>
  
  <p>Also modified existing library and set daily to true so when rotate it shows date on the file</p>
  
  <p><strong>lumberjack</strong></p>
  
  <p>Next I tried this library. Was happy to find because there's nothing much to do but add struct log configuration. Worked well as the log file didn't go any bigger that the param specify, but there's no sign of new file created. Configuration</p>
  
  <pre><code>var PrintLog *log.Logger
  
  func main() {
      _ = os.Mkdir(property.AppProperties.Logging.Path, os.ModePerm)
      f, e := os.OpenFile(logFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
      if e != nil {
          fmt.Printf("error opening file: %v", e)
      }
      PrintLog = log.New(f, "", log.Ldate|log.Ltime)
      l:= &amp;lumberjack.Logger{
          Filename:   logFile,
          MaxSize:    2, // megabytes
          MaxBackups: 3,
          MaxAge:     20, //days
      }
      log.SetOutput(l)
  
  }
  </code></pre>
  
  <p>Where am I missing?</p>