Skip to content
Michael Kenney edited this page Mar 10, 2019 · 22 revisions

bdlm/log is fully api-compatible with both the stdlib logger as well as the sirupsen/logrus package, so you can safely replace your log package imports either everywhere all at once or progressively using a strangler pattern with "github.com/bdlm/log" and add full structured logging flexibility to your service without impacting existing code.

Rotation

Log rotation is not provided with bdlm/log. Log rotation should be done by an external program (like logrotate(8)) that can compress and delete old log entries.

Thread safety

By default, Logger is protected by a mutex for concurrent writes. The mutex is held when calling hooks and writing logs. If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking.

Situations where locking is not necessary include:

  • You have no hooks registered, or hooks calling is already thread-safe.
  • Writing to logger.Out is already thread-safe, for example:
    1. logger.Out is protected by locks.

    2. logger.Out is a os.File handler opened with O_APPEND flag, and every write is smaller than 4k. This allows multi-thread/multi-process writing.

      Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/ for details.