cql-io-tinylog (empty) → 0.1.0
raw patch · 4 files changed
+69/−0 lines, 4 filesdep +basedep +bytestringdep +cql-iosetup-changed
Dependencies added: base, bytestring, cql-io, tinylog
Files
- CHANGELOG.md +4/−0
- Setup.hs +2/−0
- cql-io-tinylog.cabal +23/−0
- src/Database/CQL/IO/Tinylog.hs +40/−0
+ CHANGELOG.md view
@@ -0,0 +1,4 @@++## 0.1.0++* First version.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cql-io-tinylog.cabal view
@@ -0,0 +1,23 @@+cabal-version: 2.0++name: cql-io-tinylog+version: 0.1.0+synopsis: Tinylog integration for cql-io.+homepage: https://gitlab.com/romanb/cql-io-tinylog+license: PublicDomain+author: Roman S. Borschel+maintainer: roman@pkaboo.org+category: Database+build-type: Simple+extra-source-files: CHANGELOG.md++library+ exposed-modules: Database.CQL.IO.Tinylog+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall -fwarn-tabs+ build-depends:+ base >= 4.9 && < 5+ , bytestring >= 0.10+ , cql-io >= 1.1+ , tinylog >= 0.14
+ src/Database/CQL/IO/Tinylog.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE OverloadedStrings #-}++module Database.CQL.IO.Tinylog (mkLogger) where++import Data.ByteString.Builder+import Data.ByteString.Lazy (ByteString)+import Database.CQL.IO (Logger (..), LogLevel (..))+import Database.CQL.IO.Hexdump++import qualified Data.ByteString.Lazy as L+import qualified System.Logger as Tiny++-- | Create a cql-io 'Logger' that delegates log messages to+-- the given tinylog 'Tiny.Logger'. Requests and responses are+-- logged on 'Tiny.Trace' level.+mkLogger :: Tiny.Logger -> Logger+mkLogger l = Logger+ { logMessage = tinylogMessage l+ , logRequest = tinylogRequest l+ , logResponse = tinylogResponse l+ }++tinylogMessage :: Tiny.Logger -> LogLevel -> Builder -> IO ()+tinylogMessage l lvl msg = Tiny.log l (level lvl) $+ Tiny.msg (toLazyByteString msg)+ where+ level :: LogLevel -> Tiny.Level+ level LogDebug = Tiny.Debug+ level LogInfo = Tiny.Info+ level LogWarn = Tiny.Warn+ level LogError = Tiny.Error++tinylogRequest :: Tiny.Logger -> ByteString -> IO ()+tinylogRequest l req = Tiny.log l Tiny.Trace $+ Tiny.msg (hexdump (L.take 160 req))++tinylogResponse :: Tiny.Logger -> ByteString -> IO ()+tinylogResponse l rsp = Tiny.log l Tiny.Trace $+ Tiny.msg (hexdump (L.take 160 rsp))+