add FN_LOG_DEST for logs, fixup init (#663)

* add FN_LOG_DEST for logs, fixup init

* FN_LOG_DEST can point to a remote logging place (papertrail, whatever)
* FN_LOG_PREFIX can add a prefix onto each log line sent to FN_LOG_DEST

default remains stderr with no prefix. users need this to send to various
logging backends, though it could be done operationally, this is somewhat
simpler.

we were doing some configuration stuff inside of init() for some of the global
things. even though they're global, it's nice to keep them all in the normal
server init path.

we have had strange issues with the tracing setup, I tested the last repro of
this repeatedly and didn't have any luck reproducing it, though maybe it comes
back.

* add docs
This commit is contained in:
Reed Allman
2018-01-09 14:27:50 -08:00
committed by GitHub
parent 5fe2fa1aee
commit 24aa911609
4 changed files with 79 additions and 57 deletions

View File

@@ -6,26 +6,13 @@ import (
"os/signal"
"strconv"
"github.com/fnproject/fn/api/common"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func init() {
logLevel, err := logrus.ParseLevel(getEnv(EnvLogLevel, DefaultLogLevel))
if err != nil {
logrus.WithError(err).Fatalln("Invalid log level.")
}
logrus.SetLevel(logLevel)
// gin is not nice by default, this can get set in logging initialization
gin.SetMode(gin.ReleaseMode)
if logLevel == logrus.DebugLevel {
gin.SetMode(gin.DebugMode)
}
// do this in init so that it's only run once & before server.New() which may
// start things that use spans, which are global.
// TODO there's not a great reason that our fn spans don't work w/ noop spans, should fix this really.
setupTracer(getEnv(EnvZipkinURL, ""))
}
func getEnv(key, fallback string) string {
@@ -56,11 +43,11 @@ func contextWithSignal(ctx context.Context, signals ...os.Signal) (context.Conte
for {
select {
case <-c:
logrus.Info("Halting...")
common.Logger(ctx).Info("Halting...")
halt()
return
case <-ctx.Done():
logrus.Info("Halting... Original server context canceled.")
common.Logger(ctx).Info("Halting... Original server context canceled.")
halt()
return
}