debug logging support + rule fix

This commit is contained in:
emilis 2023-01-07 18:12:19 +00:00
parent 23bb7a61ba
commit adf911b780
3 changed files with 23 additions and 7 deletions

View File

@ -224,7 +224,7 @@ func Theme(cfg config.HlwmConfig) {
}
func SetRules() {
sFmt := "windowtype~\"_NET_WM_WINDOW_TYPE_%s\""
sFmt := "windowtype~_NET_WM_WINDOW_TYPE_%s"
logError(hlcl.Rule("focus=on"))
logError(hlcl.Rule("floatplacement=smart"))
logError(hlcl.Rule("fixedsize", "floating=on"))
@ -288,10 +288,6 @@ func (command) Invoke(args ...string) error {
return fmt.Errorf("setting cfg values to hlwm: %s", err)
}
if err := hlcl.Lock(); err != nil {
return fmt.Errorf("failed lock: %w", err)
}
exec.Command("xsetroot", "-solid", "black").Run()
logError(hlcl.KeyUnbind())

View File

@ -2,11 +2,31 @@ package ctllog
import (
"fmt"
"io"
"os"
"runtime/debug"
"strings"
)
var (
logfile io.Writer
)
func init() {
if os.Getenv("debug") == "true" {
path := fmt.Sprintf("%s/.hlctl.log", os.Getenv("HOME"))
file, err := os.Create(path)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not open [%s] for logging: %s\n", path, err)
fmt.Fprintln(os.Stderr, "Defaulting to stderr")
logfile = os.Stderr
}
logfile = file
} else {
logfile = os.Stderr
}
}
type Logger struct {
coloredName string
}
@ -24,7 +44,7 @@ func (l Logger) print(str string) {
lines[i] = fmt.Sprintf("%s: %s", l.coloredName, line)
}
str = strings.Join(lines, "\n")
fmt.Fprintln(os.Stderr, str)
fmt.Fprintln(logfile, str)
}
func (l Logger) colored(color ColorRGB, args ...any) {

View File

@ -18,7 +18,7 @@ var log = ctllog.Logger{}.New("hlcl", ctllog.Purple)
func runGeneric(command string, stdin string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
// log.Printf("Running command [%s] with args: %v", command, args)
log.Printf("Running command [%s] with args: %v", command, args)
var stdout, stderr = bytes.Buffer{}, bytes.Buffer{}
cmd.Stderr = &stderr
cmd.Stdout = &stdout