Skip to content

Commit

Permalink
experiments with simpler logger (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Apr 21, 2023
1 parent 648e54d commit 164cb23
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,22 @@ var liveCmd = &cobra.Command{

func runGloomberg(_ *cobra.Command, _ []string) {
// print header
header := style.GetHeader(Version)
header := style.GetHeader(internal.GloombergVersion)
fmt.Println(header)
gbl.Log.Info(header)

// make version available to all packages
internal.GloombergVersion = Version
// file logger | open file and create if non-existent
logFile, err := os.OpenFile(viper.GetString("log.log_file"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
gbl.Log.Fatal(err)
}
defer logFile.Close()

// loFi := internal.FileLogger(logFile)

lo.Print(header)

// loFi.Print(header)

// global defaults
viper.Set("http.timeout", 27*time.Second)
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
var (
apiKeyEtherscan, apiKeyMoralis, apiKeyOpensea, cfgFile string
endpoints, ownWallets []string

lo = internal.BasePrinter
)

// rootCmd represents the base command when called without any subcommands.
Expand Down
33 changes: 33 additions & 0 deletions internal/lo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package internal

import (
"github.com/charmbracelet/log"
)

// disabled as charmbracelet/log 0.2.1 is required for this to work
// but that version has a bug that causes gloomberg to randomly print ansi sequences...^^
var (
// BaseLogger = log.NewWithOptions(os.Stderr, log.Options{
// ReportCaller: true,
// ReportTimestamp: true,
// TimeFormat: time.TimeOnly,
// Prefix: "㏒",
// })

BaseLogger = log.New()

// BasePrinter = log.NewWithOptions(os.Stderr, log.Options{
// ReportCaller: false,
// ReportTimestamp: false,
// })

BasePrinter = log.New()
)

// func FileLogger(file *os.File) *log.Logger {
// return log.NewWithOptions(file, log.Options{
// ReportCaller: true,
// ReportTimestamp: true,
// TimeFormat: time.DateTime,
// })
// }

0 comments on commit 164cb23

Please sign in to comment.