Make the logger take a list of properties

This commit is contained in:
Jeroen Engels 2022-11-04 15:12:49 +01:00
parent 689081b035
commit 4710c132d4
4 changed files with 22 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,13 @@
module Review.Logger exposing (Logger, fromFn, log, none)
import Json.Encode as Encode
type Logger
= Logger (String -> String)
= Logger (List ( String, Encode.Value ) -> List ( String, Encode.Value ))
fromFn : (String -> String) -> Logger
fromFn : (List ( String, Encode.Value ) -> List ( String, Encode.Value )) -> Logger
fromFn =
Logger
@ -15,6 +17,6 @@ none =
Logger identity
log : Logger -> String -> a -> a
log : Logger -> List ( String, Encode.Value ) -> a -> a
log (Logger logFn) message data =
always data <| logFn message

View File

@ -24,6 +24,7 @@ process like the CLI.
import Dict exposing (Dict)
import Elm.Syntax.Range exposing (Range)
import Json.Encode as Encode
import Review.Logger as Logger
import Review.Options.Internal as Internal exposing (ReviewOptionsInternal(..))
@ -59,7 +60,7 @@ withDataExtraction extract (ReviewOptionsInternal reviewOptions) =
{-| Add a logger.
-}
withLogger : Maybe (String -> String) -> ReviewOptions -> ReviewOptions
withLogger : Maybe (List ( String, Encode.Value ) -> List ( String, Encode.Value )) -> ReviewOptions -> ReviewOptions
withLogger maybeLogger (ReviewOptionsInternal reviewOptions) =
ReviewOptionsInternal
{ reviewOptions

View File

@ -6143,30 +6143,24 @@ isInSourceDirectories (Metadata metadata) =
-- LOGS
startedRule : String -> String
startedRule : String -> List ( String, Encode.Value )
startedRule name =
Encode.object
[ ( "type", Encode.string "rule-start" )
, ( "ruleName", Encode.string name )
]
|> Encode.encode 0
[ ( "type", Encode.string "rule-start" )
, ( "ruleName", Encode.string name )
]
endedRule : String -> String
endedRule : String -> List ( String, Encode.Value )
endedRule name =
Encode.object
[ ( "type", Encode.string "rule-end" )
, ( "ruleName", Encode.string name )
]
|> Encode.encode 0
[ ( "type", Encode.string "rule-end" )
, ( "ruleName", Encode.string name )
]
fixedError : FixedErrors -> { ruleName : String, filePath : String } -> String
fixedError : FixedErrors -> { ruleName : String, filePath : String } -> List ( String, Encode.Value )
fixedError fixedErrors data =
Encode.object
[ ( "type", Encode.string "apply-fix" )
, ( "ruleName", Encode.string data.ruleName )
, ( "filePath", Encode.string data.filePath )
, ( "count", Encode.int (FixedErrors.count fixedErrors) )
]
|> Encode.encode 0
[ ( "type", Encode.string "apply-fix" )
, ( "ruleName", Encode.string data.ruleName )
, ( "filePath", Encode.string data.filePath )
, ( "count", Encode.int (FixedErrors.count fixedErrors) )
]