I'm using katip for logging. Below is my sample program
module Logger where
import Control.Exception
import Katip
import System.IO
runKatip :: IO ()
runKatip = withKatip app
where app = \le -> runKatipContextT le () "main" logSomething
withKatip :: (LogEnv -> IO a) -> IO a
withKatip app =
bracket createLogEnv closeScribes app
where
createLogEnv = do
logEnv <- initLogEnv "HAuth" "dev"
stdoutScribe <- mkHandleScribe ColorIfTerminal stdout (permitItem InfoS) V2
registerScribe "stdout" stdoutScribe defaultScribeSettings logEnv
logSomething :: (KatipContext m) => m ()
logSomething = do
$(logTM) InfoS "Log in no namespace"
katipAddNamespace "ns1" $ (logTM) WarningS "Warning in ns1"
Below is the cabal configuration -
default-extensions: ConstraintKinds
, FlexibleContexts
, NoImplicitPrelude
, OverloadedStrings
, QuasiQuotes
, TemplateHaskell
build-depends: base ^>=4.21.0.0
, katip >= 0.8.8.2
, string-random == 0.1.4.4
, mtl
, data-has
, classy-prelude
, pcre-heavy
, time
, time-lens
hs-source-dirs: src
default-language: GHC2024a
When I do cabal build
, I get below error -
cabal build
Resolving dependencies...
Build profile: -w ghc-9.12.2 -O1
In order, the following will be built (use -v for more details):
- practical-web-dev-ghc-0.1.0.0 (lib) (first run)
- practical-web-dev-ghc-0.1.0.0 (exe:practical-web-dev-ghc) (first run)
Configuring library for practical-web-dev-ghc-0.1.0.0...
Preprocessing library for practical-web-dev-ghc-0.1.0.0...
Building library for practical-web-dev-ghc-0.1.0.0...
[1 of 5] Compiling Domain.Validation ( src/Domain/Validation.hs, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Domain/Validation.o, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Domain/Validation.dyn_o )
[2 of 5] Compiling Domain.Auth ( src/Domain/Auth.hs, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Domain/Auth.o, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Domain/Auth.dyn_o )
[3 of 5] Compiling Adapter.InMemory.Auth ( src/Adapter/InMemory/Auth.hs, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Adapter/InMemory/Auth.o, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Adapter/InMemory/Auth.dyn_o )
[4 of 5] Compiling Logger ( src/Logger.hs, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Logger.o, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/Logger.dyn_o )
src/Logger.hs:24:27: error: [GHC-88464]
Variable not in scope: ($) :: (m0 a0 -> m0 a0) -> m1 () -> m ()
|
24 | katipAddNamespace "ns1" $
| ^
[5 of 5] Compiling MyLib ( src/MyLib.hs, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/MyLib.o, dist-newstyle/build/aarch64-osx/ghc-9.12.2/practical-web-dev-ghc-0.1.0.0/build/MyLib.dyn_o )
Error: [Cabal-7125]
Failed to build practical-web-dev-ghc-0.1.0.0 (which is required by exe:practical-web-dev-ghc from practical-web-dev-ghc-0.1.0.0).
I'm not sure why $
is not found.
Note: The haskell version I'm using is
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.12.2
This is example from Practical Web Development with Haskell and the project is in github here
Because it is defined in the Prelude
or Data.Function
, just like a lot of functions. But you run it with NoImplicitPrelude
, so it does not import the Prelude
.
You can import it explicitly with:
import Prelude(($))
at the top of the file.