A More Secure Internet Connection for Your Home https://fen.gg
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
1.8 KiB

  1. package main
  2. //
  3. // Fengg Security Gateway Server Application
  4. // Copyright (C) 2020 Lukas Matt <support@fen.gg>
  5. //
  6. // This program is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. //
  18. import (
  19. "os"
  20. "regexp"
  21. "strings"
  22. "tea.fen.gg/fengg/server/types"
  23. "github.com/rs/zerolog"
  24. )
  25. var callerRegex = regexp.MustCompile(`^(.+?)/(fengg|\.golang|go)/`)
  26. func formatCaller(in interface{}) string {
  27. var out strings.Builder
  28. inString, ok := in.(string)
  29. if !ok {
  30. return "<nil>"
  31. }
  32. outPath := callerRegex.ReplaceAllString(inString, "")
  33. out.WriteString(types.ColorCyan)
  34. out.WriteString(outPath)
  35. out.WriteString(types.ColorReset)
  36. out.WriteString(" >")
  37. return out.String()
  38. }
  39. func formatMessage(in interface{}) string {
  40. inString, ok := in.(string)
  41. if !ok {
  42. return "<nil>"
  43. }
  44. return strings.ReplaceAll(inString, "\n", "\n> ")
  45. }
  46. var consoleWriter = zerolog.ConsoleWriter{
  47. Out: os.Stdout,
  48. PartsOrder: []string{
  49. zerolog.TimestampFieldName,
  50. zerolog.LevelFieldName,
  51. zerolog.CallerFieldName,
  52. zerolog.MessageFieldName,
  53. },
  54. FormatCaller: formatCaller,
  55. FormatMessage: formatMessage,
  56. }
  57. var logger = zerolog.New(os.Stdout).
  58. Output(consoleWriter).
  59. Hook(types.SentryLogHook{}).
  60. With().
  61. Stack().
  62. Caller().
  63. Timestamp().
  64. Logger()