/**
 * Created by Wayne Carter.
 *
 * Copyright (c) 2012 Couchbase, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package com.couchbase.lite.util;

import com.couchbase.lite.Database;

import java.io.InputStream;

public class LoggerFactory {

    public static Logger createLogger() {

        String classname = "";
        String resource = "services/com.couchbase.lite.util.Logger";

        try {
            InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
            if (inputStream == null) {
                // Return default System logger.
                Log.d(Database.TAG, "Unable to load %s. Falling back to SystemLogger", resource);
                return new SystemLogger();
            }
            byte[] bytes = TextUtils.read(inputStream);
            classname = new String(bytes);
            if (classname == null || classname.isEmpty()) {
                // Return default System logger.
                Log.d(Database.TAG, "Unable to load %s. Falling back to SystemLogger", resource);
                return new SystemLogger();
            }
            Log.v(Database.TAG, "Loading logger: %s", classname);
            Class clazz = Class.forName(classname);
            Logger logger = (Logger) clazz.newInstance();
            return logger;
        } catch (Exception e) {
            throw new RuntimeException("Failed to logger.  Resource: " + resource + " classname: " + classname, e);
        }


    }
}

@@ -1278,33 +1278,64 @@
 );%0A            %7D
+ else %7B
 %0A
+              try %7B%0A    
             byte
@@ -1386,16 +1386,20 @@
         
+    
 classnam
@@ -1421,16 +1421,20 @@
 bytes);%0A
+    
         
@@ -1493,32 +1493,36 @@
                 
+  
+  
 // Return defaul
@@ -1530,32 +1530,36 @@
  System logger.%0A
+    
                 
@@ -1648,32 +1648,36 @@
                 
+    
 return new Syste
@@ -1699,18 +1699,26 @@
         
+ 
-%7D%0A
+   %7D%0A    
         
@@ -1787,16 +1787,20 @@
         
+   
+ 
 Class cl
@@ -1823,32 +1823,36 @@
 ame(classname);%0A
+    
             Logg
@@ -1901,24 +1901,28 @@
             
+    
 return logge
@@ -1924,16 +1924,109 @@
 logger;%0A
+              %7D finally %7B%0A                inputStream.close();%0A              %7D%0A            %7D%0A
         

fix Android CloseGuard error message