mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
🚚 move only the platform-specific part of log tailing into platform-specific files
This commit is contained in:
parent
533817bda3
commit
53ea7df655
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/aybabtme/humanlog"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
@ -306,3 +307,25 @@ func (app *App) KnownError(err error) (string, bool) {
|
|||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TailLogs() {
|
||||||
|
logFilePath, err := config.LogPath()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Tailing log file %s\n\n", logFilePath)
|
||||||
|
|
||||||
|
opts := humanlog.DefaultOptions
|
||||||
|
opts.Truncates = false
|
||||||
|
|
||||||
|
_, err = os.Stat(logFilePath)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
log.Fatal("Log file does not exist. Run `lazygit --debug` first to create the log file")
|
||||||
|
}
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
TailLogsForPlatform(logFilePath, opts)
|
||||||
|
}
|
||||||
|
@ -3,33 +3,13 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/aybabtme/humanlog"
|
"github.com/aybabtme/humanlog"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TailLogs() {
|
func TailLogsForPlatform(logFilePath string, opts *humanlog.HandlerOptions) {
|
||||||
logFilePath, err := config.LogPath()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Tailing log file %s\n\n", logFilePath)
|
|
||||||
|
|
||||||
opts := humanlog.DefaultOptions
|
|
||||||
opts.Truncates = false
|
|
||||||
|
|
||||||
_, err = os.Stat(logFilePath)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
log.Fatal("Log file does not exist. Run `lazygit --debug` first to create the log file")
|
|
||||||
}
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := secureexec.Command("tail", "-f", logFilePath)
|
cmd := secureexec.Command("tail", "-f", logFilePath)
|
||||||
|
|
||||||
stdout, _ := cmd.StdoutPipe()
|
stdout, _ := cmd.StdoutPipe()
|
||||||
|
@ -4,38 +4,14 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
|
||||||
"github.com/aybabtme/humanlog"
|
"github.com/aybabtme/humanlog"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TailLogs() {
|
func TailLogsForPlatform(logFilePath string, opts *humanlog.HandlerOptions) {
|
||||||
logFilePath, err := config.LogPath()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Tailing log file %s\n\n", logFilePath)
|
|
||||||
|
|
||||||
opts := humanlog.DefaultOptions
|
|
||||||
opts.Truncates = false
|
|
||||||
|
|
||||||
_, err = os.Stat(logFilePath)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
log.Fatal("Log file does not exist. Run `lazygit --debug` first to create the log file")
|
|
||||||
}
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
TailLogsNative(logFilePath, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TailLogsNative(logFilePath string, opts *humanlog.HandlerOptions) {
|
|
||||||
var lastModified int64 = 0
|
var lastModified int64 = 0
|
||||||
var lastOffset int64 = 0
|
var lastOffset int64 = 0
|
||||||
for {
|
for {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user