@@ -71,6 +71,7 @@ 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)
74import Data.Yaml (decode)
75import Data.Yaml (decode)
75import qualified Data.Yaml as Yaml
76import qualified Data.Yaml as Yaml
76import qualified Data.Text as T
77import qualified Data.Text as T
@@ -348,6 +349,9 @@ convertWithOpts opts = do
349 rs <- getLog
350 rs <- getLog
350 return (x, rs)
351 return (x, rs)
352+ case optLogFile opts of
353+ Nothing -> return ()
354+ Just logfile -> B.writeFile logfile (encodePretty reports)
351 let isWarning msg = messageVerbosity msg == WARNING
355 let isWarning msg = messageVerbosity msg == WARNING
352 when (optFailIfWarnings opts && any isWarning reports) $
356 when (optFailIfWarnings opts && any isWarning reports) $
353 err 3 "Failing because there were warnings."
357 err 3 "Failing because there were warnings."
@@ -487,6 +491,7 @@ data Opt = Opt
487 , optDumpArgs :: Bool -- ^ Output command-line arguments
491 , optDumpArgs :: Bool -- ^ Output command-line arguments
488 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
492 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
489 , optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
493 , optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
494+ , optLogFile :: Maybe FilePath -- ^ File to write JSON log output
490 , optFailIfWarnings :: Bool -- ^ Fail on warnings
495 , optFailIfWarnings :: Bool -- ^ Fail on warnings
491 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
496 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
492 , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
497 , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
@@ -552,6 +557,7 @@ defaultOpts = Opt
552 , optDumpArgs = False
557 , optDumpArgs = False
553 , optIgnoreArgs = False
558 , optIgnoreArgs = False
554 , optVerbosity = WARNING
559 , optVerbosity = WARNING
560+ , optLogFile = Nothing
555 , optFailIfWarnings = False
561 , optFailIfWarnings = False
556 , optReferenceLinks = False
562 , optReferenceLinks = False
557 , optReferenceLocation = EndOfDocument
563 , optReferenceLocation = EndOfDocument
@@ -1289,6 +1295,12 @@ options =
1289 (\opt -> return opt { optFailIfWarnings = True }))
1295 (\opt -> return opt { optFailIfWarnings = True }))
1290 "" -- "Exit with error status if there were warnings."
1296 "" -- "Exit with error status if there were warnings."
1298+ , Option "" ["log"]
1300+ (\arg opt -> return opt{ optLogFile = Just arg })
1302+ "" -- "Log messages in JSON format to this file."
1292 , Option "" ["bash-completion"]
1304 , Option "" ["bash-completion"]
1294 (\_ -> do
1306 (\_ -> do