@@ 11,6 11,7 @@ import (
"time"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
+ gnarkLogger "github.com/consensys/gnark/logger"
"github.com/kyoh86/xdg"
log "github.com/sirupsen/logrus"
"maunium.net/go/mautrix"
@@ 24,7 25,12 @@ import (
"tallyard.xyz/ui"
)
-var noRedact bool
+var (
+ noRedact bool
+ dataDir = xdg.DataHome() + "/tallyard"
+ electionsFname = dataDir + "/elections.json"
+ logsFname = dataDir + "/tallyard.log"
+)
func init() {
flag.BoolVar(&noRedact, "no-redact", false, "don't redact any messages once election is over (useful for debugging)")
@@ 33,16 39,17 @@ func init() {
func main() {
flag.Parse()
- os.MkdirAll(xdg.DataHome() + "/tallyard", 0700)
+ os.MkdirAll(dataDir, 0700)
- file, err := os.OpenFile(xdg.DataHome() + "/tallyard/tallyard.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
- if err == nil {
- log.SetLevel(log.DebugLevel)
- log.SetOutput(file)
- defer file.Close()
- } else {
- log.Errorf("failed to open logging file; using default stderr: %s", err)
+ file, err := os.OpenFile(logsFname, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
+ if err != nil {
+ log.Fatalf("failed to open logs file %s: %v", logsFname, err)
}
+ log.SetLevel(log.DebugLevel)
+ log.SetOutput(file)
+ gnarkLogger.SetOutput(file)
+ defer file.Close()
+
log.Info("tallyard starting...")
defer log.Info("tallyard exiting...")
@@ 238,8 245,6 @@ func setDeviceName(client *mautrix.Client, deviceID id.DeviceID) {
}
}
-var electionsFname = xdg.DataHome() + "/tallyard/elections.json"
-
func getElections(userID id.UserID) (*election.ElectionsMap, error) {
if _, err := os.Stat(electionsFname); os.IsNotExist(err) {
return election.NewElectionsMap(userID, saveElections), nil