mirror of
https://github.com/mmatczuk/go-http-tunnel.git
synced 2026-05-16 14:16:16 -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:
|
Examples:
|
||||||
tunnel start www ssh
|
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
|
tunnel start-all
|
||||||
|
|
||||||
config.yaml:
|
config.yaml:
|
||||||
|
|
@ -56,7 +56,6 @@ func init() {
|
||||||
|
|
||||||
type options struct {
|
type options struct {
|
||||||
config string
|
config string
|
||||||
logTo string
|
|
||||||
logLevel int
|
logLevel int
|
||||||
version bool
|
version bool
|
||||||
command string
|
command string
|
||||||
|
|
@ -65,14 +64,12 @@ type options struct {
|
||||||
|
|
||||||
func parseArgs() (*options, error) {
|
func parseArgs() (*options, error) {
|
||||||
config := flag.String("config", "tunnel.yml", "Path to tunnel configuration file")
|
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")
|
logLevel := flag.Int("log-level", 1, "Level of messages to log, 0-3")
|
||||||
version := flag.Bool("version", false, "Prints tunnel version")
|
version := flag.Bool("version", false, "Prints tunnel version")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
opts := &options{
|
opts := &options{
|
||||||
config: *config,
|
config: *config,
|
||||||
logTo: *logTo,
|
|
||||||
logLevel: *logLevel,
|
logLevel: *logLevel,
|
||||||
version: *version,
|
version: *version,
|
||||||
command: flag.Arg(0),
|
command: flag.Arg(0),
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,7 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger, err := log.NewLogger(opts.logTo, opts.logLevel)
|
logger := log.NewFilterLogger(log.NewStdLogger(), opts.logLevel)
|
||||||
if err != nil {
|
|
||||||
fatal("failed to init logger: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// read configuration file
|
// read configuration file
|
||||||
config, err := loadClientConfigFromFile(opts.config)
|
config, err := loadClientConfigFromFile(opts.config)
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ type options struct {
|
||||||
tlsKey string
|
tlsKey string
|
||||||
rootCA string
|
rootCA string
|
||||||
clients string
|
clients string
|
||||||
logTo string
|
|
||||||
logLevel int
|
logLevel int
|
||||||
version bool
|
version bool
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +56,6 @@ func parseArgs() *options {
|
||||||
tlsKey := flag.String("tlsKey", "server.key", "Path to a TLS key file")
|
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")
|
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")
|
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")
|
logLevel := flag.Int("log-level", 1, "Level of messages to log, 0-3")
|
||||||
version := flag.Bool("version", false, "Prints tunneld version")
|
version := flag.Bool("version", false, "Prints tunneld version")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
@ -70,7 +68,6 @@ func parseArgs() *options {
|
||||||
tlsKey: *tlsKey,
|
tlsKey: *tlsKey,
|
||||||
rootCA: *rootCA,
|
rootCA: *rootCA,
|
||||||
clients: *clients,
|
clients: *clients,
|
||||||
logTo: *logTo,
|
|
||||||
logLevel: *logLevel,
|
logLevel: *logLevel,
|
||||||
version: *version,
|
version: *version,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,7 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger, err := log.NewLogger(opts.logTo, opts.logLevel)
|
logger := log.NewFilterLogger(log.NewStdLogger(), opts.logLevel)
|
||||||
if err != nil {
|
|
||||||
fatal("failed to init logger: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tlsconf, err := tlsConfig(opts)
|
tlsconf, err := tlsConfig(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
33
log/log.go
33
log/log.go
|
|
@ -4,12 +4,6 @@
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Logger is the fundamental interface for all log operations. Log creates a
|
// Logger is the fundamental interface for all log operations. Log creates a
|
||||||
// log event from keyvals, a variadic sequence of alternating keys and values.
|
// log event from keyvals, a variadic sequence of alternating keys and values.
|
||||||
// Implementations must be safe for concurrent use by multiple goroutines. In
|
// Implementations must be safe for concurrent use by multiple goroutines. In
|
||||||
|
|
@ -18,30 +12,3 @@ import (
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
Log(keyvals ...interface{}) error
|
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