/* Copyright (C) 2021 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package main import ( "log" "os" "path/filepath" "time" "go.cypherpunks.ru/tai64n/v2" ) var ( notai *bool sinkCert = make(chan string) sinkErr = make(chan string) sinkOK = make(chan string) sinkOther = make(chan string) sinkRedir = make(chan string) sinkReq = make(chan string) sinkTLS = make(chan string) fifos *string ) func sinker(c chan string, p string) { tai := new(tai64n.TAI64N) fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666)) if err != nil { log.Fatalln(err) } for s := range c { if *notai { fd.WriteString(s + "\n") } else { tai.FromTime(time.Now()) fd.WriteString(tai64n.Encode(tai[:]) + " " + s + "\n") } fd.Close() fd, err = os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666)) if err != nil { log.Printf("Sink error: %+v\n", err) } } } func fifoInit() { go sinker(sinkCert, filepath.Join(*fifos, "cert")) go sinker(sinkErr, filepath.Join(*fifos, "err")) go sinker(sinkOK, filepath.Join(*fifos, "ok")) go sinker(sinkOther, filepath.Join(*fifos, "other")) go sinker(sinkRedir, filepath.Join(*fifos, "redir")) go sinker(sinkReq, filepath.Join(*fifos, "req")) go sinker(sinkTLS, filepath.Join(*fifos, "tls")) }