summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-11 20:13:33 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-11 20:13:33 +0100
commit92a5445aa1a0f9d6ff76c2dd97fd742033ff84ce (patch)
tree4b1451204885ca0db0861e9aaed65be2aa714cdb /src/Text
parenta6c649cfc8a591d0157b7bc89f34c6ef51a9ca27 (diff)
Logging: export logMessagesToJSON.
Use a deterministic order for fields.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/App.hs4
-rw-r--r--src/Text/Pandoc/Logging.hs10
2 files changed, 12 insertions, 2 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index df1ed9fde..e4e47c1bf 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -71,12 +71,12 @@ import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString as BS
import qualified Data.Map as M
import Data.Aeson (eitherDecode', encode)
-import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Yaml (decode)
import qualified Data.Yaml as Yaml
import qualified Data.Text as T
import System.Console.GetOpt
import Text.Pandoc.Class (withMediaBag, PandocIO, getLog)
+import Text.Pandoc.Logging (logMessagesToJSON)
import Paths_pandoc (getDataDir)
#ifndef _WINDOWS
import System.Posix.Terminal (queryTerminal)
@@ -351,7 +351,7 @@ convertWithOpts opts = do
return (x, rs)
case optLogFile opts of
Nothing -> return ()
- Just logfile -> B.writeFile logfile (encodePretty reports)
+ Just logfile -> B.writeFile logfile (logMessagesToJSON reports)
let isWarning msg = messageVerbosity msg == WARNING
when (optFailIfWarnings opts && any isWarning reports) $
err 3 "Failing because there were warnings."
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