-
Notifications
You must be signed in to change notification settings - Fork 5
Home
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.
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.
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:-
logger.Out
is protected by locks. -
logger.Out
is a os.File handler opened withO_APPEND
flag, and every write is smaller than4k
. This allows multi-thread/multi-process writing.Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/ for details.
-
Which one will reach the other side of the river: The one who dreams of a raft, or the one that hitchhikes to the next bridge?