all repos — honk @ ea8aab1e57ebf2a937b4ea8b336c3a88faf44fe4

my fork of honk

start making log shared
Ted Unangst tedu@tedunangst.com
Sun, 27 Feb 2022 15:38:19 -0500
commit

ea8aab1e57ebf2a937b4ea8b336c3a88faf44fe4

parent

c31318c11751d5c7f13ac23bfc29976460db8cb7

6 files changed, 17 insertions(+), 94 deletions(-)

jump to
M admin.goadmin.go

@@ -30,10 +30,12 @@ "fmt"

"os" "os/signal" "strings" + + "humungus.tedunangst.com/r/webs/log" ) func adminscreen() { - initLogging("null", "null", "null") + log.InitX("honk", "null", "null", "null") stdout := bufio.NewWriter(os.Stdout) esc := "\x1b" smcup := esc + "[?1049h"
M fun.gofun.go

@@ -653,10 +653,10 @@ }

return key, true }, Limit: 512}) -func zaggy(keyname string) httpsig.PublicKey { +func zaggy(keyname string) (httpsig.PublicKey, error) { var key httpsig.PublicKey zaggies.Get(keyname, &key) - return key + return key, nil } func savingthrow(keyname string) {
M go.modgo.mod

@@ -10,5 +10,5 @@ golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897

golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect golang.org/x/net v0.0.0-20201110031124-69a78807bb2b humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.48 + humungus.tedunangst.com/r/webs v0.6.49 )
M go.sumgo.sum

@@ -24,5 +24,5 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.6.48 h1:s4TadyjAZRWOi8I1v7bNXHbvPwQMKgGLGr/d/M2ZoM8= -humungus.tedunangst.com/r/webs v0.6.48/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.49 h1:Tv3Fx2xnv+TINW5gepCpaDP+xhkOWlWp3rYE9FAkP50= +humungus.tedunangst.com/r/webs v0.6.49/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=
M honk.gohonk.go

@@ -19,6 +19,7 @@ import (

"flag" "fmt" "html/template" + golog "log" notrand "math/rand" "os" "strconv"

@@ -26,6 +27,7 @@ "strings"

"time" "humungus.tedunangst.com/r/webs/httpsig" + "humungus.tedunangst.com/r/webs/log" ) var softwareVersion = "develop"

@@ -268,22 +270,22 @@ }

func reexecArgs(cmd string) []string { args := []string{"-datadir", dataDir} - args = append(args, loggingArgs()...) + args = append(args, log.Args()...) args = append(args, cmd) return args } + +var elog, ilog, dlog *golog.Logger func main() { flag.StringVar(&dataDir, "datadir", dataDir, "data directory") flag.StringVar(&viewDir, "viewdir", viewDir, "view directory") flag.Parse() - if alllogname != "stderr" { - elogname = alllogname - ilogname = alllogname - dlogname = alllogname - } - initLogging(elogname, ilogname, dlogname) + log.Init("honk") + elog = log.E + ilog = log.I + dlog = log.D args := flag.Args() cmd := "run"
D log.go

@@ -1,81 +0,0 @@

-// -// Copyright (c) 2022 Ted Unangst <tedu@tedunangst.com> -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -package main - -import ( - "flag" - "io/ioutil" - "log" - "log/syslog" - "os" -) - -// log.Default() not added until go 1.16 -func logdefault() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags) -} - -var elog = logdefault() -var ilog = logdefault() -var dlog = logdefault() - -var elogname, ilogname, dlogname, alllogname string - -func init() { - flag.StringVar(&elogname, "errorlog", "stderr", "error log file (or stderr, null, syslog)") - flag.StringVar(&ilogname, "infolog", "stderr", "info log file (or stderr, null, syslog)") - flag.StringVar(&dlogname, "debuglog", "stderr", "debug log file (or stderr, null, syslog)") - flag.StringVar(&alllogname, "log", "stderr", "combined log file (or stderr, null, syslog)") - -} - -func loggingArgs() []string { - return []string{"-errorlog", elogname, "-infolog", ilogname, "-debuglog", dlogname} -} - -func initLogging(elogname, ilogname, dlogname string) { - elog = openlog(elogname, syslog.LOG_ERR) - ilog = openlog(ilogname, syslog.LOG_INFO) - dlog = openlog(dlogname, syslog.LOG_DEBUG) -} - -func openlog(name string, prio syslog.Priority) *log.Logger { - if name == "stderr" { - return log.New(os.Stderr, "", log.LstdFlags) - } - if name == "stdout" { - return log.New(os.Stdout, "", log.LstdFlags) - } - if name == "null" { - return log.New(ioutil.Discard, "", log.LstdFlags) - } - if name == "syslog" { - w, err := syslog.New(syslog.LOG_UUCP|prio, "honk") - if err != nil { - elog.Printf("can't create syslog: %s", err) - return logdefault() - } - return log.New(w, "", log.LstdFlags) - } - fd, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600) - if err != nil { - elog.Printf("can't open log file %s: %s", name, err) - return logdefault() - } - logger := log.New(fd, "", log.LstdFlags) - logger.Printf("new log started") - return logger -}