Skip to content

Commit

Permalink
Added a droping log lib that matches our other log formats #8
Browse files Browse the repository at this point in the history
The lib is still new and missing its autorotating features. Closing this issue when that is added and the dep is updated
  • Loading branch information
SindreBrurberg committed Nov 2, 2021
1 parent 4c8cae2 commit ae3b9ee
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
3 changes: 2 additions & 1 deletion fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"

log "github.com/cantara/bragi"
)

func stripJar(s string) string {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/Cantara/vili
module github.com/cantara/vili

go 1.16

require (
github.com/cantara/bragi v0.1.8 // indirect
github.com/joho/godotenv v1.4.0 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
github.com/cantara/bragi v0.1.2 h1:x10uNDDwgxiHn+lLn7iAK5m0uj7QQOuW5k0F7AtK5h0=
github.com/cantara/bragi v0.1.2/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8=
github.com/cantara/bragi v0.1.3 h1:NNSrgbO74DcvV6zKDfwoiTGqysLsAXd5JdtueNLW6Bc=
github.com/cantara/bragi v0.1.3/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8=
github.com/cantara/bragi v0.1.5 h1:DKwUXy/vRHGP14cqe5LU1ju9QLLw8md0aB4ufiR/HrI=
github.com/cantara/bragi v0.1.5/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8=
github.com/cantara/bragi v0.1.6 h1:vz9HK0AtKXcesbL2+wxcZ4leYRyyu7nRUqN2L5WqgvU=
github.com/cantara/bragi v0.1.6/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8=
github.com/cantara/bragi v0.1.7 h1:jZN+vsOswlKe5BAKqePn0VHtyA7bFXm6IKexaTc80ZA=
github.com/cantara/bragi v0.1.7/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8=
github.com/cantara/bragi v0.1.8 h1:BVpNnkCT4ePpvnBTGEpg9JdDCFc+kkB/+/+go9ggrqU=
github.com/cantara/bragi v0.1.8/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
Expand Down
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"

log "github.com/cantara/bragi"
"github.com/joho/godotenv"
"k8s.io/utils/inotify"
)
Expand Down Expand Up @@ -54,18 +54,19 @@ func verifyConfig() error {
if os.Getenv("port_identifier") == "" {
return fmt.Errorf("No port identifier provided")
}
return nil
}

func main() {
loadEnv()
logFile := os.Getenv("log_file")
if logFile != "" {
f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatal(err)
logDir := os.Getenv("log_dir")
if logDir != "" {
cloaser := log.SetOutputFolder(logDir)
if cloaser != nil {
log.Fatal("Unable to sett logdir")
}
defer f.Close()
log.SetOutput(f)
defer cloaser()
log.SetPrefix("vili")
}
err := verifyConfig()
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"context"
"fmt"
"log"
"math"
"os"
"os/exec"
"sync"
"time"

log "github.com/cantara/bragi"
)

type serve struct { // TODO rename
Expand Down Expand Up @@ -73,7 +74,7 @@ func newServer(path, t string, server **serve) (err error) {
return
}

func startNewServer(serverFolder string) *serve {
func startNewServer(serverFolder, port string) *serve {
stdOut, err := os.OpenFile(serverFolder+"/stdOut", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"bufio"
"context"
"log"
"os"
"strings"

log "github.com/cantara/bragi"

"k8s.io/utils/inotify"
)

Expand Down
3 changes: 2 additions & 1 deletion zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"

log "github.com/cantara/bragi"
)

type zipper struct {
Expand Down

0 comments on commit ae3b9ee

Please sign in to comment.