@@ -67,19 +67,21 @@ const (
67
67
// to the JSON block); printf - \n is appended to the JSON block* and the
68
68
// message format matches the specified user format.
69
69
//
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.
74
74
//
75
75
// * JSON block is the final text representation of the logger in
76
76
// JSON format written as text.
77
77
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 $}"
80
81
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 $}"
83
85
)
84
86
85
87
var (
@@ -147,6 +149,8 @@ type Output struct {
147
149
// The name must sound like a variable name in most programming languages:
148
150
// it must have special characters, not start with a number, etc.
149
151
// 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).
150
154
Name string
151
155
152
156
// Writer is the point where the login data will be output,
@@ -440,7 +444,7 @@ func (logger *Logger) SetOutputs(outputs ...Output) error {
440
444
// The name must be specified.
441
445
if g .IsEmpty (o .Name ) {
442
446
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 ) {
444
448
return fmt .Errorf ("the %d output has incorrect name '%s'" ,
445
449
i , o .Name )
446
450
}
@@ -640,7 +644,7 @@ func (logger *Logger) echo(w io.Writer, l level.Level, f string, a ...any) {
640
644
// for its operands and writes to w. Spaces are added between operands
641
645
// when neither is a string.
642
646
func (logger * Logger ) Fpanic (w io.Writer , a ... any ) {
643
- logger .echo (w , level .Panic , formatStr , a ... )
647
+ logger .echo (w , level .Panic , formatPrint , a ... )
644
648
panic (fmt .Sprint (a ... ))
645
649
}
646
650
@@ -655,15 +659,15 @@ func (logger *Logger) Fpanicf(w io.Writer, format string, a ...any) {
655
659
// for its operands and writes to w. Spaces are always added between
656
660
// operands and a newline is appended.
657
661
func (logger * Logger ) Fpanicln (w io.Writer , a ... any ) {
658
- logger .echo (w , level .Panic , formatStrLn , a ... )
662
+ logger .echo (w , level .Panic , formatPrintln , a ... )
659
663
panic (fmt .Sprintln (a ... ))
660
664
}
661
665
662
666
// Panic creates message with Panic level, using the default formats
663
667
// for its operands and writes to log.Writer. Spaces are added between
664
668
// operands when neither is a string.
665
669
func (logger * Logger ) Panic (a ... any ) {
666
- logger .echo (nil , level .Panic , formatStr , a ... )
670
+ logger .echo (nil , level .Panic , formatPrint , a ... )
667
671
panic (fmt .Sprint (a ... ))
668
672
}
669
673
@@ -678,15 +682,15 @@ func (logger *Logger) Panicf(format string, a ...any) {
678
682
// for its operands and writes to log.Writer. Spaces are always added
679
683
// between operands and a newline is appended.
680
684
func (logger * Logger ) Panicln (a ... any ) (int , error ) {
681
- logger .echo (nil , level .Panic , formatStrLn , a ... )
685
+ logger .echo (nil , level .Panic , formatPrintln , a ... )
682
686
panic (fmt .Sprintln (a ... ))
683
687
}
684
688
685
689
// Ffatal creates message with Fatal level, using the default formats
686
690
// for its operands and writes to w. Spaces are added between operands
687
691
// when neither is a string.
688
692
func (logger * Logger ) Ffatal (w io.Writer , a ... any ) {
689
- logger .echo (w , level .Fatal , formatStr , a ... )
693
+ logger .echo (w , level .Fatal , formatPrint , a ... )
690
694
exit (logger .fatalStatusCode )
691
695
}
692
696
@@ -701,15 +705,15 @@ func (logger *Logger) Ffatalf(w io.Writer, format string, a ...any) {
701
705
// for its operands and writes to w. Spaces are always added between
702
706
// operands and a newline is appended.
703
707
func (logger * Logger ) Ffatalln (w io.Writer , a ... any ) {
704
- logger .echo (w , level .Fatal , formatStrLn , a ... )
708
+ logger .echo (w , level .Fatal , formatPrintln , a ... )
705
709
exit (logger .fatalStatusCode )
706
710
}
707
711
708
712
// Fatal creates message with Fatal level, using the default formats
709
713
// for its operands and writes to log.Writer. Spaces are added between
710
714
// operands when neither is a string.
711
715
func (logger * Logger ) Fatal (a ... any ) {
712
- logger .echo (nil , level .Fatal , formatStr , a ... )
716
+ logger .echo (nil , level .Fatal , formatPrint , a ... )
713
717
exit (logger .fatalStatusCode )
714
718
}
715
719
@@ -724,15 +728,15 @@ func (logger *Logger) Fatalf(format string, a ...any) {
724
728
// for its operands and writes to log.Writer. Spaces are always added
725
729
// between operands and a newline is appended.
726
730
func (logger * Logger ) Fatalln (a ... any ) {
727
- logger .echo (nil , level .Fatal , formatStrLn , a ... )
731
+ logger .echo (nil , level .Fatal , formatPrintln , a ... )
728
732
exit (logger .fatalStatusCode )
729
733
}
730
734
731
735
// Ferror creates message with Error level, using the default formats
732
736
// for its operands and writes to w. Spaces are added between operands
733
737
// when neither is a string.
734
738
func (logger * Logger ) Ferror (w io.Writer , a ... any ) {
735
- logger .echo (w , level .Error , formatStr , a ... )
739
+ logger .echo (w , level .Error , formatPrint , a ... )
736
740
}
737
741
738
742
// 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) {
745
749
// for its operands and writes to w. Spaces are always added between
746
750
// operands and a newline is appended.
747
751
func (logger * Logger ) Ferrorln (w io.Writer , a ... any ) {
748
- logger .echo (w , level .Error , formatStrLn , a ... )
752
+ logger .echo (w , level .Error , formatPrintln , a ... )
749
753
}
750
754
751
755
// Error creates message with Error level, using the default formats
752
756
// for its operands and writes to log.Writer. Spaces are added between
753
757
// operands when neither is a string.
754
758
func (logger * Logger ) Error (a ... any ) {
755
- logger .echo (nil , level .Error , formatStr , a ... )
759
+ logger .echo (nil , level .Error , formatPrint , a ... )
756
760
}
757
761
758
762
// Errorf creates message with Error level, according to a format specifier
@@ -765,14 +769,14 @@ func (logger *Logger) Errorf(f string, a ...any) {
765
769
// for its operands and writes to log.Writer. Spaces are always added
766
770
// between operands and a newline is appended.
767
771
func (logger * Logger ) Errorln (a ... any ) {
768
- logger .echo (nil , level .Error , formatStrLn , a ... )
772
+ logger .echo (nil , level .Error , formatPrintln , a ... )
769
773
}
770
774
771
775
// Fwarn creates message with Warn level, using the default formats
772
776
// for its operands and writes to w. Spaces are added between operands
773
777
// when neither is a string.
774
778
func (logger * Logger ) Fwarn (w io.Writer , a ... any ) {
775
- logger .echo (w , level .Warn , formatStr , a ... )
779
+ logger .echo (w , level .Warn , formatPrint , a ... )
776
780
}
777
781
778
782
// 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) {
785
789
// for its operands and writes to w. Spaces are always added between
786
790
// operands and a newline is appended.
787
791
func (logger * Logger ) Fwarnln (w io.Writer , a ... any ) {
788
- logger .echo (w , level .Warn , formatStrLn , a ... )
792
+ logger .echo (w , level .Warn , formatPrintln , a ... )
789
793
}
790
794
791
795
// Warn creates message with Warn level, using the default formats
792
796
// for its operands and writes to log.Writer. Spaces are added between
793
797
// operands when neither is a string.
794
798
func (logger * Logger ) Warn (a ... any ) {
795
- logger .echo (nil , level .Warn , formatStr , a ... )
799
+ logger .echo (nil , level .Warn , formatPrint , a ... )
796
800
}
797
801
798
802
// Warnf creates message with Warn level, according to a format specifier
@@ -805,14 +809,14 @@ func (logger *Logger) Warnf(format string, a ...any) {
805
809
// for its operands and writes to log.Writer. Spaces are always added
806
810
// between operands and a newline is appended.
807
811
func (logger * Logger ) Warnln (a ... any ) {
808
- logger .echo (nil , level .Warn , formatStrLn , a ... )
812
+ logger .echo (nil , level .Warn , formatPrintln , a ... )
809
813
}
810
814
811
815
// Finfo creates message with Info level, using the default formats
812
816
// for its operands and writes to w. Spaces are added between operands
813
817
// when neither is a string.
814
818
func (logger * Logger ) Finfo (w io.Writer , a ... any ) {
815
- logger .echo (w , level .Info , formatStr , a ... )
819
+ logger .echo (w , level .Info , formatPrint , a ... )
816
820
}
817
821
818
822
// 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) {
825
829
// for its operands and writes to w. Spaces are always added between
826
830
// operands and a newline is appended.
827
831
func (logger * Logger ) Finfoln (w io.Writer , a ... any ) {
828
- logger .echo (w , level .Info , formatStrLn , a ... )
832
+ logger .echo (w , level .Info , formatPrintln , a ... )
829
833
}
830
834
831
835
// Info creates message with Info level, using the default formats
832
836
// for its operands and writes to log.Writer. Spaces are added between
833
837
// operands when neither is a string.
834
838
func (logger * Logger ) Info (a ... any ) {
835
- logger .echo (nil , level .Info , formatStr , a ... )
839
+ logger .echo (nil , level .Info , formatPrint , a ... )
836
840
}
837
841
838
842
// Infof creates message with Info level, according to a format specifier
@@ -845,14 +849,14 @@ func (logger *Logger) Infof(format string, a ...any) {
845
849
// for its operands and writes to log.Writer. Spaces are always added
846
850
// between operands and a newline is appended.
847
851
func (logger * Logger ) Infoln (a ... any ) {
848
- logger .echo (nil , level .Info , formatStrLn , a ... )
852
+ logger .echo (nil , level .Info , formatPrintln , a ... )
849
853
}
850
854
851
855
// Fdebug creates message with Debug level, using the default formats
852
856
// for its operands and writes to w. Spaces are added between operands
853
857
// when neither is a string.
854
858
func (logger * Logger ) Fdebug (w io.Writer , a ... any ) {
855
- logger .echo (w , level .Debug , formatStr , a ... )
859
+ logger .echo (w , level .Debug , formatPrint , a ... )
856
860
}
857
861
858
862
// 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) {
865
869
// for its operands and writes to w. Spaces are always added between
866
870
// operands and a newline is appended.
867
871
func (logger * Logger ) Fdebugln (w io.Writer , a ... any ) {
868
- logger .echo (w , level .Debug , formatStrLn , a ... )
872
+ logger .echo (w , level .Debug , formatPrintln , a ... )
869
873
}
870
874
871
875
// Debug creates message with Debug level, using the default formats
872
876
// for its operands and writes to log.Writer. Spaces are added between
873
877
// operands when neither is a string.
874
878
func (logger * Logger ) Debug (a ... any ) {
875
- logger .echo (nil , level .Debug , formatStr , a ... )
879
+ logger .echo (nil , level .Debug , formatPrint , a ... )
876
880
}
877
881
878
882
// Debugf creates message with Debug level, according to a format specifier
@@ -886,14 +890,14 @@ func (logger *Logger) Debugf(format string, a ...any) {
886
890
// for its operands and writes to log.Writer. Spaces are always added
887
891
// between operands and a newline is appended.
888
892
func (logger * Logger ) Debugln (a ... any ) {
889
- logger .echo (nil , level .Debug , formatStrLn , a ... )
893
+ logger .echo (nil , level .Debug , formatPrintln , a ... )
890
894
}
891
895
892
896
// Ftrace creates message with Trace level, using the default formats
893
897
// for its operands and writes to w. Spaces are added between operands
894
898
// when neither is a string.
895
899
func (logger * Logger ) Ftrace (w io.Writer , a ... any ) {
896
- logger .echo (w , level .Trace , formatStr , a ... )
900
+ logger .echo (w , level .Trace , formatPrint , a ... )
897
901
}
898
902
899
903
// 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) {
906
910
// for its operands and writes to w. Spaces are always added between
907
911
// operands and a newline is appended.
908
912
func (logger * Logger ) Ftraceln (w io.Writer , a ... any ) {
909
- logger .echo (w , level .Trace , formatStrLn , a ... )
913
+ logger .echo (w , level .Trace , formatPrintln , a ... )
910
914
}
911
915
912
916
// Trace creates message with Trace level, using the default formats
913
917
// for its operands and writes to log.Writer. Spaces are added between
914
918
// operands when neither is a string.
915
919
func (logger * Logger ) Trace (a ... any ) {
916
- logger .echo (nil , level .Trace , formatStr , a ... )
920
+ logger .echo (nil , level .Trace , formatPrint , a ... )
917
921
}
918
922
919
923
// Tracef creates message with Trace level, according to a format specifier
@@ -926,5 +930,5 @@ func (logger *Logger) Tracef(format string, a ...any) {
926
930
// for its operands and writes to log.Writer. Spaces are always added
927
931
// between operands and a newline is appended.
928
932
func (logger * Logger ) Traceln (a ... any ) {
929
- logger .echo (nil , level .Trace , formatStrLn , a ... )
933
+ logger .echo (nil , level .Trace , formatPrintln , a ... )
930
934
}
0 commit comments