|
2 | 2 |
|
3 | 3 | {- |
|
4 | 4 | Module : Colog.Core.Severity
|
5 |
| -Copyright : (c) 2018-2020 Kowainik, 2021 Co-Log |
| 5 | +Copyright : (c) 2018-2020 Kowainik, 2021-2022 Co-Log |
6 | 6 | SPDX-License-Identifier : MPL-2.0
|
7 | 7 | Maintainer : Co-Log <[email protected]>
|
8 | 8 | Stability : Stable
|
@@ -114,26 +114,32 @@ It is common to want to log various types of messages tagged with a severity.
|
114 | 114 | It is easy to 'cmap' over a 'LogAction m (WithSeverity a)', or to filter based on the severity.
|
115 | 115 |
|
116 | 116 | @
|
117 |
| -logSomething :: LogAction m (WithSeverity String) -> m () |
118 |
| -logSomething logger = logger <& "hello" `WithSeverity` Info |
| 117 | +logSomething :: 'LogAction' m ('WithSeverity' 'String') -> m () |
| 118 | +logSomething logger = logger <& "hello" \`WithSeverity\` 'Info' |
119 | 119 |
|
120 |
| -cmap' :: (b -> a) -> LogAction m (WithSeverity a) -> LogAction m (WithSeverity b) |
121 |
| -cmap' f action = cmap (fmap f) action |
| 120 | +cmap' :: (b -> a) -> 'LogAction' m ('WithSeverity' a) -> 'LogAction' m ('WithSeverity' b) |
| 121 | +cmap' f action = 'cmap' ('fmap' f) action |
122 | 122 |
|
123 |
| -filterBySeverity' :: (Applicative m) => Severity -> LogAction m (WithSeverity a) -> LogAction m (WithSeverity a) |
124 |
| -filterBySeverity' threshold action = filterBySeverity threshold getSeverity action |
| 123 | +filterBySeverity' :: ('Applicative' m) => 'Severity' -> 'LogAction' m ('WithSeverity' a) -> 'LogAction' m ('WithSeverity' a) |
| 124 | +filterBySeverity' threshold action = 'filterBySeverity' threshold 'getSeverity' action |
125 | 125 | @
|
| 126 | +
|
| 127 | +@since 0.3.1.0 |
126 | 128 | -}
|
127 | 129 | data WithSeverity msg = WithSeverity { getMsg :: msg , getSeverity :: Severity }
|
128 | 130 | deriving stock (Show, Eq, Ord, Functor, Foldable, Traversable)
|
129 | 131 |
|
130 | 132 | {- | Map the given function over the severity of a 'WithSeverity'.
|
131 | 133 |
|
132 | 134 | This can be useful to operate generically over the severity, for example:
|
| 135 | +
|
133 | 136 | @
|
134 |
| -suppressErrors :: LogAction m (WithSeverity msg) -> LogAction m (WithSeverity msg) |
135 |
| -suppressErrors = cmap (mapSeverity (\s -> if s == Error then Warning else s)) |
| 137 | +suppressErrors :: 'LogAction' m ('WithSeverity' msg) -> 'LogAction' m ('WithSeverity' msg) |
| 138 | +suppressErrors = 'cmap' ('mapSeverity' (\s -> if s == 'Error' then 'Warning' else s)) |
136 | 139 | @
|
| 140 | +
|
| 141 | +@since 0.3.1.0 |
137 | 142 | -}
|
138 | 143 | mapSeverity :: (Severity -> Severity) -> WithSeverity msg -> WithSeverity msg
|
139 | 144 | mapSeverity f (WithSeverity msg sev) = WithSeverity msg (f sev)
|
| 145 | +{-# INLINE mapSeverity #-} |
0 commit comments