Added --log option to save log messages in JSON format to a file.
See #3392.
This commit is contained in:
parent
e0d21dbb82
commit
a6c649cfc8
3 changed files with 20 additions and 17 deletions
|
@ -356,6 +356,12 @@ General options
|
|||
|
||||
: Exit with error status if there are any warnings.
|
||||
|
||||
`--log=`*FILE*
|
||||
|
||||
: Write log messages in machine-readable JSON format to
|
||||
*FILE*. All messages above DEBUG level will be written,
|
||||
regardless of verbosity settings (`--verbose`, `--quiet`).
|
||||
|
||||
`--list-input-formats`
|
||||
|
||||
: List supported input formats, one per line.
|
||||
|
|
19
pandoc.cabal
19
pandoc.cabal
|
@ -275,6 +275,7 @@ Library
|
|||
extensible-exceptions >= 0.1 && < 0.2,
|
||||
pandoc-types >= 1.17 && < 1.18,
|
||||
aeson >= 0.7 && < 1.2,
|
||||
aeson-pretty >= 0.8 && < 0.9,
|
||||
tagsoup >= 0.13.7 && < 0.15,
|
||||
base64-bytestring >= 0.1 && < 1.1,
|
||||
zlib >= 0.5 && < 0.7,
|
||||
|
@ -435,23 +436,7 @@ Library
|
|||
|
||||
Executable pandoc
|
||||
Build-Depends: pandoc,
|
||||
pandoc-types >= 1.17 && < 1.18,
|
||||
base >= 4.2 && <5,
|
||||
directory >= 1.2 && < 1.4,
|
||||
filepath >= 1.1 && < 1.5,
|
||||
text >= 0.11 && < 1.3,
|
||||
bytestring >= 0.9 && < 0.11,
|
||||
extensible-exceptions >= 0.1 && < 0.2,
|
||||
skylighting >= 0.1.1.3 && < 0.2,
|
||||
aeson >= 0.7.0.5 && < 1.2,
|
||||
yaml >= 0.8.8.2 && < 0.9,
|
||||
containers >= 0.1 && < 0.6,
|
||||
HTTP >= 4000.0.5 && < 4000.4,
|
||||
mtl >= 2.2 && < 2.3
|
||||
if flag(network-uri)
|
||||
Build-Depends: network-uri >= 2.6 && < 2.7, network >= 2.6
|
||||
else
|
||||
Build-Depends: network >= 2 && < 2.6
|
||||
base >= 4.2 && < 5
|
||||
Ghc-Options: -rtsopts -with-rtsopts=-K16m -Wall -fno-warn-unused-do-bind
|
||||
Ghc-Prof-Options: -fprof-auto-exported -rtsopts -with-rtsopts=-K16m
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ import qualified Data.ByteString.Lazy as B
|
|||
import qualified Data.ByteString as BS
|
||||
import qualified Data.Map as M
|
||||
import Data.Aeson (eitherDecode', encode)
|
||||
import Data.Aeson.Encode.Pretty (encodePretty)
|
||||
import Data.Yaml (decode)
|
||||
import qualified Data.Yaml as Yaml
|
||||
import qualified Data.Text as T
|
||||
|
@ -348,6 +349,9 @@ convertWithOpts opts = do
|
|||
x <- f
|
||||
rs <- getLog
|
||||
return (x, rs)
|
||||
case optLogFile opts of
|
||||
Nothing -> return ()
|
||||
Just logfile -> B.writeFile logfile (encodePretty reports)
|
||||
let isWarning msg = messageVerbosity msg == WARNING
|
||||
when (optFailIfWarnings opts && any isWarning reports) $
|
||||
err 3 "Failing because there were warnings."
|
||||
|
@ -487,6 +491,7 @@ data Opt = Opt
|
|||
, optDumpArgs :: Bool -- ^ Output command-line arguments
|
||||
, optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
|
||||
, optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
|
||||
, optLogFile :: Maybe FilePath -- ^ File to write JSON log output
|
||||
, optFailIfWarnings :: Bool -- ^ Fail on warnings
|
||||
, optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
|
||||
, optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
|
||||
|
@ -552,6 +557,7 @@ defaultOpts = Opt
|
|||
, optDumpArgs = False
|
||||
, optIgnoreArgs = False
|
||||
, optVerbosity = WARNING
|
||||
, optLogFile = Nothing
|
||||
, optFailIfWarnings = False
|
||||
, optReferenceLinks = False
|
||||
, optReferenceLocation = EndOfDocument
|
||||
|
@ -1289,6 +1295,12 @@ options =
|
|||
(\opt -> return opt { optFailIfWarnings = True }))
|
||||
"" -- "Exit with error status if there were warnings."
|
||||
|
||||
, Option "" ["log"]
|
||||
(ReqArg
|
||||
(\arg opt -> return opt{ optLogFile = Just arg })
|
||||
"FILE")
|
||||
"" -- "Log messages in JSON format to this file."
|
||||
|
||||
, Option "" ["bash-completion"]
|
||||
(NoArg
|
||||
(\_ -> do
|
||||
|
|
Loading…
Add table
Reference in a new issue