style.go 692 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* Right now I only added necessary colors for logger */
  2. package prettylog
  3. type Style struct {
  4. Disabled bool
  5. stylmap map[string]string
  6. }
  7. func NewStyle() *Style {
  8. return &Style{
  9. Disabled: false,
  10. stylmap: map[string]string{
  11. "Message": "\033[37m",
  12. "Prefix": "\033[33m",
  13. "Time": "\033[34m",
  14. "Duration": "\033[90m",
  15. "File": "\033[30m",
  16. },
  17. }
  18. }
  19. func (s *Style) color(code string, str string) string {
  20. return code + str + "\033[0m"
  21. }
  22. func (s *Style) Get(str, msg string) string {
  23. if s.Disabled {
  24. return msg
  25. }
  26. return s.color(s.stylmap[str], msg)
  27. }
  28. func (s *Style) GetX(str, msg string) string {
  29. if s.Disabled {
  30. return ""
  31. }
  32. return s.Get(str, msg)
  33. }