git.iko.soy/typeable/pandoc
on master help sign in
Logging: export logMessagesToJSON.

Use a deterministic order for fields.

commit92a5445aa1a0f9d6ff76c2dd97fd742033ff84ce authorJohn MacFarlane <jgm@berkeley.edu> dateSat 11 Feb 2017, 20:13 (10 years ago) parenta6c649c
2 files changed+12−2
src/Text/Pandoc/App.hs+2−2 src/Text/Pandoc/Logging.hs+10
src/Text/Pandoc/App.hs+2−2
@@ -71,12 +71,12 @@ import qualified Data.ByteString.Lazy as B
7171import qualified Data.ByteString as BS
7272import qualified Data.Map as M
7373import Data.Aeson (eitherDecode', encode)
74−import Data.Aeson.Encode.Pretty (encodePretty)
7574import Data.Yaml (decode)
7675import qualified Data.Yaml as Yaml
7776import qualified Data.Text as T
7877import System.Console.GetOpt
7978import Text.Pandoc.Class (withMediaBag, PandocIO, getLog)
79+import Text.Pandoc.Logging (logMessagesToJSON)
8080import Paths_pandoc (getDataDir)
8181#ifndef _WINDOWS
8282import System.Posix.Terminal (queryTerminal)
@@ -351,7 +351,7 @@ convertWithOpts opts = do
351351 return (x, rs)
352352 case optLogFile opts of
353353 Nothing -> return ()
354− Just logfile -> B.writeFile logfile (encodePretty reports)
354+ Just logfile -> B.writeFile logfile (logMessagesToJSON reports)
355355 let isWarning msg = messageVerbosity msg == WARNING
356356 when (optFailIfWarnings opts && any isWarning reports) $
357357 err 3 "Failing because there were warnings."
src/Text/Pandoc/Logging.hs+10
@@ -32,6 +32,7 @@ and info messages.
3232module Text.Pandoc.Logging (
3333 Verbosity(..)
3434 , LogMessage(..)
35+ , logMessagesToJSON
3536 , showLogMessage
3637 , messageVerbosity
3738 ) where
@@ -43,6 +44,9 @@ import GHC.Generics (Generic)
4344import qualified Data.Text as Text
4445import Data.Aeson
4546import Text.Pandoc.Definition
47+import Data.Aeson.Encode.Pretty (encodePretty', keyOrder,
48+ defConfig, Config(..))
49+import qualified Data.ByteString.Lazy as BL
4650
4751-- | Verbosity level.
4852data Verbosity = ERROR | WARNING | INFO | DEBUG
@@ -152,6 +156,12 @@ showPos pos = sn ++ "line " ++
152156 then ""
153157 else sourceName pos ++ " "
154158
159+logMessagesToJSON :: [LogMessage] -> BL.ByteString
160+logMessagesToJSON ms =
161+ encodePretty' defConfig{ confCompare =
162+ keyOrder [ "type", "verbosity", "contents", "message", "path",
163+ "source", "line", "column" ] } ms
164+
155165showLogMessage :: LogMessage -> String
156166showLogMessage msg =
157167 case msg of