@@ -67,19 +67,21 @@ const (
6767 // to the JSON block); printf - \n is appended to the JSON block* and the
6868 // message format matches the specified user format.
6969 //
70- // So, to determine if a custom format pattern is specified, we use two
71- // constants formatStr and formatStrLn , which help determine the type of
72- // function (print, println, or printf) that renders the message, and the
73- // formatting methods for text or JSON style.
70+ // So, to determine if a custom format pattern is specified, we use
71+ // two constants formatPrint and formatPrintln , which help determine
72+ // the type of function (print, println, or printf) that renders
73+ // the message, and the formatting methods for text or JSON style.
7474 //
7575 // * JSON block is the final text representation of the logger in
7676 // JSON format written as text.
7777
78- // The formatStr is the system format string for print-type functions.
79- formatStr = "format: string-without-a-newline-character"
78+ // The formatPrint is the system format string
79+ // for print-type functions.
80+ formatPrint = "{$ string-without-a-newline-character $}"
8081
81- // The formatStrLn is the system format string for println-type functions.
82- formatStrLn = "format: string-with-a-newline-character"
82+ // The formatPrintln is the system format string
83+ // for println-type functions.
84+ formatPrintln = "{$ string-with-a-newline-character $}"
8385)
8486
8587var (
@@ -147,6 +149,8 @@ type Output struct {
147149 // The name must sound like a variable name in most programming languages:
148150 // it must have special characters, not start with a number, etc.
149151 // But the name can be a reserved word like return, for, if ... any.
152+ // The name can also be expressed as a selector name in CSS,
153+ // for example "some-log-file" (without the leading . or # symbols).
150154 Name string
151155
152156 // Writer is the point where the login data will be output,
@@ -440,7 +444,7 @@ func (logger *Logger) SetOutputs(outputs ...Output) error {
440444 // The name must be specified.
441445 if g .IsEmpty (o .Name ) {
442446 return fmt .Errorf ("the %d output has empty name" , i )
443- } else if ! o .isSystem && ! is .Var (o .Name ) {
447+ } else if ! o .isSystem && ! is .SelectorName (o .Name , true ) {
444448 return fmt .Errorf ("the %d output has incorrect name '%s'" ,
445449 i , o .Name )
446450 }
@@ -640,7 +644,7 @@ func (logger *Logger) echo(w io.Writer, l level.Level, f string, a ...any) {
640644// for its operands and writes to w. Spaces are added between operands
641645// when neither is a string.
642646func (logger * Logger ) Fpanic (w io.Writer , a ... any ) {
643- logger .echo (w , level .Panic , formatStr , a ... )
647+ logger .echo (w , level .Panic , formatPrint , a ... )
644648 panic (fmt .Sprint (a ... ))
645649}
646650
@@ -655,15 +659,15 @@ func (logger *Logger) Fpanicf(w io.Writer, format string, a ...any) {
655659// for its operands and writes to w. Spaces are always added between
656660// operands and a newline is appended.
657661func (logger * Logger ) Fpanicln (w io.Writer , a ... any ) {
658- logger .echo (w , level .Panic , formatStrLn , a ... )
662+ logger .echo (w , level .Panic , formatPrintln , a ... )
659663 panic (fmt .Sprintln (a ... ))
660664}
661665
662666// Panic creates message with Panic level, using the default formats
663667// for its operands and writes to log.Writer. Spaces are added between
664668// operands when neither is a string.
665669func (logger * Logger ) Panic (a ... any ) {
666- logger .echo (nil , level .Panic , formatStr , a ... )
670+ logger .echo (nil , level .Panic , formatPrint , a ... )
667671 panic (fmt .Sprint (a ... ))
668672}
669673
@@ -678,15 +682,15 @@ func (logger *Logger) Panicf(format string, a ...any) {
678682// for its operands and writes to log.Writer. Spaces are always added
679683// between operands and a newline is appended.
680684func (logger * Logger ) Panicln (a ... any ) (int , error ) {
681- logger .echo (nil , level .Panic , formatStrLn , a ... )
685+ logger .echo (nil , level .Panic , formatPrintln , a ... )
682686 panic (fmt .Sprintln (a ... ))
683687}
684688
685689// Ffatal creates message with Fatal level, using the default formats
686690// for its operands and writes to w. Spaces are added between operands
687691// when neither is a string.
688692func (logger * Logger ) Ffatal (w io.Writer , a ... any ) {
689- logger .echo (w , level .Fatal , formatStr , a ... )
693+ logger .echo (w , level .Fatal , formatPrint , a ... )
690694 exit (logger .fatalStatusCode )
691695}
692696
@@ -701,15 +705,15 @@ func (logger *Logger) Ffatalf(w io.Writer, format string, a ...any) {
701705// for its operands and writes to w. Spaces are always added between
702706// operands and a newline is appended.
703707func (logger * Logger ) Ffatalln (w io.Writer , a ... any ) {
704- logger .echo (w , level .Fatal , formatStrLn , a ... )
708+ logger .echo (w , level .Fatal , formatPrintln , a ... )
705709 exit (logger .fatalStatusCode )
706710}
707711
708712// Fatal creates message with Fatal level, using the default formats
709713// for its operands and writes to log.Writer. Spaces are added between
710714// operands when neither is a string.
711715func (logger * Logger ) Fatal (a ... any ) {
712- logger .echo (nil , level .Fatal , formatStr , a ... )
716+ logger .echo (nil , level .Fatal , formatPrint , a ... )
713717 exit (logger .fatalStatusCode )
714718}
715719
@@ -724,15 +728,15 @@ func (logger *Logger) Fatalf(format string, a ...any) {
724728// for its operands and writes to log.Writer. Spaces are always added
725729// between operands and a newline is appended.
726730func (logger * Logger ) Fatalln (a ... any ) {
727- logger .echo (nil , level .Fatal , formatStrLn , a ... )
731+ logger .echo (nil , level .Fatal , formatPrintln , a ... )
728732 exit (logger .fatalStatusCode )
729733}
730734
731735// Ferror creates message with Error level, using the default formats
732736// for its operands and writes to w. Spaces are added between operands
733737// when neither is a string.
734738func (logger * Logger ) Ferror (w io.Writer , a ... any ) {
735- logger .echo (w , level .Error , formatStr , a ... )
739+ logger .echo (w , level .Error , formatPrint , a ... )
736740}
737741
738742// Ferrorf creates message with Error level, according to a format
@@ -745,14 +749,14 @@ func (logger *Logger) Ferrorf(w io.Writer, f string, a ...any) {
745749// for its operands and writes to w. Spaces are always added between
746750// operands and a newline is appended.
747751func (logger * Logger ) Ferrorln (w io.Writer , a ... any ) {
748- logger .echo (w , level .Error , formatStrLn , a ... )
752+ logger .echo (w , level .Error , formatPrintln , a ... )
749753}
750754
751755// Error creates message with Error level, using the default formats
752756// for its operands and writes to log.Writer. Spaces are added between
753757// operands when neither is a string.
754758func (logger * Logger ) Error (a ... any ) {
755- logger .echo (nil , level .Error , formatStr , a ... )
759+ logger .echo (nil , level .Error , formatPrint , a ... )
756760}
757761
758762// Errorf creates message with Error level, according to a format specifier
@@ -765,14 +769,14 @@ func (logger *Logger) Errorf(f string, a ...any) {
765769// for its operands and writes to log.Writer. Spaces are always added
766770// between operands and a newline is appended.
767771func (logger * Logger ) Errorln (a ... any ) {
768- logger .echo (nil , level .Error , formatStrLn , a ... )
772+ logger .echo (nil , level .Error , formatPrintln , a ... )
769773}
770774
771775// Fwarn creates message with Warn level, using the default formats
772776// for its operands and writes to w. Spaces are added between operands
773777// when neither is a string.
774778func (logger * Logger ) Fwarn (w io.Writer , a ... any ) {
775- logger .echo (w , level .Warn , formatStr , a ... )
779+ logger .echo (w , level .Warn , formatPrint , a ... )
776780}
777781
778782// Fwarnf creates message with Warn level, according to a format
@@ -785,14 +789,14 @@ func (logger *Logger) Fwarnf(w io.Writer, format string, a ...any) {
785789// for its operands and writes to w. Spaces are always added between
786790// operands and a newline is appended.
787791func (logger * Logger ) Fwarnln (w io.Writer , a ... any ) {
788- logger .echo (w , level .Warn , formatStrLn , a ... )
792+ logger .echo (w , level .Warn , formatPrintln , a ... )
789793}
790794
791795// Warn creates message with Warn level, using the default formats
792796// for its operands and writes to log.Writer. Spaces are added between
793797// operands when neither is a string.
794798func (logger * Logger ) Warn (a ... any ) {
795- logger .echo (nil , level .Warn , formatStr , a ... )
799+ logger .echo (nil , level .Warn , formatPrint , a ... )
796800}
797801
798802// Warnf creates message with Warn level, according to a format specifier
@@ -805,14 +809,14 @@ func (logger *Logger) Warnf(format string, a ...any) {
805809// for its operands and writes to log.Writer. Spaces are always added
806810// between operands and a newline is appended.
807811func (logger * Logger ) Warnln (a ... any ) {
808- logger .echo (nil , level .Warn , formatStrLn , a ... )
812+ logger .echo (nil , level .Warn , formatPrintln , a ... )
809813}
810814
811815// Finfo creates message with Info level, using the default formats
812816// for its operands and writes to w. Spaces are added between operands
813817// when neither is a string.
814818func (logger * Logger ) Finfo (w io.Writer , a ... any ) {
815- logger .echo (w , level .Info , formatStr , a ... )
819+ logger .echo (w , level .Info , formatPrint , a ... )
816820}
817821
818822// Finfof creates message with Info level, according to a format
@@ -825,14 +829,14 @@ func (logger *Logger) Finfof(w io.Writer, format string, a ...any) {
825829// for its operands and writes to w. Spaces are always added between
826830// operands and a newline is appended.
827831func (logger * Logger ) Finfoln (w io.Writer , a ... any ) {
828- logger .echo (w , level .Info , formatStrLn , a ... )
832+ logger .echo (w , level .Info , formatPrintln , a ... )
829833}
830834
831835// Info creates message with Info level, using the default formats
832836// for its operands and writes to log.Writer. Spaces are added between
833837// operands when neither is a string.
834838func (logger * Logger ) Info (a ... any ) {
835- logger .echo (nil , level .Info , formatStr , a ... )
839+ logger .echo (nil , level .Info , formatPrint , a ... )
836840}
837841
838842// Infof creates message with Info level, according to a format specifier
@@ -845,14 +849,14 @@ func (logger *Logger) Infof(format string, a ...any) {
845849// for its operands and writes to log.Writer. Spaces are always added
846850// between operands and a newline is appended.
847851func (logger * Logger ) Infoln (a ... any ) {
848- logger .echo (nil , level .Info , formatStrLn , a ... )
852+ logger .echo (nil , level .Info , formatPrintln , a ... )
849853}
850854
851855// Fdebug creates message with Debug level, using the default formats
852856// for its operands and writes to w. Spaces are added between operands
853857// when neither is a string.
854858func (logger * Logger ) Fdebug (w io.Writer , a ... any ) {
855- logger .echo (w , level .Debug , formatStr , a ... )
859+ logger .echo (w , level .Debug , formatPrint , a ... )
856860}
857861
858862// Fdebugf creates message with Debug level, according to a format
@@ -865,14 +869,14 @@ func (logger *Logger) Fdebugf(w io.Writer, format string, a ...any) {
865869// for its operands and writes to w. Spaces are always added between
866870// operands and a newline is appended.
867871func (logger * Logger ) Fdebugln (w io.Writer , a ... any ) {
868- logger .echo (w , level .Debug , formatStrLn , a ... )
872+ logger .echo (w , level .Debug , formatPrintln , a ... )
869873}
870874
871875// Debug creates message with Debug level, using the default formats
872876// for its operands and writes to log.Writer. Spaces are added between
873877// operands when neither is a string.
874878func (logger * Logger ) Debug (a ... any ) {
875- logger .echo (nil , level .Debug , formatStr , a ... )
879+ logger .echo (nil , level .Debug , formatPrint , a ... )
876880}
877881
878882// Debugf creates message with Debug level, according to a format specifier
@@ -886,14 +890,14 @@ func (logger *Logger) Debugf(format string, a ...any) {
886890// for its operands and writes to log.Writer. Spaces are always added
887891// between operands and a newline is appended.
888892func (logger * Logger ) Debugln (a ... any ) {
889- logger .echo (nil , level .Debug , formatStrLn , a ... )
893+ logger .echo (nil , level .Debug , formatPrintln , a ... )
890894}
891895
892896// Ftrace creates message with Trace level, using the default formats
893897// for its operands and writes to w. Spaces are added between operands
894898// when neither is a string.
895899func (logger * Logger ) Ftrace (w io.Writer , a ... any ) {
896- logger .echo (w , level .Trace , formatStr , a ... )
900+ logger .echo (w , level .Trace , formatPrint , a ... )
897901}
898902
899903// Ftracef creates message with Trace level, according to a format
@@ -906,14 +910,14 @@ func (logger *Logger) Ftracef(w io.Writer, format string, a ...any) {
906910// for its operands and writes to w. Spaces are always added between
907911// operands and a newline is appended.
908912func (logger * Logger ) Ftraceln (w io.Writer , a ... any ) {
909- logger .echo (w , level .Trace , formatStrLn , a ... )
913+ logger .echo (w , level .Trace , formatPrintln , a ... )
910914}
911915
912916// Trace creates message with Trace level, using the default formats
913917// for its operands and writes to log.Writer. Spaces are added between
914918// operands when neither is a string.
915919func (logger * Logger ) Trace (a ... any ) {
916- logger .echo (nil , level .Trace , formatStr , a ... )
920+ logger .echo (nil , level .Trace , formatPrint , a ... )
917921}
918922
919923// Tracef creates message with Trace level, according to a format specifier
@@ -926,5 +930,5 @@ func (logger *Logger) Tracef(format string, a ...any) {
926930// for its operands and writes to log.Writer. Spaces are always added
927931// between operands and a newline is appended.
928932func (logger * Logger ) Traceln (a ... any ) {
929- logger .echo (nil , level .Trace , formatStrLn , a ... )
933+ logger .echo (nil , level .Trace , formatPrintln , a ... )
930934}
0 commit comments