@@ -71,6 +71,7 @@ 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)
7475import Data.Yaml (decode)
7576import qualified Data.Yaml as Yaml
7677import qualified Data.Text as T
@@ -348,6 +349,9 @@ convertWithOpts opts = do
348349 x <- f
349350 rs <- getLog
350351 return (x, rs)
352+ case optLogFile opts of
353+ Nothing -> return ()
354+ Just logfile -> B.writeFile logfile (encodePretty reports)
351355 let isWarning msg = messageVerbosity msg == WARNING
352356 when (optFailIfWarnings opts && any isWarning reports) $
353357 err 3 "Failing because there were warnings."
@@ -487,6 +491,7 @@ data Opt = Opt
487491 , optDumpArgs :: Bool -- ^ Output command-line arguments
488492 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
489493 , optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
494+ , optLogFile :: Maybe FilePath -- ^ File to write JSON log output
490495 , optFailIfWarnings :: Bool -- ^ Fail on warnings
491496 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
492497 , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
@@ -552,6 +557,7 @@ defaultOpts = Opt
552557 , optDumpArgs = False
553558 , optIgnoreArgs = False
554559 , optVerbosity = WARNING
560+ , optLogFile = Nothing
555561 , optFailIfWarnings = False
556562 , optReferenceLinks = False
557563 , optReferenceLocation = EndOfDocument
@@ -1289,6 +1295,12 @@ options =
12891295 (\opt -> return opt { optFailIfWarnings = True }))
12901296 "" -- "Exit with error status if there were warnings."
12911297
1298+ , Option "" ["log"]
1299+ (ReqArg
1300+ (\arg opt -> return opt{ optLogFile = Just arg })
1301+ "FILE")
1302+ "" -- "Log messages in JSON format to this file."
1303+
12921304 , Option "" ["bash-completion"]
12931305 (NoArg
12941306 (\_ -> do