mirror of
https://github.com/mmatczuk/go-http-tunnel.git
synced 2026-05-15 06:06:03 -06:00
log: removal of log-to flags
This commit is contained in:
parent
0a860143c2
commit
1debf52fed
5 changed files with 3 additions and 48 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
log/log.go
33
log/log.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue