summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Logging.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Logging.hs')
-rw-r--r--src/Text/Pandoc/Logging.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Logging.hs b/src/Text/Pandoc/Logging.hs
index 8b2b85a45..15b903c05 100644
--- a/src/Text/Pandoc/Logging.hs
+++ b/src/Text/Pandoc/Logging.hs
@@ -32,6 +32,7 @@ and info messages.
module Text.Pandoc.Logging (
Verbosity(..)
, LogMessage(..)
+ , logMessagesToJSON
, showLogMessage
, messageVerbosity
) where
@@ -43,6 +44,9 @@ import GHC.Generics (Generic)
import qualified Data.Text as Text
import Data.Aeson
import Text.Pandoc.Definition
+import Data.Aeson.Encode.Pretty (encodePretty', keyOrder,
+ defConfig, Config(..))
+import qualified Data.ByteString.Lazy as BL
-- | Verbosity level.
data Verbosity = ERROR | WARNING | INFO | DEBUG
@@ -152,6 +156,12 @@ showPos pos = sn ++ "line " ++
then ""
else sourceName pos ++ " "
+logMessagesToJSON :: [LogMessage] -> BL.ByteString
+logMessagesToJSON ms =
+ encodePretty' defConfig{ confCompare =
+ keyOrder [ "type", "verbosity", "contents", "message", "path",
+ "source", "line", "column" ] } ms
+
showLogMessage :: LogMessage -> String
showLogMessage msg =
case msg of