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() { func SetRules() {
sFmt := "windowtype~\"_NET_WM_WINDOW_TYPE_%s\"" sFmt := "windowtype~_NET_WM_WINDOW_TYPE_%s"
logError(hlcl.Rule("focus=on")) logError(hlcl.Rule("focus=on"))
logError(hlcl.Rule("floatplacement=smart")) logError(hlcl.Rule("floatplacement=smart"))
logError(hlcl.Rule("fixedsize", "floating=on")) 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) 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() exec.Command("xsetroot", "-solid", "black").Run()
logError(hlcl.KeyUnbind()) logError(hlcl.KeyUnbind())

View File

@ -2,11 +2,31 @@ package ctllog
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"runtime/debug" "runtime/debug"
"strings" "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 { type Logger struct {
coloredName string coloredName string
} }
@ -24,7 +44,7 @@ func (l Logger) print(str string) {
lines[i] = fmt.Sprintf("%s: %s", l.coloredName, line) lines[i] = fmt.Sprintf("%s: %s", l.coloredName, line)
} }
str = strings.Join(lines, "\n") str = strings.Join(lines, "\n")
fmt.Fprintln(os.Stderr, str) fmt.Fprintln(logfile, str)
} }
func (l Logger) colored(color ColorRGB, args ...any) { 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) { func runGeneric(command string, stdin string, args ...string) (string, error) {
cmd := exec.Command(command, args...) 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{} var stdout, stderr = bytes.Buffer{}, bytes.Buffer{}
cmd.Stderr = &stderr cmd.Stderr = &stderr
cmd.Stdout = &stdout cmd.Stdout = &stdout