AUTH-2810 added warn for backwards compatibility sake

This commit is contained in:
Dalton 2020-06-12 11:20:36 -05:00 committed by Adam Chalmers
parent acb7d604fd
commit 55acf7283c
6 changed files with 24 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import (
"strings"
"github.com/cloudflare/cloudflared/carrier"
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
"github.com/cloudflare/cloudflared/h2mux"
"github.com/cloudflare/cloudflared/logger"
@ -67,7 +68,7 @@ func ssh(c *cli.Context) error {
logger, err := logger.New(logger.DefaultFile(logDirectory), logger.LogLevelString(logLevel))
if err != nil {
return errors.Wrap(err, "error setting up logger")
return cliutil.PrintLoggerSetupError("error setting up logger", err)
}
// get the hostname from the cmdline and error out if its not provided

View File

@ -2,8 +2,10 @@ package cliutil
import (
"fmt"
"log"
"github.com/cloudflare/cloudflared/logger"
"github.com/pkg/errors"
"gopkg.in/urfave/cli.v2"
)
@ -39,3 +41,15 @@ func ErrorHandler(actionFunc cli.ActionFunc) cli.ActionFunc {
return err
}
}
// PrintLoggerSetupError returns an error to stdout to notify when a logger can't start
func PrintLoggerSetupError(msg string, err error) error {
l, le := logger.New()
if le != nil {
log.Printf("%s: %s", msg, err)
} else {
l.Errorf("%s: %s", msg, err)
}
return errors.Wrap(err, msg)
}

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/cloudflare/cloudflared/cmd/cloudflared/access"
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
"github.com/cloudflare/cloudflared/cmd/cloudflared/tunnel"
"github.com/cloudflare/cloudflared/cmd/cloudflared/updater"
@ -165,16 +166,15 @@ func handleError(err error) {
// cloudflared was started without any flags
func handleServiceMode(shutdownC chan struct{}) error {
defer log.SharedWriteManager.Shutdown()
logDirectory, logLevel := config.FindLogSettings()
logger, err := log.New(log.DefaultFile(logDirectory), log.LogLevelString(logLevel))
if err != nil {
return errors.Wrap(err, "error setting up logger")
return cliutil.PrintLoggerSetupError("error setting up logger", err)
}
logger.Infof("logging to directory: %s", logDirectory)
defer log.SharedWriteManager.Shutdown()
// start the main run loop that reads from the config file
f, err := watcher.NewFile()
if err != nil {

View File

@ -235,7 +235,7 @@ func createLogger(c *cli.Context, isTransport bool) (logger.Service, error) {
func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan struct{}) error {
logger, err := createLogger(c, false)
if err != nil {
return errors.Wrap(err, "error setting up logger")
return cliutil.PrintLoggerSetupError("error setting up logger", err)
}
_ = raven.SetDSN(sentryDSN)
@ -478,7 +478,7 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
func Before(c *cli.Context) error {
logger, err := createLogger(c, false)
if err != nil {
return errors.Wrap(err, "error setting up logger")
return cliutil.PrintLoggerSetupError("error setting up logger", err)
}
if c.String("config") == "" {

View File

@ -141,7 +141,7 @@ func ParseLevelString(lvl string) ([]Level, error) {
return []Level{FatalLevel}, nil
case "error":
return []Level{FatalLevel, ErrorLevel}, nil
case "info":
case "info", "warn":
return []Level{FatalLevel, ErrorLevel, InfoLevel}, nil
case "debug":
return []Level{FatalLevel, ErrorLevel, InfoLevel, DebugLevel}, nil

View File

@ -8,6 +8,7 @@ import (
"sync"
"syscall"
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
"github.com/cloudflare/cloudflared/logger"
"github.com/cloudflare/cloudflared/metrics"
@ -31,7 +32,7 @@ func Run(c *cli.Context) error {
logDirectory, logLevel := config.FindLogSettings()
logger, err := logger.New(logger.DefaultFile(logDirectory), logger.LogLevelString(logLevel))
if err != nil {
return errors.Wrap(err, "error setting up logger")
return cliutil.PrintLoggerSetupError("error setting up logger", err)
}
metricsListener, err := net.Listen("tcp", c.String("metrics"))