@@ -55,70 +55,41 @@ displayWithColor x = do
5555
5656-- TODO: switch to using implicit callstacks once 7.8 support is dropped
5757
58- prettyDebug :: Q Exp
59- prettyDebug = do
58+ prettyWith :: LogLevel -> ExpQ -> Q Exp
59+ prettyWith level f = do
6060 loc <- location
61- [e | monadLoggerLog loc "" LevelDebug <=< displayWithColor |]
62-
63- prettyInfo :: Q Exp
64- prettyInfo = do
65- loc <- location
66- [e | monadLoggerLog loc "" LevelInfo <=< displayWithColor |]
67-
68- prettyWarn :: Q Exp
69- prettyWarn = do
70- loc <- location
71- [e | monadLoggerLog loc "" LevelWarn <=< displayWithColor . (line <>) . (warningColor "Warning:" <+>) . indentAfterLabel |]
72-
73- prettyError :: Q Exp
74- prettyError = do
75- loc <- location
76- [e | monadLoggerLog loc "" LevelError <=< displayWithColor . (line <>) . (errorColor "Error:" <+>) . indentAfterLabel |]
77-
78- -- TODO: Figure out how to collapse these to use the same implementation
79- -- as the above ones!
80-
81- prettyDebugL :: Q Exp
82- prettyDebugL = do
83- loc <- location
84- [e | monadLoggerLog loc "" LevelDebug <=< displayWithColor . fillSep|]
85-
86- prettyInfoL :: Q Exp
87- prettyInfoL = do
88- loc <- location
89- [e | monadLoggerLog loc "" LevelInfo <=< displayWithColor . fillSep|]
90-
91- prettyWarnL :: Q Exp
92- prettyWarnL = do
93- loc <- location
94- [e | monadLoggerLog loc "" LevelWarn <=< displayWithColor . (line <>) . (warningColor "Warning:" <+>) . indentAfterLabel . fillSep|]
95-
96- prettyErrorL :: Q Exp
97- prettyErrorL = do
98- loc <- location
99- [e | monadLoggerLog loc "" LevelError <=< displayWithColor . (line <>) . (errorColor "Error:" <+>) . indentAfterLabel . fillSep|]
100-
101- prettyDebugS :: Q Exp
102- prettyDebugS = do
103- loc <- location
104- [e | monadLoggerLog loc "" LevelDebug <=< displayWithColor . flow|]
105-
106- prettyInfoS :: Q Exp
107- prettyInfoS = do
108- loc <- location
109- [e | monadLoggerLog loc "" LevelInfo <=< displayWithColor . flow|]
110-
111- prettyWarnS :: Q Exp
112- prettyWarnS = do
113- loc <- location
114- [e | monadLoggerLog loc "" LevelWarn <=< displayWithColor . (line <>) . (warningColor "Warning:" <+>) . indentAfterLabel . flow|]
115-
116- prettyErrorS :: Q Exp
117- prettyErrorS = do
118- loc <- location
119- [e | monadLoggerLog loc "" LevelError <=< displayWithColor . (line <>) . (errorColor "Error:" <+>) . indentAfterLabel . flow|]
120-
121- -- End of duplicates
61+ [e | monadLoggerLog loc "" level <=< displayWithColor . $f |]
62+
63+ -- Note: I think keeping this section aligned helps spot errors, might be
64+ -- worth keeping the alignment in place.
65+ prettyDebugWith , prettyInfoWith , prettyWarnWith , prettyErrorWith :: ExpQ -> Q Exp
66+ prettyDebugWith = prettyWith LevelDebug
67+ prettyInfoWith = prettyWith LevelInfo
68+ prettyWarnWith f = prettyWith LevelWarn
69+ [| (line <> ) . (warningColor " Warning:" <+> ) .
70+ indentAfterLabel . $ f | ]
71+ prettyErrorWith f = prettyWith LevelError
72+ [| (line <> ) . (errorColor " Error:" <+> ) .
73+ indentAfterLabel . $ f | ]
74+
75+ prettyDebug , prettyInfo , prettyWarn , prettyError :: Q Exp
76+ prettyDebug = prettyDebugWith [| id | ]
77+ prettyInfo = prettyInfoWith [| id | ]
78+ prettyWarn = prettyWarnWith [| id | ]
79+ prettyError = prettyErrorWith [| id | ]
80+
81+ prettyDebugL , prettyInfoL , prettyWarnL , prettyErrorL :: Q Exp
82+ prettyDebugL = prettyDebugWith [| fillSep | ]
83+ prettyInfoL = prettyInfoWith [| fillSep | ]
84+ prettyWarnL = prettyWarnWith [| fillSep | ]
85+ prettyErrorL = prettyErrorWith [| fillSep | ]
86+
87+ prettyDebugS , prettyInfoS , prettyWarnS , prettyErrorS :: Q Exp
88+ prettyDebugS = prettyDebugWith [| flow | ]
89+ prettyInfoS = prettyInfoWith [| flow | ]
90+ prettyWarnS = prettyWarnWith [| flow | ]
91+ prettyErrorS = prettyErrorWith [| flow | ]
92+ -- End of aligned section
12293
12394indentAfterLabel :: Doc a -> Doc a
12495indentAfterLabel = align
0 commit comments