+
+// CatchSignalShutdown return a channel.
+// that channel will get a SIG_INT or SIG_KILL signal is received
+// this is intended to be used to stop a client/server
+func CatchSignalShutdown() chan interface{} {
+ shutdownChan := make(chan interface{}, 1)
+ go func() {
+ termSignal := make(chan os.Signal, 1)
+ signal.Notify(termSignal, os.Interrupt, os.Kill)
+ sig := <-termSignal
+ logger.WithFields(logrus.Fields{
+ "func": logFuncPrefix + "CatchSignalShutdown",
+ "signal": sig.String(),
+ }).Debug("Catch signal, shutting down")
+ shutdownChan <- sig
+ }()
+ return shutdownChan
+}
+
+// SetLogger set the Logger used by this library.
+// by default logrus StdLogger is used.
+func SetLogger(l *logrus.Logger) {
+ logger = l
+}
+
+// CloseLog log an error if a io.Closer fail to Close
+func CloseLog(c io.Closer, l *logrus.Logger, fields logrus.Fields) {
+ if err := c.Close(); err != nil {
+ logrus.WithFields(fields).WithError(err).Error("Couldn't close connection")
+ }
+}