1717import com .github .stickerifier .stickerify .exception .FileOperationException ;
1818import com .github .stickerifier .stickerify .exception .MediaException ;
1919import com .github .stickerifier .stickerify .exception .ProcessException ;
20+ import com .github .stickerifier .stickerify .logger .StructuredLogger ;
2021import com .github .stickerifier .stickerify .process .OsConstants ;
2122import com .github .stickerifier .stickerify .process .ProcessHelper ;
2223import com .google .gson .Gson ;
2324import com .google .gson .JsonSyntaxException ;
2425import com .google .gson .annotations .SerializedName ;
2526import org .apache .tika .Tika ;
2627import org .jspecify .annotations .Nullable ;
27- import org .slf4j .Logger ;
28- import org .slf4j .LoggerFactory ;
28+ import org .slf4j .event .Level ;
2929
3030import java .io .File ;
3131import java .io .FileInputStream ;
3737
3838public final class MediaHelper {
3939
40- private static final Logger LOGGER = LoggerFactory . getLogger (MediaHelper .class );
40+ private static final StructuredLogger LOGGER = new StructuredLogger (MediaHelper .class );
4141
4242 private static final Tika TIKA = new Tika ();
4343 private static final Gson GSON = new Gson ();
@@ -69,28 +69,28 @@ public final class MediaHelper {
6969 try {
7070 if (isSupportedVideo (mimeType )) {
7171 if (isVideoCompliant (inputFile )) {
72- LOGGER .atInfo ( ).log ("The video doesn't need conversion" );
72+ LOGGER .at ( Level . INFO ).log ("The video doesn't need conversion" );
7373 return null ;
7474 }
7575
7676 return convertToWebm (inputFile );
7777 }
7878
7979 if (isAnimatedStickerCompliant (inputFile , mimeType )) {
80- LOGGER .atInfo ( ).log ("The animated sticker doesn't need conversion" );
80+ LOGGER .at ( Level . INFO ).log ("The animated sticker doesn't need conversion" );
8181 return null ;
8282 }
8383
8484 if (isSupportedImage (inputFile , mimeType )) {
8585 if (isImageCompliant (inputFile , mimeType )) {
86- LOGGER .atInfo ( ).log ("The image doesn't need conversion" );
86+ LOGGER .at ( Level . INFO ).log ("The image doesn't need conversion" );
8787 return null ;
8888 }
8989
9090 return convertToWebp (inputFile );
9191 }
9292 } catch (MediaException e ) {
93- LOGGER .atWarn ( ).setCause (e ).addKeyValue ("mime_type" , mimeType ).log ("The file with {} MIME type could not be converted" , mimeType );
93+ LOGGER .at ( Level . WARN ).setCause (e ).addKeyValue ("mime_type" , mimeType ).log ("The file with {} MIME type could not be converted" , mimeType );
9494 throw e ;
9595 }
9696
@@ -107,11 +107,11 @@ public final class MediaHelper {
107107 private static String detectMimeType (File file ) throws MediaException {
108108 try {
109109 var mimeType = TIKA .detect (file );
110- LOGGER .atDebug ( ).addKeyValue ("mime_type" , mimeType ).log ("MIME type successfully detected" );
110+ LOGGER .at ( Level . DEBUG ).addKeyValue ("mime_type" , mimeType ).log ("MIME type successfully detected" );
111111
112112 return mimeType ;
113113 } catch (IOException e ) {
114- LOGGER .atError ( ).addKeyValue ("file_name" , file .getName ()).log ("Unable to retrieve MIME type" );
114+ LOGGER .at ( Level . ERROR ).addKeyValue ("file_name" , file .getName ()).log ("Unable to retrieve MIME type" );
115115 throw new MediaException (e );
116116 }
117117 }
@@ -241,7 +241,7 @@ private static boolean isAnimatedStickerCompliant(File file, String mimeType) th
241241 try (var gzipInputStream = new GZIPInputStream (new FileInputStream (file ))) {
242242 uncompressedContent = new String (gzipInputStream .readAllBytes (), UTF_8 );
243243 } catch (IOException _) {
244- LOGGER .atError ( ).addKeyValue ("file_name" , file .getName ()).log ("Unable to retrieve gzip content" );
244+ LOGGER .at ( Level . ERROR ).addKeyValue ("file_name" , file .getName ()).log ("Unable to retrieve gzip content" );
245245 }
246246
247247 try {
@@ -255,9 +255,9 @@ private static boolean isAnimatedStickerCompliant(File file, String mimeType) th
255255 }
256256 }
257257
258- LOGGER .atWarn ( ).addKeyValue ("sticker" , sticker ).log ("The animated sticker doesn't meet Telegram's requirements" );
258+ LOGGER .at ( Level . WARN ).addKeyValue ("sticker" , sticker ).log ("The animated sticker doesn't meet Telegram's requirements" );
259259 } catch (JsonSyntaxException _) {
260- LOGGER .atInfo ( ).log ("The archive isn't an animated sticker" );
260+ LOGGER .at ( Level . INFO ).log ("The archive isn't an animated sticker" );
261261 }
262262 }
263263
@@ -305,7 +305,7 @@ private static boolean isAnimationCompliant(@Nullable AnimationDetails animation
305305 */
306306 private static boolean isSupportedImage (File image , String mimeType ) {
307307 if ("image/webp" .equals (mimeType ) && isAnimatedWebp (image )) {
308- LOGGER .atInfo ( ).log ("The image is an animated WebP" );
308+ LOGGER .at ( Level . INFO ).log ("The image is an animated WebP" );
309309 return false ;
310310 }
311311
@@ -331,7 +331,7 @@ private static boolean isAnimatedWebp(File file) {
331331
332332 return isExtendedFormat && hasAnimationFlag ;
333333 } catch (IOException e ) {
334- LOGGER .atWarn ( ).setCause (e ).log ("An error occurred checking if the file is an animated WebP" );
334+ LOGGER .at ( Level . WARN ).setCause (e ).log ("An error occurred checking if the file is an animated WebP" );
335335 return false ;
336336 }
337337 }
@@ -436,7 +436,7 @@ private static File createTempFile(String fileExtension) throws FileOperationExc
436436 private static void deleteFile (File file ) throws FileOperationException {
437437 try {
438438 if (!Files .deleteIfExists (file .toPath ())) {
439- LOGGER .atInfo ( ).addKeyValue ("file_path" , file .toPath ()).log ("Unable to delete file" );
439+ LOGGER .at ( Level . INFO ).addKeyValue ("file_path" , file .toPath ()).log ("Unable to delete file" );
440440 }
441441 } catch (IOException e ) {
442442 throw new FileOperationException ("An error occurred deleting the file" , e );
@@ -485,7 +485,7 @@ private static File convertToWebm(File file) throws MediaException, InterruptedE
485485 try {
486486 deleteFile (new File (logFileName ));
487487 } catch (FileOperationException e ) {
488- LOGGER .atWarn ( ).setCause (e ).addKeyValue ("file_name" , logFileName ).log ("Could not delete log file" );
488+ LOGGER .at ( Level . WARN ).setCause (e ).addKeyValue ("file_name" , logFileName ).log ("Could not delete log file" );
489489 }
490490 }
491491
0 commit comments