1//go:build !windows && !plan92// +build !windows,!plan934/*5Maddy Mail Server - Composable all-in-one email server.6Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors78This program is free software: you can redistribute it and/or modify9it under the terms of the GNU General Public License as published by10the Free Software Foundation, either version 3 of the License, or11(at your option) any later version.1213This program is distributed in the hope that it will be useful,14but WITHOUT ANY WARRANTY; without even the implied warranty of15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16GNU General Public License for more details.1718You should have received a copy of the GNU General Public License19along with this program. If not, see <https://www.gnu.org/licenses/>.20*/2122package log2324import (25 "fmt"26 "log/syslog"27 "os"28 "time"29)3031type syslogOut struct {32 w *syslog.Writer33}3435func (s syslogOut) Write(stamp time.Time, debug bool, msg string) {36 var err error37 if debug {38 err = s.w.Debug(msg + "\n")39 } else {40 err = s.w.Info(msg + "\n")41 }4243 if err != nil {44 fmt.Fprintf(os.Stderr, "!!! Failed to send message to syslog daemon: %v\n", err)45 }46}4748func (s syslogOut) Close() error {49 return s.w.Close()50}5152// SyslogOutput returns a log.Output implementation that will send53// messages to the system syslog daemon.54//55// Regular messages will be written with INFO priority,56// debug messages will be written with DEBUG priority.57//58// Returned log.Output object is goroutine-safe.59func SyslogOutput() (Output, error) {60 w, err := syslog.New(syslog.LOG_MAIL|syslog.LOG_INFO, "maddy")61 return syslogOut{w}, err62}