1/*2Maddy Mail Server - Composable all-in-one email server.3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors45This program is free software: you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation, either version 3 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program. If not, see <https://www.gnu.org/licenses/>.17*/1819package log2021import (22 "time"23)2425type Output interface {26 Write(stamp time.Time, debug bool, msg string)27 Close() error28}2930type multiOut struct {31 outs []Output32}3334func (m multiOut) Write(stamp time.Time, debug bool, msg string) {35 for _, out := range m.outs {36 out.Write(stamp, debug, msg)37 }38}3940func (m multiOut) Close() error {41 for _, out := range m.outs {42 if err := out.Close(); err != nil {43 return err44 }45 }46 return nil47}4849func MultiOutput(outputs ...Output) Output {50 return multiOut{outputs}51}5253type funcOut struct {54 out func(time.Time, bool, string)55 close func() error56}5758func (f funcOut) Write(stamp time.Time, debug bool, msg string) {59 f.out(stamp, debug, msg)60}6162func (f funcOut) Close() error {63 return f.close()64}6566func FuncOutput(f func(time.Time, bool, string), close func() error) Output {67 return funcOut{f, close}68}6970type NopOutput struct{}7172func (NopOutput) Write(time.Time, bool, string) {}7374func (NopOutput) Close() error { return nil }