You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/04/23 12:44:27 UTC

[GitHub] bdelacretaz closed pull request #1: SLING-7611 - Switch to slf4j

bdelacretaz closed pull request #1: SLING-7611 - Switch to slf4j
URL: https://github.com/apache/sling-org-apache-sling-commons-mime/pull/1
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
index 914390f..e7a7e14 100644
--- a/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.PrintStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Dictionary;
@@ -43,10 +42,11 @@
 import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.osgi.service.component.annotations.ReferencePolicy;
-import org.osgi.service.log.LogService;
 import org.osgi.service.metatype.annotations.AttributeDefinition;
 import org.osgi.service.metatype.annotations.Designate;
 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The <code>MimeTypeServiceImpl</code> is the official implementation of the
@@ -63,7 +63,7 @@
     public static final String CORE_MIME_TYPES = "/META-INF/core_mime.types";
 
     public static final String MIME_TYPES = "/META-INF/mime.types";
-
+    
     @ObjectClassDefinition(name = "Apache Sling MIME Type Service",
             description = "The Sling MIME Type Service provides support for " +
                 "maintaining and configuring MIME Type mappings.")
@@ -80,9 +80,8 @@
         String[] mime_types();
     }
 
-    @Reference(cardinality=ReferenceCardinality.OPTIONAL, policy=ReferencePolicy.DYNAMIC)
-    private volatile LogService logService;
-
+    private Logger log = LoggerFactory.getLogger(this.getClass());
+    
     private Map<String, String> mimeTab = new HashMap<>();
 
     private Map<String, String> extensionMap = new HashMap<>();
@@ -152,8 +151,8 @@ public void registerMimeType(String mimeType, String... extensions) {
                 String oldMimeType = mimeTab.get(extension);
                 if (oldMimeType == null) {
 
-                    log(LogService.LOG_DEBUG, "registerMimeType: Add mapping "
-                        + extension + "=" + mimeType, null);
+                    log.debug("registerMimeType: Add mapping "
+                        + extension + "=" + mimeType);
 
                     this.mimeTab.put(extension, mimeType);
 
@@ -163,10 +162,10 @@ public void registerMimeType(String mimeType, String... extensions) {
 
                 } else {
 
-                    log(LogService.LOG_INFO,
+                    log.info(
                         "registerMimeType: Ignoring mapping " + extension + "="
                             + mimeType + ": Mapping " + extension + "="
-                            + oldMimeType + " already exists", null);
+                            + oldMimeType + " already exists");
 
                 }
 
@@ -272,7 +271,7 @@ public void bundleChanged(BundleEvent event) {
             try {
                 this.registerMimeType(event.getBundle().getEntry(MIME_TYPES));
             } catch (IllegalStateException ie) {
-                log(LogService.LOG_INFO, "bundleChanged: an issue while registering the mime type occurred", null);
+                log.info("bundleChanged: an issue while registering the mime type occurred");
             }
         }
     }
@@ -310,7 +309,7 @@ private void registerMimeType(URL mimetypes) {
                 this.registerMimeType(ins);
             } catch (IOException ioe) {
                 // log but don't actually care
-                this.log(LogService.LOG_WARNING, "An error occurred reading "
+                log.warn("An error occurred reading "
                     + mimetypes, ioe);
             } finally {
                 if (ins != null) {
@@ -340,19 +339,4 @@ private void registerMimeType(String line) {
         }
     }
 
-    private void log(int level, String message, Throwable t) {
-        LogService log = this.logService;
-        if (log != null) {
-            log.log(level, message, t);
-        } else {
-            PrintStream out = (level == LogService.LOG_ERROR)
-                    ? System.err
-                    : System.out;
-            out.println(message);
-            if (t != null) {
-                t.printStackTrace(out);
-            }
-        }
-    }
-
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services