git.iko.soy/typeable/pandoc
on master help sign in
Added --log option to save log messages in JSON format to a file.

See #3392.

commita6c649cfc8a591d0157b7bc89f34c6ef51a9ca27 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 11 Feb 2017, 09:59 (10 years ago) parente0d21db
3 files changed+20−17
MANUAL.txt+6 pandoc.cabal+2−17 src/Text/Pandoc/App.hs+12
MANUAL.txt+6
@@ -356,6 +356,12 @@ General options
356356
357357: Exit with error status if there are any warnings.
358358
359+`--log=`*FILE*
360+
361+: Write log messages in machine-readable JSON format to
362+ *FILE*. All messages above DEBUG level will be written,
363+ regardless of verbosity settings (`--verbose`, `--quiet`).
364+
359365`--list-input-formats`
360366
361367: List supported input formats, one per line.
pandoc.cabal+2−17
@@ -275,6 +275,7 @@ Library
275275 extensible-exceptions >= 0.1 && < 0.2,
276276 pandoc-types >= 1.17 && < 1.18,
277277 aeson >= 0.7 && < 1.2,
278+ aeson-pretty >= 0.8 && < 0.9,
278279 tagsoup >= 0.13.7 && < 0.15,
279280 base64-bytestring >= 0.1 && < 1.1,
280281 zlib >= 0.5 && < 0.7,
@@ -435,23 +436,7 @@ Library
435436
436437Executable pandoc
437438 Build-Depends: pandoc,
438− pandoc-types >= 1.17 && < 1.18,
439− base >= 4.2 && <5,
440− directory >= 1.2 && < 1.4,
441− filepath >= 1.1 && < 1.5,
442− text >= 0.11 && < 1.3,
443− bytestring >= 0.9 && < 0.11,
444− extensible-exceptions >= 0.1 && < 0.2,
445− skylighting >= 0.1.1.3 && < 0.2,
446− aeson >= 0.7.0.5 && < 1.2,
447− yaml >= 0.8.8.2 && < 0.9,
448− containers >= 0.1 && < 0.6,
449− HTTP >= 4000.0.5 && < 4000.4,
450− mtl >= 2.2 && < 2.3
451− if flag(network-uri)
452− Build-Depends: network-uri >= 2.6 && < 2.7, network >= 2.6
453− else
454− Build-Depends: network >= 2 && < 2.6
439+ base >= 4.2 && < 5
455440 Ghc-Options: -rtsopts -with-rtsopts=-K16m -Wall -fno-warn-unused-do-bind
456441 Ghc-Prof-Options: -fprof-auto-exported -rtsopts -with-rtsopts=-K16m
457442
src/Text/Pandoc/App.hs+12
@@ -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