github.com/searKing/golang/go@v1.2.117/log/slog/color.go (about) 1 // Copyright 2023 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package slog 6 7 import "log/slog" 8 9 // https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters 10 // https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit 11 const ( 12 reset = "\x1b[0m" 13 black = "\x1b[30m" 14 red = "\x1b[31m" 15 green = "\x1b[32m" 16 yellow = "\x1b[33m" 17 blue = "\x1b[34m" 18 magenta = "\x1b[35m" 19 cyan = "\x1b[36m" 20 white = "\x1b[37m" 21 gray = "\x1b[90m" 22 ) 23 24 func levelColor(level slog.Level) string { 25 switch level { 26 case slog.LevelDebug: 27 return gray 28 case slog.LevelWarn: 29 return yellow 30 case slog.LevelError: 31 return red 32 default: 33 return blue 34 } 35 }