Skip to content

Commit

Permalink
log: removal of log-to flags
Browse files Browse the repository at this point in the history
mmatczuk committed Nov 28, 2017
1 parent 0a86014 commit 1debf52
Showing 5 changed files with 3 additions and 48 deletions.
5 changes: 1 addition & 4 deletions cmd/tunnel/options.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ Commands:
Examples:
tunnel start www ssh
tunnel -config config.yaml -log stdout -log-level 2 start ssh
tunnel -config config.yaml -log-level 2 start ssh
tunnel start-all
config.yaml:
@@ -56,7 +56,6 @@ func init() {

type options struct {
config string
logTo string
logLevel int
version bool
command string
@@ -65,14 +64,12 @@ type options struct {

func parseArgs() (*options, error) {
config := flag.String("config", "tunnel.yml", "Path to tunnel configuration file")
logTo := flag.String("log", "stdout", "Write log messages to this file, file name or 'stdout', 'stderr', 'none'")
logLevel := flag.Int("log-level", 1, "Level of messages to log, 0-3")
version := flag.Bool("version", false, "Prints tunnel version")
flag.Parse()

opts := &options{
config: *config,
logTo: *logTo,
logLevel: *logLevel,
version: *version,
command: flag.Arg(0),
5 changes: 1 addition & 4 deletions cmd/tunnel/tunnel.go
Original file line number Diff line number Diff line change
@@ -34,10 +34,7 @@ func main() {
return
}

logger, err := log.NewLogger(opts.logTo, opts.logLevel)
if err != nil {
fatal("failed to init logger: %s", err)
}
logger := log.NewFilterLogger(log.NewStdLogger(), opts.logLevel)

// read configuration file
config, err := loadClientConfigFromFile(opts.config)
3 changes: 0 additions & 3 deletions cmd/tunneld/options.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ type options struct {
tlsKey string
rootCA string
clients string
logTo string
logLevel int
version bool
}
@@ -57,7 +56,6 @@ func parseArgs() *options {
tlsKey := flag.String("tlsKey", "server.key", "Path to a TLS key file")
rootCA := flag.String("rootCA", "", "Path to the trusted certificate chian used for client certificate authentication, if empty do not authenticate clients")
clients := flag.String("clients", "", "Comma-separated list of tunnel client ids, if empty accept all clients")
logTo := flag.String("log", "stdout", "Write log messages to this file, file name or 'stdout', 'stderr', 'none'")
logLevel := flag.Int("log-level", 1, "Level of messages to log, 0-3")
version := flag.Bool("version", false, "Prints tunneld version")
flag.Parse()
@@ -70,7 +68,6 @@ func parseArgs() *options {
tlsKey: *tlsKey,
rootCA: *rootCA,
clients: *clients,
logTo: *logTo,
logLevel: *logLevel,
version: *version,
}
5 changes: 1 addition & 4 deletions cmd/tunneld/tunneld.go
Original file line number Diff line number Diff line change
@@ -28,10 +28,7 @@ func main() {
return
}

logger, err := log.NewLogger(opts.logTo, opts.logLevel)
if err != nil {
fatal("failed to init logger: %s", err)
}
logger := log.NewFilterLogger(log.NewStdLogger(), opts.logLevel)

tlsconf, err := tlsConfig(opts)
if err != nil {
33 changes: 0 additions & 33 deletions log/log.go
Original file line number Diff line number Diff line change
@@ -4,12 +4,6 @@

package log

import (
"io"
"log"
"os"
)

// Logger is the fundamental interface for all log operations. Log creates a
// log event from keyvals, a variadic sequence of alternating keys and values.
// Implementations must be safe for concurrent use by multiple goroutines. In
@@ -18,30 +12,3 @@ import (
type Logger interface {
Log(keyvals ...interface{}) error
}

// NewLogger returns logfmt based logger, printing messages up to log level
// logLevel.
func NewLogger(to string, level int) (Logger, error) {
var w io.Writer

switch to {
case "none":
return NewNopLogger(), nil
case "stdout":
w = os.Stdout
case "stderr":
w = os.Stderr
default:
f, err := os.Create(to)
if err != nil {
return nil, err
}
w = f
}

log.SetOutput(w)

l := NewStdLogger()
l = NewFilterLogger(l, level)
return l, nil
}

0 comments on commit 1debf52

Please sign in to comment.