|
- package main
- //
- // Fengg Security Gateway Server Application
- // Copyright (C) 2020 Lukas Matt <support@fen.gg>
- //
- // 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, either 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 <https://www.gnu.org/licenses/>.
- //
-
- import (
- "os"
- "regexp"
- "strings"
-
- "tea.fen.gg/fengg/server/types"
- "github.com/rs/zerolog"
- )
-
- var callerRegex = regexp.MustCompile(`^(.+?)/(fengg|\.golang|go)/`)
-
- func formatCaller(in interface{}) string {
- var out strings.Builder
- inString, ok := in.(string)
- if !ok {
- return "<nil>"
- }
- outPath := callerRegex.ReplaceAllString(inString, "")
- out.WriteString(types.ColorCyan)
- out.WriteString(outPath)
- out.WriteString(types.ColorReset)
- out.WriteString(" >")
- return out.String()
- }
-
- func formatMessage(in interface{}) string {
- inString, ok := in.(string)
- if !ok {
- return "<nil>"
- }
- return strings.ReplaceAll(inString, "\n", "\n> ")
- }
-
- var consoleWriter = zerolog.ConsoleWriter{
- Out: os.Stdout,
- PartsOrder: []string{
- zerolog.TimestampFieldName,
- zerolog.LevelFieldName,
- zerolog.CallerFieldName,
- zerolog.MessageFieldName,
- },
- FormatCaller: formatCaller,
- FormatMessage: formatMessage,
- }
-
- var logger = zerolog.New(os.Stdout).
- Output(consoleWriter).
- Hook(types.SentryLogHook{}).
- With().
- Stack().
- Caller().
- Timestamp().
- Logger()
|