git.iko.soy/typeable/pandoc
on master help sign in
Logging: export logMessagesToJSON.
92a5445John MacFarlane
src/Text/Pandoc/App.hs+2−2
@@ -71,12 +71,12 @@ import qualified Data.ByteString.Lazy as B
71import qualified Data.ByteString as BS
71import qualified Data.ByteString as BS
72import qualified Data.Map as M
72import qualified Data.Map as M
73import Data.Aeson (eitherDecode', encode)
73import Data.Aeson (eitherDecode', encode)
74−import Data.Aeson.Encode.Pretty (encodePretty)
75import Data.Yaml (decode)
74import Data.Yaml (decode)
76import qualified Data.Yaml as Yaml
75import qualified Data.Yaml as Yaml
77import qualified Data.Text as T
76import qualified Data.Text as T
78import System.Console.GetOpt
77import System.Console.GetOpt
79import Text.Pandoc.Class (withMediaBag, PandocIO, getLog)
78import Text.Pandoc.Class (withMediaBag, PandocIO, getLog)
79+import Text.Pandoc.Logging (logMessagesToJSON)
80import Paths_pandoc (getDataDir)
80import Paths_pandoc (getDataDir)
81#ifndef _WINDOWS
81#ifndef _WINDOWS
82import System.Posix.Terminal (queryTerminal)
82import System.Posix.Terminal (queryTerminal)
@@ -351,7 +351,7 @@ convertWithOpts opts = do
351 return (x, rs)
351 return (x, rs)
352 case optLogFile opts of
352 case optLogFile opts of
353 Nothing -> return ()
353 Nothing -> return ()
354− Just logfile -> B.writeFile logfile (encodePretty reports)
354+ Just logfile -> B.writeFile logfile (logMessagesToJSON reports)
355 let isWarning msg = messageVerbosity msg == WARNING
355 let isWarning msg = messageVerbosity msg == WARNING
356 when (optFailIfWarnings opts && any isWarning reports) $
356 when (optFailIfWarnings opts && any isWarning reports) $
357 err 3 "Failing because there were warnings."
357 err 3 "Failing because there were warnings."
src/Text/Pandoc/Logging.hs+10
@@ -32,6 +32,7 @@ and info messages.
32module Text.Pandoc.Logging (
32module Text.Pandoc.Logging (
33 Verbosity(..)
33 Verbosity(..)
34 , LogMessage(..)
34 , LogMessage(..)
35+ , logMessagesToJSON
35 , showLogMessage
36 , showLogMessage
36 , messageVerbosity
37 , messageVerbosity
37 ) where
38 ) where
@@ -43,6 +44,9 @@ import GHC.Generics (Generic)
43import qualified Data.Text as Text
44import qualified Data.Text as Text
44import Data.Aeson
45import Data.Aeson
45import Text.Pandoc.Definition
46import Text.Pandoc.Definition
47+import Data.Aeson.Encode.Pretty (encodePretty', keyOrder,
48+ defConfig, Config(..))
49+import qualified Data.ByteString.Lazy as BL
46
50
47-- | Verbosity level.
51-- | Verbosity level.
48data Verbosity = ERROR | WARNING | INFO | DEBUG
52data Verbosity = ERROR | WARNING | INFO | DEBUG
@@ -152,6 +156,12 @@ showPos pos = sn ++ "line " ++
152 then ""
156 then ""
153 else sourceName pos ++ " "
157 else sourceName pos ++ " "
154
158
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+
155showLogMessage :: LogMessage -> String
165showLogMessage :: LogMessage -> String
156showLogMessage msg =
166showLogMessage msg =
157 case msg of
167 case msg of