Skip to content

Commit

Permalink
slog: simplify lf handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hexian000 committed Oct 15, 2023
1 parent 4a68e47 commit 723190d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/hexian000/tlswrapper)](https://goreportcard.com/report/github.com/hexian000/tlswrapper)
[![Release](https://img.shields.io/github/release/hexian000/tlswrapper.svg?style=flat)](https://github.com/hexian000/tlswrapper/releases)

Wrap any TCP-based service with multiplexed mutual TLS tunnels.

Status: **Stable**

- [Features](#features)
- [Protocol Stack](#protocol-stack)
- [Authentication Model](#authentication-model)
Expand All @@ -20,8 +24,6 @@

## Features

Wrap any TCP-based service with multiplexed mutual TLS tunnels.

- Multiplexed: All traffic goes over one TCP connection.
- Secured: All traffic is optionally protected by mutual authenticated TLS.
- Mutual Forwarded: Each peer can listen and connect to the other peer simultaneously over the same underlying connection.
Expand Down
2 changes: 1 addition & 1 deletion cmd/tlswrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
slog.Fatal("logging:", err)
os.Exit(1)
}
slog.Debugf("runtime: %s\n", runtime.Version())
slog.Debugf("runtime: %s", runtime.Version())
slog.Info("config:", path)
server := tlswrapper.NewServer(cfg)
if err := server.LoadConfig(cfg); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions slog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,47 @@ func Default() *Logger {
}

func Verbose(v ...interface{}) {
std.Output(2, LevelVerbose, []byte(fmt.Sprintln(v...)))
std.Output(2, LevelVerbose, []byte(fmt.Sprint(v...)))
}

func Verbosef(format string, v ...interface{}) {
std.Output(2, LevelVerbose, []byte(fmt.Sprintf(format, v...)))
}

func Debug(v ...interface{}) {
std.Output(2, LevelDebug, []byte(fmt.Sprintln(v...)))
std.Output(2, LevelDebug, []byte(fmt.Sprint(v...)))
}

func Debugf(format string, v ...interface{}) {
std.Output(2, LevelDebug, []byte(fmt.Sprintf(format, v...)))
}

func Info(v ...interface{}) {
std.Output(2, LevelInfo, []byte(fmt.Sprintln(v...)))
std.Output(2, LevelInfo, []byte(fmt.Sprint(v...)))
}

func Infof(format string, v ...interface{}) {
std.Output(2, LevelInfo, []byte(fmt.Sprintf(format, v...)))
}

func Warning(v ...interface{}) {
std.Output(2, LevelWarning, []byte(fmt.Sprintln(v...)))
std.Output(2, LevelWarning, []byte(fmt.Sprint(v...)))
}

func Warningf(format string, v ...interface{}) {
std.Output(2, LevelWarning, []byte(fmt.Sprintf(format, v...)))
}

func Error(v ...interface{}) {
std.Output(2, LevelError, []byte(fmt.Sprintln(v...)))
std.Output(2, LevelError, []byte(fmt.Sprint(v...)))
}

func Errorf(format string, v ...interface{}) {
std.Output(2, LevelError, []byte(fmt.Sprintf(format, v...)))
}

func Fatal(v ...interface{}) {
std.Output(2, LevelFatal, []byte(fmt.Sprintln(v...)))
std.Output(2, LevelFatal, []byte(fmt.Sprint(v...)))
}

func Fatalf(format string, v ...interface{}) {
Expand Down
12 changes: 6 additions & 6 deletions slog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,47 +78,47 @@ func (l *Logger) SetOutput(w io.Writer) {
}

func (l *Logger) Verbose(v ...interface{}) {
l.Output(2, LevelVerbose, []byte(fmt.Sprintln(v...)))
l.Output(2, LevelVerbose, []byte(fmt.Sprint(v...)))
}

func (l *Logger) Verbosef(format string, v ...interface{}) {
l.Output(2, LevelVerbose, []byte(fmt.Sprintf(format, v...)))
}

func (l *Logger) Debug(v ...interface{}) {
l.Output(2, LevelDebug, []byte(fmt.Sprintln(v...)))
l.Output(2, LevelDebug, []byte(fmt.Sprint(v...)))
}

func (l *Logger) Debugf(format string, v ...interface{}) {
l.Output(2, LevelDebug, []byte(fmt.Sprintf(format, v...)))
}

func (l *Logger) Info(v ...interface{}) {
l.Output(2, LevelInfo, []byte(fmt.Sprintln(v...)))
l.Output(2, LevelInfo, []byte(fmt.Sprint(v...)))
}

func (l *Logger) Infof(format string, v ...interface{}) {
l.Output(2, LevelInfo, []byte(fmt.Sprintf(format, v...)))
}

func (l *Logger) Warning(v ...interface{}) {
l.Output(2, LevelWarning, []byte(fmt.Sprintln(v...)))
l.Output(2, LevelWarning, []byte(fmt.Sprint(v...)))
}

func (l *Logger) Warningf(format string, v ...interface{}) {
l.Output(2, LevelWarning, []byte(fmt.Sprintf(format, v...)))
}

func (l *Logger) Error(v ...interface{}) {
l.Output(2, LevelError, []byte(fmt.Sprintln(v...)))
l.Output(2, LevelError, []byte(fmt.Sprint(v...)))
}

func (l *Logger) Errorf(format string, v ...interface{}) {
l.Output(2, LevelError, []byte(fmt.Sprintf(format, v...)))
}

func (l *Logger) Fatal(v ...interface{}) {
l.Output(2, LevelFatal, []byte(fmt.Sprintln(v...)))
l.Output(2, LevelFatal, []byte(fmt.Sprint(v...)))
}

func (l *Logger) Fatalf(format string, v ...interface{}) {
Expand Down
4 changes: 1 addition & 3 deletions slog/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ func (l *lineOutput) Write(m logMessage) {
buf = strconv.AppendInt(buf, int64(m.line), 10)
buf = append(buf, ' ')
buf = append(buf, m.msg...)
if len(m.msg) == 0 || m.msg[len(m.msg)-1] != '\n' {
buf = append(buf, '\n')
}
buf = append(buf, '\n')
l.buf = buf
_, _ = l.out.Write(buf)
}
3 changes: 0 additions & 3 deletions slog/output_syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func (s *syslogOutput) Write(m logMessage) {
buf = strconv.AppendInt(buf, int64(m.line), 10)
buf = append(buf, ' ')
buf = append(buf, m.msg...)
if len(m.msg) == 0 || m.msg[len(m.msg)-1] != '\n' {
buf = append(buf, '\n')
}
s.buf = buf
s.out.Write(buf)
}

0 comments on commit 723190d

Please sign in to comment.