Skip to content

Commit

Permalink
Fix non-JSON log parsing
Browse files Browse the repository at this point in the history
When implementing support for act logs, we pushed anything that didn't
parse to `trace` level since that stuff seemed _really_ chatty. We
intended to update the UI with a trace toggle (like we have for debug),
but we never go there.

We stopped short of using act in production anyway, so we don't need
that. And the lack of a toggle meant these logs were now just completely
hidden.

While we're in here, we made the prefix parsing a little more robust for
parsing prefixes we see in underlying tools' non-JSON logs too.
  • Loading branch information
pbrisbin committed Sep 27, 2024
1 parent 05b7ed6 commit e4992d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
13 changes: 13 additions & 0 deletions seeds/output/prettier.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{"time":"2024-09-26T22:37:30.596752914Z","level":"info","location":{"package":"restyler-0.2.1.0-DyO5DeMlAdAFZ59Xnx0p0c","module":"Restyler.Setup","file":"src/Restyler/Setup.hs","line":56,"char":3},"message":{"text":"Restyler started","meta":{"owner":"freckle","repo":"megarepo","pull":36608}}}
{"time":"2024-09-26T22:37:30.940962758Z","level":"info","location":{"package":"restyler-0.2.1.0-DyO5DeMlAdAFZ59Xnx0p0c","module":"Restyler.Setup","file":"src/Restyler/Setup.hs","line":89,"char":3},"message":{"text":"Cloning repository"}}
Switched to branch 'pull-36608'
{"time":"2024-09-26T22:38:23.243103975Z","level":"info","location":{"package":"restyler-0.2.1.0-DyO5DeMlAdAFZ59Xnx0p0c","module":"Restyler.RemoteFile","file":"src/Restyler/RemoteFile.hs","line":29,"char":3},"message":{"text":"Fetching remote file","meta":{"path":"/tmp/restylers-stable.yaml"}}}
{"time":"2024-09-26T22:38:24.167226784Z","level":"info","location":{"package":"restyler-0.2.1.0-DyO5DeMlAdAFZ59Xnx0p0c","module":"Restyler.Restyler.Run","file":"src/Restyler/Restyler/Run.hs","line":309,"char":3},"message":{"text":"Restyling","meta":{"restyler":"prettier","run":"1 of 1","style":"RestylerRunStylePathsOverwriteSep"}}}
[error] No parser could be inferred for file: frontend/educator/classroom/ts/math/levels-report/components/report/__snapshots__/diagnostic-report.test.tsx.snap
frontend/educator/classroom/ts/math/levels-report/components/report/diagnostic-report-table/index.tsx 429ms
frontend/educator/classroom/ts/math/levels-report/components/report/diagnostic-report.tsx 188ms
frontend/educator/classroom/ts/math/levels-report/components/report/lll-recommendation-banner.module.scss 47ms
frontend/educator/classroom/ts/math/levels-report/components/report/lll-recommendation-banner.tsx 71ms
{"time":"2024-09-26T22:38:26.208717914Z","level":"warn","location":{"package":"restyler-0.2.1.0-DyO5DeMlAdAFZ59Xnx0p0c","module":"Restyler.App","file":"src/Restyler/App.hs","line":110,"char":46},"message":{"text":"callProcessExitCode","meta":{"command":"docker","arguments":["run","--rm","--net","none","--cap-drop","all","--cpu-shares","128","--memory","512m","--volume","/tmp/restyler-1:/code","restyled/restyler-prettier:v2.6.2","prettier","--write","--","./frontend/educator/classroom/ts/math/levels-report/components/report/__snapshots__/diagnostic-report.test.tsx.snap","./frontend/educator/classroom/ts/math/levels-report/components/report/diagnostic-report-table/index.tsx","./frontend/educator/classroom/ts/math/levels-report/components/report/diagnostic-report.tsx","./frontend/educator/classroom/ts/math/levels-report/components/report/lll-recommendation-banner.module.scss","./frontend/educator/classroom/ts/math/levels-report/components/report/lll-recommendation-banner.tsx"],"exitCode":2}}}
{"time":"2024-09-26T22:38:28.418343801Z","level":"error","location":{"package":"restyler-0.2.1.0-DyO5DeMlAdAFZ59Xnx0p0c","module":"Restyler.Exit","file":"src/Restyler/Exit.hs","line":74,"char":5},"message":{"text":"Exception:\nRestyler prettier exited non-zero (2)\n Error information may be present in debug messages printed above\n\n Help:\n https://github.com/restyled-io/restyled.io/wiki/Common-Errors:-Prettier\n https://prettier.io/docs/en/","meta":{"error":{"description":"a Restyler errored","exitCode":20,"severity":"warning","tag":"restyler"}}}}
{"time":"2024-09-26T22:38:28.952387369Z","level":"info","location":{"package":"main","module":"Main","file":"app/main.hs","line":29,"char":7},"message":{"text":"Restyler done","meta":{"exitCode":20}}}
2 changes: 2 additions & 0 deletions src/Restyled/Development/Seeds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ seedDB = do
restylingOutputGHA <- readSeedOutput "gha1"
restylingOutputGHAPatch <- readSeedOutput "gha-patch"
configErrorOutput1 <- readSeedOutput "config-error1"
prettierErrorOutput <- readSeedOutput "prettier"

seedJob demo 1 now (Just 127) invalidArgumentOutput
seedJob restyled 1 now (Just 0) noDifferencesOutput
seedJob restyled 2 now (Just 0) restylingOutputGHA
seedJob restyled 3 now (Just 0) restylingOutputGHAPatch
seedJob restyler 1 now Nothing restylingOutput
seedJob restyler 2 now (Just 10) configErrorOutput1
seedJob restyler 3 now (Just 2) prettierErrorOutput

Entity discountPlanId _ <-
findOrCreateMarketplacePlan
Expand Down
17 changes: 11 additions & 6 deletions src/Restyled/Models/JobLogLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ fakeLoggedMessage ll =

stripLogLevel :: Text -> (Text, LogLevel)
stripLogLevel content =
maybe (content, LevelOther "trace") getFirst
maybe (content, LevelDebug) getFirst
$ foldMap (fmap First . firstM (`T.stripPrefix` content)) stylePrefixes

stylePrefixes :: [(Text, LogLevel)]
stylePrefixes =
[ ("[Debug] ", LevelDebug)
, ("[Info] ", LevelInfo)
, ("[Warn] ", LevelWarn)
, ("[Error] ", LevelError)
]
mconcat
[ [(p, LevelDebug) | p <- mkPrefixes "Debug"]
, [(p, LevelInfo) | p <- mkPrefixes "Info"]
, [(p, LevelWarn) | p <- mkPrefixes "Warn"]
, [(p, LevelError) | p <- mkPrefixes "Error"]
]
where
mkPrefixes x =
let ps = [x, T.toLower x, "[" <> x <> "]", "[" <> T.toLower x <> "]"]
in map (<> ": ") ps <> map (<> " ") ps <> ps

0 comments on commit e4992d1

Please sign in to comment.