Fix offset of severity
This commit is contained in:
parent
a6d4703bcd
commit
d522dbaf4f
11
package.yaml
11
package.yaml
@ -46,6 +46,17 @@ ghc-options:
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
tests:
|
||||
ris-utils-test:
|
||||
main: Spec.hs
|
||||
source-dirs: tests
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- ris-utils
|
||||
|
||||
default-extensions:
|
||||
- BangPatterns
|
||||
- BlockArguments
|
||||
|
||||
@ -67,3 +67,54 @@ library
|
||||
, torsor ==0.1.*
|
||||
, unliftio ==0.2.*
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite ris-utils-test
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
other-modules:
|
||||
Paths_ris_utils
|
||||
hs-source-dirs:
|
||||
tests
|
||||
default-extensions:
|
||||
BangPatterns
|
||||
BlockArguments
|
||||
ConstraintKinds
|
||||
DataKinds
|
||||
DeriveAnyClass
|
||||
DeriveGeneric
|
||||
DuplicateRecordFields
|
||||
FlexibleContexts
|
||||
FlexibleInstances
|
||||
GADTs
|
||||
LambdaCase
|
||||
MultiParamTypeClasses
|
||||
OverloadedLabels
|
||||
OverloadedStrings
|
||||
PolyKinds
|
||||
QuasiQuotes
|
||||
RankNTypes
|
||||
ScopedTypeVariables
|
||||
TemplateHaskell
|
||||
TupleSections
|
||||
TypeApplications
|
||||
TypeFamilies
|
||||
TypeOperators
|
||||
UndecidableInstances
|
||||
StandaloneDeriving
|
||||
ImportQualifiedPost
|
||||
LambdaCase
|
||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends:
|
||||
base >=4.7 && <5
|
||||
, bytestring ==0.11.*
|
||||
, chronos >=1.1.5 && <2
|
||||
, co-log-core ==0.3.*
|
||||
, effectful >=2.2.2.0 && <3
|
||||
, effectful-core >=2.2.2.0 && <3
|
||||
, effectful-th ==1.*
|
||||
, ris-utils
|
||||
, string-conv ==0.2.*
|
||||
, text ==2.*
|
||||
, torsor ==0.1.*
|
||||
, unliftio ==0.2.*
|
||||
default-language: Haskell2010
|
||||
|
||||
@ -18,7 +18,7 @@ module Effects.Log (
|
||||
import Colog.Core
|
||||
import Data.String (IsString (..))
|
||||
import Data.String.Conv
|
||||
import Data.Text (Text, justifyLeft)
|
||||
import Data.Text (Text)
|
||||
import Data.Text qualified as T
|
||||
import Data.Text.IO qualified as T
|
||||
import Data.Text.Lazy qualified as LT
|
||||
@ -82,11 +82,14 @@ stderrLogger =
|
||||
)
|
||||
|
||||
fmtMessage :: WithSeverity LogData -> LogData
|
||||
fmtMessage (WithSeverity txt sev) = "[" <> ls (justifyLeft 7 ' ' (colorSev sev)) <> "] - " <> txt
|
||||
fmtMessage (WithSeverity txt sev) =
|
||||
let sp = T.pack $ replicate (7 - length (show sev)) ' '
|
||||
in "[" <> ls (colorSev sev <> sp) <> "] - " <> txt
|
||||
where
|
||||
colorSev :: Severity -> Text
|
||||
colorSev I = colorNormal Green . tshow $ I
|
||||
colorSev W = colorNormal Yellow . tshow $ W
|
||||
colorSev E = colorBright Red . tshow $ E
|
||||
colorSev E = colorNormal Red . tshow $ E
|
||||
colorSev a = tshow a
|
||||
|
||||
addTime ::
|
||||
|
||||
18
tests/Spec.hs
Normal file
18
tests/Spec.hs
Normal file
@ -0,0 +1,18 @@
|
||||
import Colog.Core
|
||||
import Data.Text qualified as T
|
||||
import Data.Text.Lazy qualified as LT
|
||||
import Data.Text.Lazy.Builder qualified as T
|
||||
import Effects.Log
|
||||
|
||||
gen :: String -> Severity -> String
|
||||
gen str sev =
|
||||
let (LogData d) = fmtMessage $ ls (T.pack str) `WithSeverity` sev
|
||||
in T.unpack . LT.toStrict . T.toLazyText $ d
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn " "
|
||||
putStrLn $ gen "Test debug" D
|
||||
putStrLn $ gen "Test info" I
|
||||
putStrLn $ gen "Test warn" W
|
||||
putStrLn $ gen "Test error" E
|
||||
Loading…
Reference in New Issue
Block a user