11package com .github .stickerifier .stickerify .media ;
22
3+ import static com .github .stickerifier .stickerify .logger .StructuredLogger .FILE_PATH_LOG_KEY ;
34import static com .github .stickerifier .stickerify .logger .StructuredLogger .MIME_TYPE ;
5+ import static com .github .stickerifier .stickerify .logger .StructuredLogger .STICKER_LOG_KEY ;
46import static com .github .stickerifier .stickerify .media .MediaConstraints .MATROSKA_FORMAT ;
57import static com .github .stickerifier .stickerify .media .MediaConstraints .MAX_ANIMATION_DURATION_SECONDS ;
68import static com .github .stickerifier .stickerify .media .MediaConstraints .MAX_ANIMATION_FILE_SIZE ;
@@ -81,7 +83,7 @@ private static String detectMimeType(File file) throws MediaException {
8183 try {
8284 return TIKA .detect (file );
8385 } catch (IOException e ) {
84- LOGGER .at (Level .ERROR ).setCause (e ).addKeyValue ("file_name" , file .getName ()).log ("Unable to retrieve MIME type" );
86+ LOGGER .at (Level .ERROR ).setCause (e ).addKeyValue (FILE_PATH_LOG_KEY , file .getPath ()).log ("Unable to retrieve MIME type" );
8587 throw new MediaException (e );
8688 }
8789 }
@@ -253,7 +255,7 @@ private static boolean isAnimatedStickerCompliant(File file, String mimeType) th
253255 try (var gzipInputStream = new GZIPInputStream (new FileInputStream (file ))) {
254256 uncompressedContent = new String (gzipInputStream .readAllBytes (), UTF_8 );
255257 } catch (IOException e ) {
256- LOGGER .at (Level .ERROR ).setCause (e ).addKeyValue ("file_name" , file .getName ()).log ("Unable to retrieve gzip content" );
258+ LOGGER .at (Level .ERROR ).setCause (e ).addKeyValue (FILE_PATH_LOG_KEY , file .getPath ()).log ("Unable to retrieve gzip content" );
257259 }
258260
259261 try {
@@ -267,7 +269,7 @@ private static boolean isAnimatedStickerCompliant(File file, String mimeType) th
267269 }
268270 }
269271
270- LOGGER .at (Level .WARN ).addKeyValue ("sticker" , sticker ).log ("The animated sticker doesn't meet Telegram's requirements" );
272+ LOGGER .at (Level .WARN ).addKeyValue (STICKER_LOG_KEY , sticker ).log ("The animated sticker doesn't meet Telegram's requirements" );
271273 } catch (JsonSyntaxException _) {
272274 LOGGER .at (Level .INFO ).log ("The archive isn't an animated sticker" );
273275 }
@@ -448,7 +450,7 @@ private static File createTempFile(String fileExtension) throws FileOperationExc
448450 private static void deleteFile (File file ) throws FileOperationException {
449451 try {
450452 if (!Files .deleteIfExists (file .toPath ())) {
451- LOGGER .at (Level .INFO ).addKeyValue ("file_path" , file .toPath ()).log ("Unable to delete file" );
453+ LOGGER .at (Level .INFO ).addKeyValue (FILE_PATH_LOG_KEY , file .toPath ()).log ("Unable to delete file" );
452454 }
453455 } catch (IOException e ) {
454456 throw new FileOperationException ("An error occurred deleting the file" , e );
@@ -493,11 +495,11 @@ private static File convertToWebm(File file) throws MediaException, InterruptedE
493495 }
494496 throw new MediaException ("FFmpeg two-pass conversion failed" , e );
495497 } finally {
496- var logFileName = logPrefix + "-0.log" ;
498+ var logFilePath = logPrefix + "-0.log" ;
497499 try {
498- deleteFile (new File (logFileName ));
500+ deleteFile (new File (logFilePath ));
499501 } catch (FileOperationException e ) {
500- LOGGER .at (Level .WARN ).setCause (e ).addKeyValue ("file_name" , logFileName ).log ("Could not delete log file" );
502+ LOGGER .at (Level .WARN ).setCause (e ).addKeyValue (FILE_PATH_LOG_KEY , logFilePath ).log ("Could not delete log file" );
501503 }
502504 }
503505
0 commit comments