Skip to content

Commit

Permalink
Switch to my own logging library
Browse files Browse the repository at this point in the history
  • Loading branch information
skifli committed Feb 11, 2023
1 parent 8845474 commit a39ca14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ go 1.19
require (
github.com/akamensky/argparse v1.4.0 // Better flag parsing
github.com/goccy/go-json v0.10.0 // Faster json parsing
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // Better logging
github.com/skifli/golog v1.0.2 // Logging API
golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 // Slices manipulation functions
)

require (
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/skifli/golog v1.0.2 h1:B23fTxGlD/q+arioUqreAbYHUPxJYO019BbW3wFrAxk=
github.com/skifli/golog v1.0.2/go.mod h1:PB5/BtIUjQzJyMbpdBJLuCBbAt5p1xlC+NkBauOGRIY=
golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 h1:fJwx88sMf5RXwDwziL0/Mn9Wqs+efMSo/RYcL+37W9c=
golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
32 changes: 16 additions & 16 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ import (

"github.com/akamensky/argparse"
"github.com/goccy/go-json"
"github.com/op/go-logging"
"github.com/skifli/golog"
"golang.org/x/exp/slices"
)

var VERSION = "v1.3.0"
var VERSION = "v1.3.1"

var log = logging.MustGetLogger("gocc")
var logger = golog.NewLogger([]*golog.Log{
golog.NewLog([]*os.File{os.Stderr}, golog.FormatterHuman),
})
var mode = ""
var processedNum = 0
var targets []string
var successfulNum = 0

func check(err error) {
if err != nil {
log.Fatal(err)
logger.Panic(err, nil)
}
}

Expand Down Expand Up @@ -97,14 +99,14 @@ func parseConfig() (string, string) {
argsError("Config file does not contain required key 'targets'.")
}

log.Debug("Parsed configuration file.")
logger.Debug("Parsed configuration file.", nil)
}

if *dump == "" {
*dump = filepath.Join(cwd, "build")
log.Debugf("Dump directory set to '%s' because it wasn't specified.", dump)
logger.Debugf("Dump directory set to '%s' because it wasn't specified.", nil, *dump)
} else {
log.Debugf("Dump directory set to '%s'.", dump)
logger.Debugf("Dump directory set to '%s'.", nil, *dump)
}

err = os.MkdirAll(*dump, 0700)
Expand All @@ -131,7 +133,7 @@ func checkForUpdate() {
tag := bodyJson["tag_name"].(string)

if tag != VERSION {
log.Warningf("Update available (%s -> %s).", VERSION, tag)
logger.Warningf("Update available (%s -> %s).", nil, VERSION, tag)
}
}

Expand All @@ -150,8 +152,6 @@ func checkNotAllowed(buildStr string, build []string) bool {
}

func main() {
logging.SetBackend(logging.NewBackendFormatter(logging.NewLogBackend(os.Stderr, "", 0), logging.MustStringFormatter(`%{color}[%{time:15:04:05.000}] %{level}%{color:reset} - %{message}`)))

checkForUpdate()

dump, target := parseConfig()
Expand All @@ -163,7 +163,7 @@ func main() {

builds := strings.FieldsFunc(string(buildsBytes), func(r rune) bool { return r == '\n' })

log.Debug("Beginning compilation of targets.")
logger.Debug("Beginning compilation of targets.", nil)

cmd = exec.Command("gcc")

Expand All @@ -177,11 +177,11 @@ func main() {
build := strings.Split(buildStr, "/")

if checkNotAllowed(buildStr, build) {
log.Debugf("Skipping '%s' because the config disallows it.", buildStr)
logger.Debugf("Skipping '%s' because the config disallows it.", nil, buildStr)
continue
}

log.Debugf("Compiling for '%s'.", buildStr)
logger.Debugf("Compiling for '%s'.", nil, buildStr)
processedNum++

path := ""
Expand All @@ -198,12 +198,12 @@ func main() {
outputBytes, err := cmd.CombinedOutput()

if err != nil {
log.Warningf("Failed to compile for '%s'. %s: %s", buildStr, err, strings.Join(strings.FieldsFunc(string(outputBytes), func(r rune) bool { return r == '\n' }), "; "))
logger.Warningf("Failed to compile for '%s'. %s: %s", nil, buildStr, err, strings.Join(strings.FieldsFunc(string(outputBytes), func(r rune) bool { return r == '\n' }), "; "))
} else {
log.Debugf("Successfully compiled for '%s'.", buildStr)
logger.Debugf("Successfully compiled for '%s'.", nil, buildStr)
successfulNum++
}
}

log.Debugf("Compilation of targets completed in %.2f seconds. %d / %d targets successfully compiled (%.2f%%).", time.Since(start).Seconds(), successfulNum, processedNum, float64(successfulNum)/float64(processedNum)*100)
logger.Debugf("Compilation of targets completed in %.2f seconds. %d / %d targets successfully compiled (%.2f%%).", nil, time.Since(start).Seconds(), successfulNum, processedNum, float64(successfulNum)/float64(processedNum)*100)
}

0 comments on commit a39ca14

Please sign in to comment.