Move logs to Text module

pull/24/head
Bram 2024-05-28 16:46:33 +02:00
parent 2b9370f0c2
commit 7fcef60ec6
8 changed files with 87 additions and 57 deletions

View File

@ -15,6 +15,7 @@ import Internal.Api.Chain as C
import Internal.Api.Request as R import Internal.Api.Request as R
import Internal.Config.Leaks as L import Internal.Config.Leaks as L
import Internal.Config.Log exposing (log) import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Values.Context as Context import Internal.Values.Context as Context
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
@ -29,13 +30,7 @@ baseUrl data =
{ logHttp = { logHttp =
\r -> \r ->
( E.HttpRequest r ( E.HttpRequest r
, String.concat , Text.logs.httpRequest r.method r.url
-- TODO: Move this to Internal.Config.Text module
[ "Matrix HTTP: "
, r.method
, " "
, r.url
]
|> log.info |> log.info
|> List.singleton |> List.singleton
) )
@ -52,12 +47,7 @@ baseUrl data =
, toUpdate = , toUpdate =
\info -> \info ->
( E.SetBaseUrl info.homeserver.baseUrl ( E.SetBaseUrl info.homeserver.baseUrl
, String.concat , Text.logs.baseUrlFound data.url info.homeserver.baseUrl
[ "Found baseURL of "
, data.url
, " at address "
, info.homeserver.baseUrl
]
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )

View File

@ -15,6 +15,7 @@ retrieve this event e.g. by being a member in the room for this event.
import Internal.Api.Api as A import Internal.Api.Api as A
import Internal.Api.Request as R import Internal.Api.Request as R
import Internal.Config.Log exposing (log) import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Tools.Timestamp as Timestamp import Internal.Tools.Timestamp as Timestamp
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
@ -85,7 +86,7 @@ getEventV1 { eventId, roomId } =
\event -> \event ->
( E.ContentUpdate <| V.MapRoom roomId (Room.AddEvent event) ( E.ContentUpdate <| V.MapRoom roomId (Room.AddEvent event)
, event.eventId , event.eventId
|> (++) "Received event id " |> Text.logs.getEventId
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )
@ -109,7 +110,7 @@ getEventV2 { eventId, roomId } =
\event -> \event ->
( E.ContentUpdate <| V.MapRoom roomId (Room.AddEvent event) ( E.ContentUpdate <| V.MapRoom roomId (Room.AddEvent event)
, event.eventId , event.eventId
|> (++) "Received event id " |> Text.logs.getEventId
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )

View File

@ -21,6 +21,7 @@ event to the room.
import Internal.Api.Api as A import Internal.Api.Api as A
import Internal.Api.Request as R import Internal.Api.Request as R
import Internal.Config.Log exposing (log) import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
import Internal.Values.Room as Room import Internal.Values.Room as Room
@ -95,13 +96,7 @@ inviteV1 { roomId, user } =
, toUpdate = , toUpdate =
always always
( E.ContentUpdate <| V.MapRoom roomId (Room.Invite user) ( E.ContentUpdate <| V.MapRoom roomId (Room.Invite user)
, String.concat , Text.logs.invitedUser (User.toString user) roomId
-- TODO: Move to Internal.Config.Text
[ "Invited user "
, User.toString user
, " to room "
, roomId
]
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )
@ -125,13 +120,7 @@ inviteV2 { reason, roomId, user } =
, toUpdate = , toUpdate =
always always
( E.ContentUpdate <| V.MapRoom roomId (Room.Invite user) ( E.ContentUpdate <| V.MapRoom roomId (Room.Invite user)
, String.concat , Text.logs.invitedUser (User.toString user) roomId
-- TODO: Move to Internal.Config.Text
[ "Invited user "
, User.toString user
, " to room "
, roomId
]
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )

View File

@ -14,6 +14,8 @@ This module allows the user to log in using a username and password.
import Internal.Api.Api as A import Internal.Api.Api as A
import Internal.Api.Request as R import Internal.Api.Request as R
import Internal.Config.Leaks as L import Internal.Config.Leaks as L
import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Values.Context as Context import Internal.Values.Context as Context
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
@ -192,7 +194,9 @@ loginWithUsernameAndPasswordV1 { username, password } =
|> Maybe.map (V.SetUser >> E.ContentUpdate) |> Maybe.map (V.SetUser >> E.ContentUpdate)
|> E.Optional |> E.Optional
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context
@ -234,7 +238,9 @@ loginWithUsernameAndPasswordV2 { deviceId, initialDeviceDisplayName, username, p
|> Maybe.map E.SetDeviceId |> Maybe.map E.SetDeviceId
|> E.Optional |> E.Optional
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context
@ -283,7 +289,9 @@ loginWithUsernameAndPasswordV3 { deviceId, initialDeviceDisplayName, username, p
|> Maybe.map E.SetDeviceId |> Maybe.map E.SetDeviceId
|> E.Optional |> E.Optional
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context
@ -336,7 +344,9 @@ loginWithUsernameAndPasswordV4 { deviceId, initialDeviceDisplayName, username, p
|> Maybe.map E.SetDeviceId |> Maybe.map E.SetDeviceId
|> E.Optional |> E.Optional
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context
@ -389,7 +399,9 @@ loginWithUsernameAndPasswordV5 { deviceId, initialDeviceDisplayName, username, p
|> Maybe.map E.SetDeviceId |> Maybe.map E.SetDeviceId
|> E.Optional |> E.Optional
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context
@ -443,7 +455,9 @@ loginWithUsernameAndPasswordV6 { deviceId, enableRefreshToken, initialDeviceDisp
|> Maybe.map E.SetDeviceId |> Maybe.map E.SetDeviceId
|> E.Optional |> E.Optional
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context
@ -493,7 +507,9 @@ loginWithUsernameAndPasswordV7 { deviceId, enableRefreshToken, initialDeviceDisp
|> E.Optional |> E.Optional
, E.SetDeviceId out.deviceId , E.SetDeviceId out.deviceId
] ]
, [] , Text.logs.loggedInAs username
|> log.debug
|> List.singleton
) )
} }
context context

View File

@ -13,6 +13,7 @@ Get the current time.
import Internal.Api.Api as A import Internal.Api.Api as A
import Internal.Config.Log exposing (log) import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text
import Internal.Values.Context as Context import Internal.Values.Context as Context
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
import Task import Task
@ -28,10 +29,9 @@ getNow =
(\now -> (\now ->
{ messages = [ E.SetNow now ] { messages = [ E.SetNow now ]
, logs = , logs =
[ "Identified current time at Unix time " now
, now |> Time.posixToMillis |> String.fromInt |> Time.posixToMillis
] |> Text.logs.getNow
|> String.concat
|> log.debug |> log.debug
|> List.singleton |> List.singleton
, contextChange = Context.setNow now , contextChange = Context.setNow now

View File

@ -309,22 +309,22 @@ getBody attributes =
Nothing -> Nothing ->
case case
List.filterMap List.filterMap
(\attr -> (\attr ->
case attr of case attr of
BodyParam key value -> BodyParam key value ->
Just ( key, value ) Just ( key, value )
_ -> _ ->
Nothing Nothing
) )
attributes attributes
of of
[] -> [] ->
Nothing Nothing
head :: tail -> head :: tail ->
Just <| E.object (head :: tail) Just <| E.object (head :: tail)
) )
getHeaders : List ContextAttr -> List Http.Header getHeaders : List ContextAttr -> List Http.Header

View File

@ -15,6 +15,7 @@ import Internal.Api.Api as A
import Internal.Api.Request as R import Internal.Api.Request as R
import Internal.Config.Leaks as L import Internal.Config.Leaks as L
import Internal.Config.Log exposing (log) import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
@ -93,9 +94,7 @@ sendMessageEventV1 { content, eventType, roomId, transactionId } =
\out -> \out ->
( E.More [] ( E.More []
, out.eventId , out.eventId
|> Maybe.map ((++) ", received event id ") |> Text.logs.sendEvent
|> Maybe.withDefault ""
|> (++) "Sent event"
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )
@ -114,7 +113,8 @@ sendMessageEventV2 { content, eventType, roomId, transactionId } =
\out -> \out ->
( E.More [] ( E.More []
, out.eventId , out.eventId
|> (++) "Sent event, received event id " |> Maybe.Just
|> Text.logs.sendEvent
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )
@ -133,7 +133,8 @@ sendMessageEventV3 { content, eventType, roomId, transactionId } =
\out -> \out ->
( E.More [] ( E.More []
, out.eventId , out.eventId
|> (++) "Sent event, received event id " |> Maybe.Just
|> Text.logs.sendEvent
|> log.debug |> log.debug
|> List.singleton |> List.singleton
) )
@ -178,7 +179,7 @@ coderV2 =
, description = , description =
[ "This endpoint is used to send a message event to a room. Message events allow access to historical events and pagination, making them suited for \"once-off\" activity in a room." [ "This endpoint is used to send a message event to a room. Message events allow access to historical events and pagination, making them suited for \"once-off\" activity in a room."
, "The body of the request should be the content object of the event; the fields in this object will vary depending on the type of event." , "The body of the request should be the content object of the event; the fields in this object will vary depending on the type of event."
, "https://spec.matrix.org/legacy/r0.0.0/client_server.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid" , "https://spec.matrix.org/legacy/client_server/r0.6.1.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid"
] ]
, init = always SendMessageEventOutputV2 , init = always SendMessageEventOutputV2
} }

View File

@ -545,18 +545,51 @@ happened. Most of these unexpected results, are taken account of by the Elm SDK,
but logged so that the programmer can do something about it. but logged so that the programmer can do something about it.
-} -}
logs : logs :
{ keyIsNotAnInt : String -> String { baseUrlFound : String -> String -> String
, getEventId : String -> String
, getNow : Int -> String
, httpRequest : String -> String -> String
, invitedUser : String -> String -> String
, keyIsNotAnInt : String -> String
, loggedInAs : String -> String
, sendEvent : Maybe String -> String
, serverReturnedInvalidJSON : String -> String , serverReturnedInvalidJSON : String -> String
, serverReturnedUnknownJSON : String -> String , serverReturnedUnknownJSON : String -> String
} }
logs = logs =
{ keyIsNotAnInt = { baseUrlFound =
\url baseUrl ->
String.concat [ "Found baseURL of ", url, " at address ", baseUrl ]
, getEventId = (++) "Received event with id = "
, getNow =
\now ->
String.concat
[ "Identified current time at Unix time "
, String.fromInt now
]
, httpRequest =
\method url -> String.concat [ "Matrix HTTP: ", method, " ", url ]
, invitedUser =
\userId roomId ->
String.concat [ "Invited user ", userId, " to room ", roomId ]
, keyIsNotAnInt =
\key -> \key ->
String.concat String.concat
[ "Encountered a key `" [ "Encountered a key `"
, key , key
, "` that cannot be converted to an Int" , "` that cannot be converted to an Int"
] ]
, loggedInAs =
\username ->
String.concat [ "Successfully logged in as user ", username ]
, sendEvent =
\eventId ->
case eventId of
Just e ->
"Sent event, received event id " ++ e
Nothing ->
"Sent event, event id not known - make sure to check transaction id"
, serverReturnedInvalidJSON = (++) "The server returned invalid JSON: " , serverReturnedInvalidJSON = (++) "The server returned invalid JSON: "
, serverReturnedUnknownJSON = (++) "The server returned JSON that doesn't seem to live up to spec rules: " , serverReturnedUnknownJSON = (++) "The server returned JSON that doesn't seem to live up to spec rules: "
} }