autogits/bots-common/log.go

42 lines
1.1 KiB
Go
Raw Normal View History

2024-07-07 21:08:41 +02:00
package common
2024-09-10 18:24:41 +02:00
/*
* This file is part of Autogits.
*
* Copyright © 2024 SUSE LLC
*
* Autogits 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, either version 2 of the License, or (at your option) any later
* version.
*
* Autogits 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
* Foobar. If not, see <https://www.gnu.org/licenses/>.
*/
2024-07-07 21:08:41 +02:00
import (
"fmt"
"io"
2024-08-24 13:32:39 +02:00
"log"
2024-07-07 21:08:41 +02:00
)
var id uint
2024-08-24 13:32:39 +02:00
func CreateStdoutLogger(stdout, stderr io.Writer) (*log.Logger, *log.Logger) {
2024-07-07 21:08:41 +02:00
id++
2024-08-24 13:32:39 +02:00
idStr := fmt.Sprintf("[%d] ", id)
stdLogger := log.New(stdout, idStr, log.Lmsgprefix)
errLogger := log.New(stderr, idStr, log.Lmsgprefix)
return stdLogger, errLogger
2024-07-07 21:08:41 +02:00
}
2024-09-11 18:50:49 +02:00
func PanicOnError(err error) {
if err != nil {
panic(err)
}
}