@@ -132,6 +132,8 @@ app.post("/", async (c) => {
132132 */
133133app . post ( "/:incidentId/logs" , async ( c ) => {
134134 const incidentId = c . req . param ( "incidentId" ) ;
135+ logger . info ( { incidentId } , "[incident-logs] POST /:incidentId/logs received" ) ;
136+
135137 let source : string ;
136138 let logCategory : "phoneLogs" | "glassesLogs" | "glassesFirmwareLogs" | null = null ;
137139 let appPackageName : string | null = null ;
@@ -142,9 +144,15 @@ app.post("/:incidentId/logs", async (c) => {
142144 try {
143145 body = await c . req . json ( ) ;
144146 } catch {
147+ logger . warn ( { incidentId } , "[incident-logs] Invalid JSON body" ) ;
145148 return c . json ( { success : false , message : "Invalid JSON body" } , 400 ) ;
146149 }
147150
151+ logger . info (
152+ { incidentId, source : body . source , logsCount : body . logs ?. length } ,
153+ "[incident-logs] Request body parsed (source + logs count)" ,
154+ ) ;
155+
148156 // Validate logs array
149157 if ( ! body . logs || ! Array . isArray ( body . logs ) ) {
150158 return c . json ( { success : false , message : "Invalid payload: logs array required" } , 400 ) ;
@@ -165,6 +173,10 @@ app.post("/:incidentId/logs", async (c) => {
165173 source = body . source || "phone" ;
166174 logCategory =
167175 source === "glasses" ? "glassesLogs" : source === "glasses_firmware" ? "glassesFirmwareLogs" : "phoneLogs" ;
176+ logger . info (
177+ { incidentId, source, logCategory, userEmail } ,
178+ "[incident-logs] CoreToken auth OK — routing to category" ,
179+ ) ;
168180 } catch {
169181 return c . json ( { success : false , message : "Invalid token" } , 401 ) ;
170182 }
@@ -204,11 +216,16 @@ app.post("/:incidentId/logs", async (c) => {
204216 // Check if incident exists and verify ownership
205217 const incident = await Incident . findOne ( { incidentId } ) ;
206218 if ( ! incident ) {
219+ logger . warn ( { incidentId, source : body . source } , "[incident-logs] Incident not found (404)" ) ;
207220 return c . json ( { success : false , message : "Incident not found" } , 404 ) ;
208221 }
209222
210223 // Verify the authenticated user owns this incident
211224 if ( incident . userId !== userEmail ) {
225+ logger . warn (
226+ { incidentId, incidentUserId : incident . userId , tokenUser : userEmail } ,
227+ "[incident-logs] Forbidden: incident owner mismatch (403)" ,
228+ ) ;
212229 return c . json ( { success : false , message : "Forbidden" } , 403 ) ;
213230 }
214231
@@ -218,8 +235,14 @@ app.post("/:incidentId/logs", async (c) => {
218235 // App telemetry - use dedicated method that organizes by package name
219236 await incidentStorage . appendAppTelemetry ( incidentId , appPackageName , body . logs ) ;
220237 } else if ( logCategory ) {
221- // Phone or glasses logs
238+ // Phone or glasses logs (including glasses_firmware)
239+ logger . info (
240+ { incidentId, logCategory, count : body . logs . length } ,
241+ "[incident-logs] Calling appendLogs (phone/glasses/glasses_firmware)" ,
242+ ) ;
222243 await incidentStorage . appendLogs ( incidentId , logCategory , body . logs , source ) ;
244+ } else {
245+ logger . warn ( { incidentId, source : body . source } , "[incident-logs] No logCategory — request not appended" ) ;
223246 }
224247
225248 logger . info (
@@ -235,7 +258,7 @@ app.post("/:incidentId/logs", async (c) => {
235258
236259 return c . json ( { success : true } ) ;
237260 } catch ( err ) {
238- logger . error ( { incidentId, source, err } , "Failed to append logs to incident " ) ;
261+ logger . error ( { incidentId, source : body . source , logCategory , err } , "[incident-logs] Failed to append logs (500) " ) ;
239262 return c . json ( { success : false , message : "Storage error" } , 500 ) ;
240263 }
241264} ) ;
0 commit comments