summaryrefslogtreecommitdiff
path: root/internal/io
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-28 09:49:10 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-28 09:49:10 +0000
commita5a91623ee60f33dafc16e1752f3fb1f6798ee76 (patch)
treec6433ef4a3415cc7206b5fbe733c0539d0e5a60f /internal/io
parentae8ffc84331ca72f0d33fff69edd85d6e03d29ae (diff)
parent495e9f38220a6d448b15882a235e7a9c21f21d18 (diff)
merge
Diffstat (limited to 'internal/io')
-rw-r--r--internal/io/fs/permissions/permission_linux.go2
-rw-r--r--internal/io/line/line.go6
-rw-r--r--internal/io/logger/logger.go24
-rw-r--r--internal/io/logger/modes.go1
-rw-r--r--internal/io/prompt/prompt.go6
-rw-r--r--internal/io/signal/signal.go29
6 files changed, 42 insertions, 26 deletions
diff --git a/internal/io/fs/permissions/permission_linux.go b/internal/io/fs/permissions/permission_linux.go
index feae729..bbc039b 100644
--- a/internal/io/fs/permissions/permission_linux.go
+++ b/internal/io/fs/permissions/permission_linux.go
@@ -11,7 +11,7 @@ import (
"unsafe"
)
-// To check whether user has Linux file system permissions to read a given file.
+// ToRead checks whether user has Linux file system permissions to read a given file.
func ToRead(user, filePath string) (bool, error) {
cUser := C.CString(user)
cFilePath := C.CString(filePath)
diff --git a/internal/io/line/line.go b/internal/io/line/line.go
index 9db93c0..715be34 100644
--- a/internal/io/line/line.go
+++ b/internal/io/line/line.go
@@ -15,7 +15,11 @@ type Line struct {
// lines if that happens but it will signal to the client how
// many log lines in % could be transmitted to the client.
TransmittedPerc int
- SourceID string
+ // Contains the unique identifier of the source log file.
+ // It could be the name of the log or it could be one of the parent
+ // directories in case multiple log files with the same basename are
+ // followed.
+ SourceID string
}
// Return a human readable representation of the followed line.
diff --git a/internal/io/logger/logger.go b/internal/io/logger/logger.go
index b7db0a7..4254eef 100644
--- a/internal/io/logger/logger.go
+++ b/internal/io/logger/logger.go
@@ -72,12 +72,15 @@ type buf struct {
func Start(ctx context.Context, mode Modes) {
Mode = mode
- if Mode.Nothing {
+ switch {
+ case Mode.Nothing:
return
- }
-
- if Mode.Trace {
+ case Mode.Quiet:
+ Mode.Trace = false
+ Mode.Debug = false
+ case Mode.Trace:
Mode.Debug = true
+ default:
}
strategy := logStrategy()
@@ -87,7 +90,7 @@ func Start(ctx context.Context, mode Modes) {
case DailyStrategy:
_, err := os.Stat(config.Common.LogDir)
Mode.logToFile = !os.IsNotExist(err)
- Mode.logToStdout = !Mode.Server || Mode.Debug || Mode.Trace
+ Mode.logToStdout = !Mode.Server || Mode.Debug || Mode.Trace || Mode.Quiet
case StdoutStrategy:
fallthrough
default:
@@ -131,11 +134,14 @@ func Info(args ...interface{}) string {
// Warn message logging.
func Warn(args ...interface{}) string {
- if Mode.Server {
- return log(serverStr, warnStr, args)
+ if !Mode.Quiet {
+ if Mode.Server {
+ return log(serverStr, warnStr, args)
+ }
+ return log(clientStr, warnStr, args)
}
- return log(clientStr, warnStr, args)
+ return ""
}
// Error message logging.
@@ -242,7 +248,7 @@ func log(what string, severity string, args []interface{}) string {
message := strings.Join(messages, "|")
write(what, severity, message)
- return message
+ return fmt.Sprintf("%s|%s", severity, message)
}
// Raw message logging.
diff --git a/internal/io/logger/modes.go b/internal/io/logger/modes.go
index 47dadfe..8864179 100644
--- a/internal/io/logger/modes.go
+++ b/internal/io/logger/modes.go
@@ -6,6 +6,7 @@ type Modes struct {
Trace bool
Debug bool
Nothing bool
+ Quiet bool
logToStdout bool
logToFile bool
}
diff --git a/internal/io/prompt/prompt.go b/internal/io/prompt/prompt.go
index a438d33..36ebdb5 100644
--- a/internal/io/prompt/prompt.go
+++ b/internal/io/prompt/prompt.go
@@ -3,9 +3,10 @@ package prompt
import (
"bufio"
"fmt"
- "github.com/mimecast/dtail/internal/io/logger"
"os"
"strings"
+
+ "github.com/mimecast/dtail/internal/io/logger"
)
// Answer is a user input of a prompt question.
@@ -18,8 +19,7 @@ type Answer struct {
Callback func()
// Runs after Callback and after logging resumes
EndCallback func()
-
- AskAgain bool
+ AskAgain bool
}
// Prompt used for interactive user input.
diff --git a/internal/io/signal/signal.go b/internal/io/signal/signal.go
index 3785d71..500c530 100644
--- a/internal/io/signal/signal.go
+++ b/internal/io/signal/signal.go
@@ -4,33 +4,38 @@ import (
"context"
"os"
gosignal "os/signal"
+ "syscall"
"time"
- "github.com/mimecast/dtail/internal/io/logger"
+ "github.com/mimecast/dtail/internal/config"
)
-// StatsCh returns a channel for "please print stats" signalling.
-func InterruptCh(ctx context.Context) <-chan struct{} {
- sigCh := make(chan os.Signal)
- gosignal.Notify(sigCh, os.Interrupt)
+// InterruptCh returns a channel for "please print stats" signalling.
+func InterruptCh(ctx context.Context) <-chan string {
+ sigIntCh := make(chan os.Signal)
+ gosignal.Notify(sigIntCh, os.Interrupt)
- statsCh := make(chan struct{})
+ sigOtherCh := make(chan os.Signal)
+ gosignal.Notify(sigOtherCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGQUIT)
+
+ statsCh := make(chan string)
go func() {
for {
select {
- case <-sigCh:
+ case <-sigIntCh:
select {
- case statsCh <- struct{}{}:
- logger.Info("Hit Ctrl+C twice to exit")
+ case statsCh <- "Hint: Hit Ctrl+C again to exit":
select {
- case <-sigCh:
+ case <-sigIntCh:
os.Exit(0)
- case <-time.After(time.Second):
+ case <-time.After(time.Second * time.Duration(config.InterruptTimeoutS)):
}
default:
- // Stats currently already printed.
+ // Stats already printed.
}
+ case <-sigOtherCh:
+ os.Exit(0)
case <-ctx.Done():
return
}