Skip to content

Commit

Permalink
Fix logging output showing
Browse files Browse the repository at this point in the history
  • Loading branch information
Borwe committed Nov 20, 2023
1 parent 23acdd5 commit bd5597b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module wakarizer

go 1.20
go 1.21

toolchain go1.21.4

require (
github.com/charmbracelet/bubbles v0.16.1
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"os"
"strings"

"wakarizer/wakatime"

"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/wakatime/wakatime-cli/pkg/log"
ini "gopkg.in/ini.v1"
"wakarizer/wakatime"
)

type Status int
Expand Down Expand Up @@ -65,6 +67,12 @@ func (l *LanguagesInfo) updateLanguageIndex() {
// Perform the actual wakatime hearbeat
func (l *LanguagesInfo) doHeartBeat() {
key := l.getKey()
_, w, error := os.Pipe()
if error != nil {
fmt.Fprintln(os.Stderr, "Error creating Pipe")
os.Exit(1)
}
log.SetOutput(w)
for {
wakatime.Execute(l.languages[l.language_index], key)
l.updateLanguageIndex()
Expand Down
68 changes: 33 additions & 35 deletions wakatime/wakatime.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,37 @@ import (
"gopkg.in/ini.v1"
)

func Execute(lang string, key string){
iniOption := viper.IniLoadOptions(ini.LoadOptions{
AllowPythonMultilineValues: true,
})
viper := viper.NewWithOptions(iniOption)


file, err := os.CreateTemp(fmt.Sprintf("%s",os.TempDir()),fmt.Sprintf("*.%s",lang))
if err!=nil {
fmt.Printf("Error creating temp file: %s", err)
os.Exit(1)
}


fileName := file.Name()

viper.Set("entity", fileName)
viper.Set("plugin", "\"wakarizer-wakatime/0.1\"")
viper.Set("write", "")
viper.Set("key", key)

file.WriteString(fmt.Sprintf("YOLO BABY %d", rand.Intn(999999999)))
file.Close()

_, err = heartbeat.Run(viper)
if err!=nil {
//fmt.Printf("ERROR: %s",err) uncomment to see debug info
}

os.Remove(file.Name())

time.Sleep(time.Second * 3)
//fmt.Printf("KEY: %s FILE: %s",key, file) //print where the file is located
// Comment out bellow for testing execution
//os.Exit(1)
func Execute(lang string, key string) {
iniOption := viper.IniLoadOptions(ini.LoadOptions{
AllowPythonMultilineValues: true,
})
viper := viper.NewWithOptions(iniOption)

file, err := os.CreateTemp(fmt.Sprintf("%s", os.TempDir()), fmt.Sprintf("*.%s", lang))
if err != nil {
fmt.Printf("Error creating temp file: %s", err)
os.Exit(1)
}

fileName := file.Name()

viper.Set("entity", fileName)
viper.Set("plugin", "\"wakarizer-wakatime/0.1\"")
viper.Set("write", "")
viper.Set("key", key)

file.WriteString(fmt.Sprintf("YOLO BABY %d", rand.Intn(999999999)))
file.Close()

_, err = heartbeat.Run(viper)
if err != nil {
//fmt.Printf("ERROR: %s",err) uncomment to see debug info
}

os.Remove(file.Name())

time.Sleep(time.Second * 3)
//fmt.Printf("KEY: %s FILE: %s",key, file) //print where the file is located
// Comment out bellow for testing execution
//os.Exit(1)
}

0 comments on commit bd5597b

Please sign in to comment.