Skip to content

Commit

Permalink
feat: use koi/util/logger, close #35
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Jun 1, 2022
1 parent 770e87d commit 227b54c
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 94 deletions.
6 changes: 1 addition & 5 deletions packages/koi/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import (
"github.com/urfave/cli/v2"
"koi/config"
"koi/env"

log "github.com/sirupsen/logrus"
l "koi/util/logger"
)

var (
// Log
l = log.WithField("package", "cli")

app = &cli.App{
Name: "Koi",
Usage: "The Koishi Launcher.",
Expand Down
14 changes: 8 additions & 6 deletions packages/koi/cli/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"koi/config"
"koi/daemon"
"koi/util"
l "koi/util/logger"
"koi/util/strutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -74,12 +76,12 @@ var (
func createInstanceAction(c *cli.Context) error {
var err error

name := util.Trim(c.String("name"))
name := strutil.Trim(c.String("name"))
l.Infof("Creating new instance: %s", name)

var packages []string
for _, p := range strings.Split(util.Trim(c.String("with-packages")), ",") {
pp := util.Trim(p)
for _, p := range strings.Split(strutil.Trim(c.String("with-packages")), ",") {
pp := strutil.Trim(p)
if len(pp) > 0 {
packages = append(packages, pp)
}
Expand Down Expand Up @@ -116,15 +118,15 @@ func createInstanceAction(c *cli.Context) error {
}

l.Debug("Constructing boilerplate url.")
mirror := util.Trim(c.String("mirror"))
mirror := strutil.Trim(c.String("mirror"))
if mirror == "" {
mirror = "https://github.com"
}
template := util.Trim(c.String("template"))
template := strutil.Trim(c.String("template"))
if template == "" {
template = "koishijs/boilerplate"
}
ref := util.Trim(c.String("ref"))
ref := strutil.Trim(c.String("ref"))
if ref == "" {
ref = "refs/heads/master"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/koi/cli/pre.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package cli

import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"koi/config"
l "koi/util/logger"
)

func preAction(c *cli.Context) error {
l.Debug("Trigger pseudo action: pre")

l.Debug("Checking flag debug...")
if c.Bool("debug") {
log.SetLevel(log.TraceLevel)
l.Level = l.DebugLevel
}

l.Debug("Checking config file...")
Expand Down
1 change: 1 addition & 0 deletions packages/koi/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"github.com/urfave/cli/v2"
"koi/daemon"
l "koi/util/logger"
)

func runAction(*cli.Context) error {
Expand Down
4 changes: 3 additions & 1 deletion packages/koi/cli/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"koi/config"
"koi/daemon"
"koi/util"
l "koi/util/logger"
"koi/util/strutil"
)

var (
Expand All @@ -29,7 +31,7 @@ func yarnAction(c *cli.Context) error {
args := c.Args().Slice()
l.Info(args)

target := util.Trim(c.String("target"))
target := strutil.Trim(c.String("target"))
if target == "" {
target = config.Config.Target
}
Expand Down
7 changes: 3 additions & 4 deletions packages/koi/config/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package config

import log "github.com/sirupsen/logrus"
import (
l "koi/util/logger"
)

var (
// Log
l = log.WithField("package", "config")

Version = "v0.0.0"

Config *KoiConfig
Expand Down
1 change: 1 addition & 0 deletions packages/koi/config/read_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/goccy/go-yaml"
"koi/env"
"koi/util"
l "koi/util/logger"
"os"
"path/filepath"
"runtime"
Expand Down
7 changes: 1 addition & 6 deletions packages/koi/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ package daemon

import (
"github.com/ifrstr/browser"
log "github.com/sirupsen/logrus"
"koi/config"
"koi/util"
l "koi/util/logger"
"os"
"os/signal"
"strings"
"syscall"
)

var (
// Log
l = log.WithField("package", "daemon")
)

// Daemon is to start and daemon the Koishi process.
//
// The only thing to emphasize is that the Daemon will always be
Expand Down
16 changes: 6 additions & 10 deletions packages/koi/daemon/node_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ package daemon

import (
"bufio"
log "github.com/sirupsen/logrus"
"koi/config"
"koi/util"
l "koi/util/logger"
"koi/util/strutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)

var (
// Log
lKoishi = log.WithField("package", "koishi")
)

type NodeCmdOut struct {
IsErr bool
Text string
Expand Down Expand Up @@ -229,8 +225,8 @@ func CreateNodeCmd(
stdoutScanner := bufio.NewScanner(stdoutPipe)
go func() {
for stdoutScanner.Scan() {
s := stdoutScanner.Text() + util.ResetCtrlStr
lKoishi.Info(s)
s := stdoutScanner.Text() + strutil.ResetCtrlStr
_, _ = os.Stderr.WriteString(s + "\n")
if nodeCmd.Out != nil {
*nodeCmd.Out <- NodeCmdOut{
IsErr: false,
Expand All @@ -256,8 +252,8 @@ func CreateNodeCmd(
stderrScanner := bufio.NewScanner(stderrPipe)
go func() {
for stderrScanner.Scan() {
s := stderrScanner.Text() + util.ResetCtrlStr
lKoishi.Info(s)
s := stderrScanner.Text() + strutil.ResetCtrlStr
_, _ = os.Stderr.WriteString(s + "\n")
if nodeCmd.Out != nil {
*nodeCmd.Out <- NodeCmdOut{
IsErr: true,
Expand Down
5 changes: 1 addition & 4 deletions packages/koi/env/path.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package env

import (
log "github.com/sirupsen/logrus"
"koi/util"
l "koi/util/logger"
"os"
"path/filepath"
)

var (
// Log
l = log.WithField("package", "env")

DirName = dirName()
)

Expand Down
3 changes: 0 additions & 3 deletions packages/koi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module koi
go 1.16

require (
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/goccy/go-yaml v1.9.5
github.com/ifrstr/browser v0.1.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.6.1 // indirect
github.com/urfave/cli/v2 v2.4.0
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71
)
13 changes: 0 additions & 13 deletions packages/koi/go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ=
github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
Expand All @@ -25,17 +21,11 @@ github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I=
github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -44,7 +34,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71 h1:X/2sJAybVknnUnV7AD2HdT6rm2p5BP6eH2j+igduWgk=
Expand All @@ -57,5 +46,3 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
14 changes: 1 addition & 13 deletions packages/koi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
package main

import (
formatter "github.com/antonfisher/nested-logrus-formatter"
log "github.com/sirupsen/logrus"
"koi/cli"
"koi/config"
l "koi/util/logger"
"os"
"runtime"
)

var (
// Log
l = log.WithField("package", "main")
)

func main() {
// Initialize log
log.SetFormatter(&formatter.Formatter{
FieldsOrder: []string{"package", "component"},
HideKeys: true,
})

// Initialize environment
l.Infof("Koi %s", config.Version)
l.Infof("Go: %s", runtime.Version())
Expand Down
1 change: 1 addition & 0 deletions packages/koi/util/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"errors"
"io"
l "koi/util/logger"
"os"
"path/filepath"
"strings"
Expand Down
Loading

0 comments on commit 227b54c

Please sign in to comment.