Move logs to Text module
parent
2b9370f0c2
commit
7fcef60ec6
|
@ -15,6 +15,7 @@ import Internal.Api.Chain as C
|
|||
import Internal.Api.Request as R
|
||||
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.Values.Context as Context
|
||||
import Internal.Values.Envelope as E
|
||||
|
@ -29,13 +30,7 @@ baseUrl data =
|
|||
{ logHttp =
|
||||
\r ->
|
||||
( E.HttpRequest r
|
||||
, String.concat
|
||||
-- TODO: Move this to Internal.Config.Text module
|
||||
[ "Matrix HTTP: "
|
||||
, r.method
|
||||
, " "
|
||||
, r.url
|
||||
]
|
||||
, Text.logs.httpRequest r.method r.url
|
||||
|> log.info
|
||||
|> List.singleton
|
||||
)
|
||||
|
@ -52,12 +47,7 @@ baseUrl data =
|
|||
, toUpdate =
|
||||
\info ->
|
||||
( E.SetBaseUrl info.homeserver.baseUrl
|
||||
, String.concat
|
||||
[ "Found baseURL of "
|
||||
, data.url
|
||||
, " at address "
|
||||
, info.homeserver.baseUrl
|
||||
]
|
||||
, Text.logs.baseUrlFound data.url info.homeserver.baseUrl
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
|
|
@ -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.Request as R
|
||||
import Internal.Config.Log exposing (log)
|
||||
import Internal.Config.Text as Text
|
||||
import Internal.Tools.Json as Json
|
||||
import Internal.Tools.Timestamp as Timestamp
|
||||
import Internal.Values.Envelope as E
|
||||
|
@ -85,7 +86,7 @@ getEventV1 { eventId, roomId } =
|
|||
\event ->
|
||||
( E.ContentUpdate <| V.MapRoom roomId (Room.AddEvent event)
|
||||
, event.eventId
|
||||
|> (++) "Received event id "
|
||||
|> Text.logs.getEventId
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
@ -109,7 +110,7 @@ getEventV2 { eventId, roomId } =
|
|||
\event ->
|
||||
( E.ContentUpdate <| V.MapRoom roomId (Room.AddEvent event)
|
||||
, event.eventId
|
||||
|> (++) "Received event id "
|
||||
|> Text.logs.getEventId
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
|
|
@ -21,6 +21,7 @@ event to the room.
|
|||
import Internal.Api.Api as A
|
||||
import Internal.Api.Request as R
|
||||
import Internal.Config.Log exposing (log)
|
||||
import Internal.Config.Text as Text
|
||||
import Internal.Tools.Json as Json
|
||||
import Internal.Values.Envelope as E
|
||||
import Internal.Values.Room as Room
|
||||
|
@ -95,13 +96,7 @@ inviteV1 { roomId, user } =
|
|||
, toUpdate =
|
||||
always
|
||||
( E.ContentUpdate <| V.MapRoom roomId (Room.Invite user)
|
||||
, String.concat
|
||||
-- TODO: Move to Internal.Config.Text
|
||||
[ "Invited user "
|
||||
, User.toString user
|
||||
, " to room "
|
||||
, roomId
|
||||
]
|
||||
, Text.logs.invitedUser (User.toString user) roomId
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
@ -125,13 +120,7 @@ inviteV2 { reason, roomId, user } =
|
|||
, toUpdate =
|
||||
always
|
||||
( E.ContentUpdate <| V.MapRoom roomId (Room.Invite user)
|
||||
, String.concat
|
||||
-- TODO: Move to Internal.Config.Text
|
||||
[ "Invited user "
|
||||
, User.toString user
|
||||
, " to room "
|
||||
, roomId
|
||||
]
|
||||
, Text.logs.invitedUser (User.toString user) roomId
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
|
|
@ -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.Request as R
|
||||
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.Values.Context as Context
|
||||
import Internal.Values.Envelope as E
|
||||
|
@ -192,7 +194,9 @@ loginWithUsernameAndPasswordV1 { username, password } =
|
|||
|> Maybe.map (V.SetUser >> E.ContentUpdate)
|
||||
|> E.Optional
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
@ -234,7 +238,9 @@ loginWithUsernameAndPasswordV2 { deviceId, initialDeviceDisplayName, username, p
|
|||
|> Maybe.map E.SetDeviceId
|
||||
|> E.Optional
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
@ -283,7 +289,9 @@ loginWithUsernameAndPasswordV3 { deviceId, initialDeviceDisplayName, username, p
|
|||
|> Maybe.map E.SetDeviceId
|
||||
|> E.Optional
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
@ -336,7 +344,9 @@ loginWithUsernameAndPasswordV4 { deviceId, initialDeviceDisplayName, username, p
|
|||
|> Maybe.map E.SetDeviceId
|
||||
|> E.Optional
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
@ -389,7 +399,9 @@ loginWithUsernameAndPasswordV5 { deviceId, initialDeviceDisplayName, username, p
|
|||
|> Maybe.map E.SetDeviceId
|
||||
|> E.Optional
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
@ -443,7 +455,9 @@ loginWithUsernameAndPasswordV6 { deviceId, enableRefreshToken, initialDeviceDisp
|
|||
|> Maybe.map E.SetDeviceId
|
||||
|> E.Optional
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
@ -493,7 +507,9 @@ loginWithUsernameAndPasswordV7 { deviceId, enableRefreshToken, initialDeviceDisp
|
|||
|> E.Optional
|
||||
, E.SetDeviceId out.deviceId
|
||||
]
|
||||
, []
|
||||
, Text.logs.loggedInAs username
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
}
|
||||
context
|
||||
|
|
|
@ -13,6 +13,7 @@ Get the current time.
|
|||
|
||||
import Internal.Api.Api as A
|
||||
import Internal.Config.Log exposing (log)
|
||||
import Internal.Config.Text as Text
|
||||
import Internal.Values.Context as Context
|
||||
import Internal.Values.Envelope as E
|
||||
import Task
|
||||
|
@ -28,10 +29,9 @@ getNow =
|
|||
(\now ->
|
||||
{ messages = [ E.SetNow now ]
|
||||
, logs =
|
||||
[ "Identified current time at Unix time "
|
||||
, now |> Time.posixToMillis |> String.fromInt
|
||||
]
|
||||
|> String.concat
|
||||
now
|
||||
|> Time.posixToMillis
|
||||
|> Text.logs.getNow
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
, contextChange = Context.setNow now
|
||||
|
|
|
@ -15,6 +15,7 @@ import Internal.Api.Api as A
|
|||
import Internal.Api.Request as R
|
||||
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.Values.Envelope as E
|
||||
|
||||
|
@ -93,9 +94,7 @@ sendMessageEventV1 { content, eventType, roomId, transactionId } =
|
|||
\out ->
|
||||
( E.More []
|
||||
, out.eventId
|
||||
|> Maybe.map ((++) ", received event id ")
|
||||
|> Maybe.withDefault ""
|
||||
|> (++) "Sent event"
|
||||
|> Text.logs.sendEvent
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
@ -114,7 +113,8 @@ sendMessageEventV2 { content, eventType, roomId, transactionId } =
|
|||
\out ->
|
||||
( E.More []
|
||||
, out.eventId
|
||||
|> (++) "Sent event, received event id "
|
||||
|> Maybe.Just
|
||||
|> Text.logs.sendEvent
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
@ -133,7 +133,8 @@ sendMessageEventV3 { content, eventType, roomId, transactionId } =
|
|||
\out ->
|
||||
( E.More []
|
||||
, out.eventId
|
||||
|> (++) "Sent event, received event id "
|
||||
|> Maybe.Just
|
||||
|> Text.logs.sendEvent
|
||||
|> log.debug
|
||||
|> List.singleton
|
||||
)
|
||||
|
@ -178,7 +179,7 @@ coderV2 =
|
|||
, 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."
|
||||
, "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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
-}
|
||||
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
|
||||
, serverReturnedUnknownJSON : String -> String
|
||||
}
|
||||
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 ->
|
||||
String.concat
|
||||
[ "Encountered a key `"
|
||||
, key
|
||||
, "` 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: "
|
||||
, serverReturnedUnknownJSON = (++) "The server returned JSON that doesn't seem to live up to spec rules: "
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue