Integrated log files(Logger, errLog, FileLogger) related 25/9525/7
authorJung Seungho <shonest.jung@samsung.com>
Thu, 21 Jul 2016 01:25:57 +0000 (10:25 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Thu, 21 Jul 2016 05:51:19 +0000 (05:51 +0000)
Change-Id: I6579edd85593a2fe005767f1ec5fb862e9c7fe9e
Signed-off-by: Jung Seungho <shonest.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9525
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
28 files changed:
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServer.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServerManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/MongoDB.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/OAuthServerFactory.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/token/TokenGenerator.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/token/TokenManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/token/TokenValidator.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/CloudInterfaceServer.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/DeviceServerSystem.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/MessageQueueServer.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/MessageQueueUtils.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaCommonWrapper.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaConsumerWrapper.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaProducerWrapper.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/ResourceDirectoryServer.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/rd/ResourceDirectoryResource.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/res/DiscoveryResource.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/presence/device/DevicePresenceResource.java
cloud/stack/src/main/java/org/iotivity/cloud/base/ServerSystem.java
cloud/stack/src/main/java/org/iotivity/cloud/base/connector/CoapClient.java
cloud/stack/src/main/java/org/iotivity/cloud/base/device/CoapDevice.java
cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/coap/CoapLogHandler.java
cloud/stack/src/main/java/org/iotivity/cloud/base/server/Server.java
cloud/stack/src/main/java/org/iotivity/cloud/util/Cbor.java
cloud/stack/src/main/java/org/iotivity/cloud/util/ErrorLogger.java [deleted file]
cloud/stack/src/main/java/org/iotivity/cloud/util/FileLogger.java [deleted file]
cloud/stack/src/main/java/org/iotivity/cloud/util/Log.java [moved from cloud/stack/src/main/java/org/iotivity/cloud/util/Logger.java with 68% similarity]

index f9c00a9..8bc8039 100644 (file)
@@ -30,9 +30,7 @@ import org.iotivity.cloud.accountserver.resources.account.session.SessionResourc
 import org.iotivity.cloud.accountserver.resources.account.tokenrefresh.TokenRefreshResource;
 import org.iotivity.cloud.base.ServerSystem;
 import org.iotivity.cloud.base.server.CoapServer;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -42,18 +40,16 @@ import org.iotivity.cloud.util.Logger;
 public class AccountServer {
 
     public static void main(String[] args) throws Exception {
-        System.setOut(FileLogger.createLoggingProxy(System.out));
-
+        Log.Init();
+        
         System.out.println("-----Account SERVER-----");
 
         if (args.length != 2) {
-            Logger.e("coap server port and TLS mode required\n"
+            Log.e("coap server port and TLS mode required\n"
                     + "ex) 5685 0\n");
             return;
         }
 
-        ErrorLogger.Init();
-
         ServerSystem serverSystem = new ServerSystem();
 
         serverSystem.addResource(new AccountResource());
index 2214ebc..6a0f62f 100644 (file)
@@ -27,7 +27,7 @@ import org.iotivity.cloud.accountserver.db.AccountDBManager;
 import org.iotivity.cloud.accountserver.oauth.OAuthServerFactory;
 import org.iotivity.cloud.accountserver.token.Token;
 import org.iotivity.cloud.accountserver.token.TokenManager;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -41,7 +41,7 @@ public class AccountServerManager {
 
     /**
      * API for requesting user account
-     * 
+     *
      * @param userId
      *            user identifier
      * @param deviceId
@@ -62,7 +62,7 @@ public class AccountServerManager {
     /**
      * API for requesting user account and getting session code for registered
      * user.
-     * 
+     *
      * @param userId
      *            user identifier
      * @return String - session code for registered user
@@ -86,7 +86,7 @@ public class AccountServerManager {
     /**
      * API for requesting user identifier corresponding with authorization
      * information.
-     * 
+     *
      * @param authCode
      *            authorization code
      * @param authServer
@@ -105,7 +105,7 @@ public class AccountServerManager {
 
     /**
      * API for requesting user identifier corresponding with session code.
-     * 
+     *
      * @param sessionCode
      *            session code
      * @return String - user identifier
@@ -123,14 +123,14 @@ public class AccountServerManager {
 
     /**
      * API for getting devices corresponding with user identifier.
-     * 
+     *
      * @param userId
      *            user identifier
      * @return ArrayList<String> - list of devices
      */
     public ArrayList<String> requestAccountDevices(String userId) {
 
-        Logger.d("userId= " + userId);
+        Log.d("userId= " + userId);
 
         ArrayList<String> deviceList = AccountDBManager.getInstance()
                 .getDevices(userId);
index b86cc8b..6750b56 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Date;
 
 import org.bson.Document;
 import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import com.mongodb.MongoClient;
 import com.mongodb.client.MongoCollection;
@@ -48,7 +48,7 @@ public class MongoDB {
 
     /**
      * API creating MongoClient and initializing MongoDatabase
-     * 
+     *
      * @param dbname
      *            database name to create MongoDatabase
      * @throws Exception
@@ -62,7 +62,7 @@ public class MongoDB {
 
     /**
      * API creating collection
-     * 
+     *
      * @param tableName
      *            collection name
      */
@@ -73,7 +73,7 @@ public class MongoDB {
 
     /**
      * API deleting collection
-     * 
+     *
      * @param tableName
      *            collection name
      */
@@ -84,7 +84,7 @@ public class MongoDB {
 
     /**
      * API getting database object
-     * 
+     *
      */
     public MongoDatabase getMongoDatabase() {
 
@@ -113,7 +113,7 @@ public class MongoDB {
 
     /**
      * API for inserting device information of user
-     * 
+     *
      * @param UserDevice
      *            device information of user
      */
@@ -140,7 +140,7 @@ public class MongoDB {
     /**
      * API for getting user identifier corresponding with session code from
      * database
-     * 
+     *
      * @param sessionCode
      *            session code
      * @return String - user identifier
@@ -206,7 +206,7 @@ public class MongoDB {
 
     /**
      * API for getting devices corresponding with user identifier from database
-     * 
+     *
      * @param userId
      *            user identifier
      */
@@ -297,7 +297,7 @@ public class MongoDB {
             updateResource = true;
 
         } else {
-            Logger.e("UpdateResource failed!");
+            Log.e("UpdateResource failed!");
         }
 
         return updateResource;
@@ -338,42 +338,42 @@ public class MongoDB {
 
         ArrayList<UserDevice> dlist = readDeviceResources();
         int size = dlist.size();
-        
-        Logger.i("[" + Constants.DEVICE_TABLE + "]Table");
+
+        Log.i("[" + Constants.DEVICE_TABLE + "]Table");
         for (int i = 0; i < size; i++) {
 
             UserDevice item = dlist.get(i);
 
-            Logger.i("[" + i + "]" + item.getUserId() + ", "
+            Log.i("[" + i + "]" + item.getUserId() + ", "
                     + item.getDeviceId());
         }
 
         /*
          * ArrayList<UserSession> slist = readSessionResources(); size =
          * slist.size();
-         * 
-         * Logger.i("*Table: " + Constants.SESSION_TABLE);
-         * 
+         *
+         * Log.i("*Table: " + Constants.SESSION_TABLE);
+         *
          * for (int i = 0; i < size; i++) {
-         * 
+         *
          * UserSession item = slist.get(i);
-         * 
-         * Logger.i("[" + i + "]" + item.getUserId() + ", " +
+         *
+         * Log.i("[" + i + "]" + item.getUserId() + ", " +
          * item.getSessionCode());
-         * 
+         *
          * }
          */
 
         ArrayList<UserToken> tlist = readUserTokenResources();
         size = tlist.size();
 
-        Logger.i("[" + Constants.TOKEN_TABLE + "]Table");
+        Log.i("[" + Constants.TOKEN_TABLE + "]Table");
 
         for (int i = 0; i < size; i++) {
 
             UserToken item = tlist.get(i);
 
-            Logger.i("[" + i + "]" + item.getUserId() + "/"
+            Log.i("[" + i + "]" + item.getUserId() + "/"
                     + item.getAccessToken() + "/" + item.getRefreshToken() + "/"
                     + item.getIssuedTime());
 
@@ -417,7 +417,7 @@ public class MongoDB {
         String refreshToken = doc.getString(Constants.KEY_REFRESH_TOKEN);
         String issuedTime = doc.getString(Constants.KEY_ISSUED_TIME);
 
-        // Logger.d("issuedTime: " + issuedTime);
+        // Log.d("issuedTime: " + issuedTime);
         userToken.setUserToken(userId, accessToken, refreshToken);
         userToken.setIssuedTime(issuedTime);
 
index 4f4977b..ee222ee 100644 (file)
@@ -29,7 +29,7 @@ import java.net.URLClassLoader;
 import java.util.HashMap;
 
 import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -53,7 +53,7 @@ public class OAuthServerFactory {
                     .invoke(authServerObj, authCode, authServerUrl);
             String errorMessage = authServerInfo.get(Constants.ERROR_MESSAGE);
             if (errorMessage != null) {
-                Logger.d("Exception Error Message from Auth Server : "
+                Log.d("Exception Error Message from Auth Server : "
                         + errorMessage);
             } else {
                 accessToken = authServerInfo.get(Constants.KEY_ACCESS_TOKEN_GH);
@@ -76,7 +76,7 @@ public class OAuthServerFactory {
                     .invoke(authServerObj, accessToken, apiServerUrl);
             String errorMessage = authServerInfo.get(Constants.ERROR_MESSAGE);
             if (errorMessage != null) {
-                Logger.d("Exception Error Message from Auth Server : "
+                Log.d("Exception Error Message from Auth Server : "
                         + errorMessage);
             } else {
                 userId = authServerInfo.get(Constants.KEY_USER_ID);
@@ -106,7 +106,7 @@ public class OAuthServerFactory {
         try {
             URL urls = new URL("jar:" + jarFile.toURI() + "!/");
 
-            Logger.d("urls: " + urls.toString());
+            Log.d("urls: " + urls.toString());
 
             classLoader = new URLClassLoader(new URL[] { urls });
             Class<?> gitHubClass = classLoader
index 88d7846..3218993 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.base.protocols.enums.ContentFormat;
 import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -100,7 +100,7 @@ public class AccountResource extends Resource {
         String authProvider = payloadData.get(Constants.REQ_AUTH_PROVIDER)
                 .toString();
 
-        Logger.d("authCode: " + authCode);
+        Log.d("authCode: " + authCode);
 
         @SuppressWarnings("unchecked")
         HashMap<String, String> options = (HashMap<String, String>) payloadData
index dcea465..4c4682a 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.oltu.oauth2.as.issuer.MD5Generator;
 import org.apache.oltu.oauth2.as.issuer.OAuthIssuer;
 import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
 import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class TokenGenerator {
 
@@ -38,7 +38,7 @@ public class TokenGenerator {
         try {
 
             accessToken = oauthIssuerImpl.accessToken();
-            Logger.d("accessToken : " + accessToken);
+            Log.d("accessToken : " + accessToken);
 
         } catch (OAuthSystemException e) {
 
@@ -57,7 +57,7 @@ public class TokenGenerator {
         try {
 
             refreshToken = oauthIssuerImpl.refreshToken();
-            Logger.d("refreshToken : " + refreshToken);
+            Log.d("refreshToken : " + refreshToken);
 
         } catch (OAuthSystemException e) {
 
index 3a1676b..50d2421 100644 (file)
@@ -22,7 +22,7 @@
 package org.iotivity.cloud.accountserver.token;
 
 import org.iotivity.cloud.accountserver.db.AccountDBManager;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class TokenManager {
 
@@ -70,7 +70,7 @@ public class TokenManager {
         verifyRefreshToken = tokenValidator.verifyRefreshToken(token);
 
         if (!verifyRefreshToken) {
-            Logger.w("RefreshToken is not existed!");
+            Log.w("RefreshToken is not existed!");
             return null;
         }
 
index fcc12f7..e4bd704 100644 (file)
@@ -27,7 +27,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.iotivity.cloud.accountserver.db.AccountDBManager;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class TokenValidator {
 
@@ -38,14 +38,14 @@ public class TokenValidator {
         // check token existed
         valid = AccountDBManager.getInstance().hasAccessToken(token);
         if (!valid) {
-            Logger.w("accessToken is not existed..");
+            Log.w("accessToken is not existed..");
             return false;
         }
 
         // check token expired
         if (getElaspedSeconds(token) > TokenPolicy.EXPIRES_IN) {
 
-            Logger.w("accessToken is expired..");
+            Log.w("accessToken is expired..");
             return false;
         }
 
@@ -68,10 +68,10 @@ public class TokenValidator {
 
         long difference = currentTime.getTime() - issuedTime.getTime();
         long elaspedSeconds = difference / 1000;
-        // Logger.d("currentTime : " + currentTime.getTime());
-        // Logger.d("issuedTime : " + issuedTime.getTime());
-        // Logger.d("difference : " + difference);
-        Logger.d("accessToken elasped time: " + elaspedSeconds + "s");
+        // Log.d("currentTime : " + currentTime.getTime());
+        // Log.d("issuedTime : " + issuedTime.getTime());
+        // Log.d("difference : " + difference);
+        Log.d("accessToken elasped time: " + elaspedSeconds + "s");
 
         return elaspedSeconds;
     }
@@ -86,7 +86,7 @@ public class TokenValidator {
         // check token existed
         valid = AccountDBManager.getInstance().hasRefreshToken(token);
         if (!valid)
-            Logger.w("refreshToken is not existed..");
+            Log.w("refreshToken is not existed..");
 
         return valid;
     }
index cea7878..1f55c98 100644 (file)
@@ -35,20 +35,17 @@ import org.iotivity.cloud.ciserver.resources.proxy.MessageQueue;
 import org.iotivity.cloud.ciserver.resources.proxy.ResourceDirectory;
 import org.iotivity.cloud.ciserver.resources.proxy.ResourceFind;
 import org.iotivity.cloud.ciserver.resources.proxy.ResourcePresence;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class CloudInterfaceServer {
 
     public static void main(String[] args) throws Exception {
-
-        System.setOut(FileLogger.createLoggingProxy(System.out));
+        Log.Init();
 
         System.out.println("-----CI SERVER-------");
 
         if (args.length != 8) {
-            Logger.e(
+            Log.e(
                     "coap server port and RDServer_Address port AccountServer_Address Port MQBroker_Address Port and TLS mode required\n"
                             + "ex) 5683 127.0.0.1 5684 127.0.0.1 5685 127.0.0.1 5686 0\n");
             return;
@@ -66,8 +63,6 @@ public class CloudInterfaceServer {
                 new InetSocketAddress(args[5], Integer.parseInt(args[6])),
                 tlsMode);
 
-        ErrorLogger.Init();
-
         DeviceServerSystem deviceServer = new DeviceServerSystem();
 
         Account acHandler = new Account();
index 82d7ba7..c6e9d4b 100644 (file)
@@ -43,7 +43,7 @@ import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.base.server.HttpServer;
 import org.iotivity.cloud.base.server.Server;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandler.Sharable;
@@ -103,7 +103,7 @@ public class DeviceServerSystem extends ServerSystem {
                             : ResponseStatus.BAD_REQUEST;
                     ctx.channel().writeAndFlush(MessageBuilder
                             .createResponse((CoapRequest) msg, responseStatus));
-                    ErrorLogger.write(ctx.channel(), t);
+                    Log.f(ctx.channel(), t);
                 }
             }
 
@@ -208,7 +208,7 @@ public class DeviceServerSystem extends ServerSystem {
                 ctx.writeAndFlush(msg);
 
             } catch (Throwable t) {
-                ErrorLogger.write(ctx.channel(), t);
+                Log.f(ctx.channel(), t);
                 ctx.writeAndFlush(msg);
                 ctx.close();
             }
@@ -270,7 +270,7 @@ public class DeviceServerSystem extends ServerSystem {
                         : ResponseStatus.UNAUTHORIZED;
                 ctx.channel().writeAndFlush(MessageBuilder
                         .createResponse((CoapRequest) msg, responseStatus));
-                ErrorLogger.write(ctx.channel(), t);
+                Log.f(ctx.channel(), t);
             }
         }
     }
index 50dda52..79e32b9 100644 (file)
@@ -27,27 +27,23 @@ import java.util.Scanner;
 import org.iotivity.cloud.base.ServerSystem;
 import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.mqserver.resources.MQBrokerResource;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class MessageQueueServer {
 
     public static void main(String[] args) throws Exception {
-        System.setOut(FileLogger.createLoggingProxy(System.out));
+        Log.Init();
 
         System.out.println("-----MQ SERVER-----");
 
         if (args.length != 6) {
-            Logger.e("coap server port, Kafka_zookeeper_Address port"
+            Log.e("coap server port, Kafka_zookeeper_Address port"
                     + " and Kafka_broker_Address Port and TLS mode required\n"
                     + "ex) 5686 127.0.0.1 2181 127.0.0.1 9092 0\n");
 
             return;
         }
 
-        ErrorLogger.Init();
-
         ServerSystem serverSystem = new ServerSystem();
 
         MQBrokerResource MQBroker = new MQBrokerResource();
index 19ba50a..7947944 100644 (file)
@@ -24,14 +24,14 @@ package org.iotivity.cloud.mqserver;
 import java.util.HashMap;
 
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class MessageQueueUtils {
 
     public static <T> T extractDataFromPayload(byte[] payload, String key) {
 
         if (payload == null || key.isEmpty()) {
-            Logger.e("payload or key is empty");
+            Log.e("payload or key is empty");
             return null;
         }
 
@@ -41,7 +41,7 @@ public class MessageQueueUtils {
         parsedData = cbor.parsePayloadFromCbor(payload, HashMap.class);
 
         if (parsedData == null || parsedData.containsKey(key) == false) {
-            Logger.e("payload doesn't contain " + key + " information");
+            Log.e("payload doesn't contain " + key + " information");
             return null;
         }
 
index 0e876bf..a67f8c1 100644 (file)
@@ -30,7 +30,7 @@ import kafka.utils.ZkUtils;
 import org.I0Itec.zkclient.ZkClient;
 import org.I0Itec.zkclient.ZkConnection;
 import org.iotivity.cloud.mqserver.Constants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class KafkaCommonWrapper {
 
@@ -49,7 +49,7 @@ public class KafkaCommonWrapper {
 
     public boolean createTopic(String topic) {
 
-        Logger.d("kafka createTopic - " + topic);
+        Log.d("kafka createTopic - " + topic);
 
         topic = topic.replace('/', '.');
 
@@ -66,7 +66,7 @@ public class KafkaCommonWrapper {
 
     public boolean deleteTopic(String topic) {
 
-        Logger.d("kafka deleteTopic - " + topic);
+        Log.d("kafka deleteTopic - " + topic);
 
         topic = topic.replace('/', '.');
 
index 0449125..3ca503b 100644 (file)
@@ -52,7 +52,7 @@ import org.I0Itec.zkclient.ZkClient;
 import org.I0Itec.zkclient.ZkConnection;
 import org.iotivity.cloud.mqserver.Constants;
 import org.iotivity.cloud.mqserver.topic.Topic;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class KafkaConsumerWrapper {
 
@@ -95,7 +95,7 @@ public class KafkaConsumerWrapper {
     // TODO exception handling
     public boolean subscribeTopic() {
 
-        Logger.d("kafka subscribeTopic - " + mTopicName);
+        Log.d("kafka subscribeTopic - " + mTopicName);
 
         if (mConsumerStarted == true) {
             return true;
@@ -128,7 +128,7 @@ public class KafkaConsumerWrapper {
 
         for (final KafkaStream<byte[], byte[]> stream : streams) {
 
-            Logger.d("kafka subscribe complete");
+            Log.d("kafka subscribe complete");
 
             mConsumerExecutor.execute(new Runnable() {
 
@@ -150,7 +150,7 @@ public class KafkaConsumerWrapper {
 
     public boolean unsubscribeTopic() {
 
-        Logger.d("kafka unsubscribeTopic - " + mTopicName);
+        Log.d("kafka unsubscribeTopic - " + mTopicName);
 
         // remove consumer group info in zookeeper
         List<String> subscribers = mZkClient.getChildren(ZkUtils
@@ -180,13 +180,13 @@ public class KafkaConsumerWrapper {
 
     public ArrayList<byte[]> getMessages() {
 
-        Logger.d("kafka get all messages - " + mTopicName);
+        Log.d("kafka get all messages - " + mTopicName);
 
         String brokerHost = mBroker.substring(0, mBroker.indexOf(':'));
         int brokerPort = Integer.parseInt(mBroker.substring(mBroker
                 .indexOf(':') + 1));
 
-        Logger.d("host " + brokerHost + ", port " + brokerPort);
+        Log.d("host " + brokerHost + ", port " + brokerPort);
 
         // TODO check options - Timeout: Int, bufferSize: Int
         SimpleConsumer simpleConsumer = new SimpleConsumer(brokerHost,
@@ -203,7 +203,7 @@ public class KafkaConsumerWrapper {
 
         if (fetchResponse == null || fetchResponse.hasError()) {
 
-            Logger.e("Error fetching data from the Broker");
+            Log.e("Error fetching data from the Broker");
             return null;
         }
 
@@ -217,7 +217,7 @@ public class KafkaConsumerWrapper {
 
                 long currentOffset = messageAndOffset.offset();
                 if (currentOffset < lastOffset) {
-                    Logger.e("Found an old offset: " + currentOffset
+                    Log.e("Found an old offset: " + currentOffset
                             + " Expecting: " + lastOffset);
                     continue;
                 }
@@ -234,7 +234,7 @@ public class KafkaConsumerWrapper {
 
         simpleConsumer.close();
 
-        Logger.d("kafka get all messages complete");
+        Log.d("kafka get all messages complete");
 
         return initialData;
     }
@@ -269,7 +269,7 @@ public class KafkaConsumerWrapper {
         OffsetResponse response = consumer.getOffsetsBefore(request);
 
         if (response == null || response.hasError()) {
-            Logger.e("Error fetching data Offset Data the Broker");
+            Log.e("Error fetching data Offset Data the Broker");
             return 0;
         }
 
index 9feefeb..9b3f2c1 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Properties;
 import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.Producer;
 import org.apache.kafka.clients.producer.ProducerRecord;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class KafkaProducerWrapper {
 
@@ -47,7 +47,7 @@ public class KafkaProducerWrapper {
     // TODO handle exception
     public boolean publishMessage(byte[] message) {
 
-        Logger.d("kafka publishMessage - " + mTopicName);
+        Log.d("kafka publishMessage - " + mTopicName);
 
         ProducerRecord<byte[], byte[]> record = new ProducerRecord<>(
                 mTopicName, message);
index 24dbb9a..16fccc3 100644 (file)
@@ -30,25 +30,21 @@ import org.iotivity.cloud.rdserver.resources.directory.rd.ResourceDirectoryResou
 import org.iotivity.cloud.rdserver.resources.directory.res.DiscoveryResource;
 import org.iotivity.cloud.rdserver.resources.presence.device.DevicePresenceResource;
 import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresenceResource;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class ResourceDirectoryServer {
 
     public static void main(String[] args) throws Exception {
-        System.setOut(FileLogger.createLoggingProxy(System.out));
+        Log.Init();
 
         System.out.println("-----RD SERVER-----");
 
         if (args.length != 2) {
-            Logger.e("coap server port and TLS mode required\n"
+            Log.e("coap server port and TLS mode required\n"
                     + "ex) 5684 0\n");
             return;
         }
 
-        ErrorLogger.Init();
-
         ServerSystem serverSystem = new ServerSystem();
 
         serverSystem.addResource(new ResourceDirectoryResource());
index fbc5b50..0f5c2de 100644 (file)
@@ -42,7 +42,7 @@ import org.iotivity.cloud.rdserver.resources.presence.ResPresenceManager;
 import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresencePayload;
 import org.iotivity.cloud.rdserver.util.TypeCastingManager;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class ResourceDirectoryResource extends Resource {
 
@@ -141,7 +141,7 @@ public class ResourceDirectoryResource extends Resource {
         }
         responseMap.put(Constants.LINKS, links);
 
-        Logger.i("publish response :" + responseMap.toString());
+        Log.i("publish response :" + responseMap.toString());
 
         byte[] encodedPaylod = mCbor.encodingPayloadToCbor(responseMap);
 
@@ -157,7 +157,7 @@ public class ResourceDirectoryResource extends Resource {
         if (payloadData == null) {
             throw new BadRequestException("payload is null");
         } else {
-            Logger.i("publish payload: " + payloadData.toString());
+            Log.i("publish payload: " + payloadData.toString());
         }
 
         PublishTags tags = new PublishTags();
index b99793c..1236c43 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.rdserver.Constants;
 import org.iotivity.cloud.rdserver.db.DBManager;
 import org.iotivity.cloud.rdserver.util.TypeCastingManager;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class DiscoveryResource extends Resource {
     private Cbor<HashMap<Object, Object>>      mCbor                     = new Cbor<>();
@@ -167,7 +167,7 @@ public class DiscoveryResource extends Resource {
             responseMapList.add(responseSegment);
         }
 
-        Logger.i("discover payload :" + responseMapList.toString());
+        Log.i("discover payload :" + responseMapList.toString());
 
         byte[] encodedPaylod = mCbor.encodingPayloadToCbor(responseMapList);
 
index 4e4d669..6ed867d 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.rdserver.Constants;
 import org.iotivity.cloud.rdserver.db.DBManager;
 import org.iotivity.cloud.rdserver.util.TypeCastingManager;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class DevicePresenceResource extends Resource {
 
@@ -128,7 +128,7 @@ public class DevicePresenceResource extends Resource {
             getPayload.add(payloadSegment);
         }
 
-        Logger.i("Get observe response" + getPayload.toString());
+        Log.i("Get observe response" + getPayload.toString());
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
                 ContentFormat.APPLICATION_CBOR,
@@ -161,7 +161,7 @@ public class DevicePresenceResource extends Resource {
                     DBManager.getInstance().findDeviceState(deviceId));
             getPayload.add(payloadSegment);
         }
-        Logger.i("Get observe response" + getPayload.toString());
+        Log.i("Get observe response" + getPayload.toString());
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
                 ContentFormat.APPLICATION_CBOR,
index 2c14d69..5ee5a06 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.base.resource.ResourceManager;
 import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.base.server.HttpServer;
 import org.iotivity.cloud.base.server.Server;
-import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandler.Sharable;
@@ -95,11 +95,11 @@ public class ServerSystem extends ResourceManager {
             } catch (ServerException e) {
                 ctx.channel().writeAndFlush(MessageBuilder.createResponse(msg,
                         e.getErrorResponse()));
-                ErrorLogger.write(ctx.channel(), e);
+                Log.f(ctx.channel(), e);
             } catch (ClientException e) {
-                ErrorLogger.write(ctx.channel(), e);
+                Log.f(ctx.channel(), e);
             } catch (Throwable t) {
-                ErrorLogger.write(ctx.channel(), t);
+                Log.f(ctx.channel(), t);
                 if (msg instanceof CoapRequest) {
                     ctx.channel().writeAndFlush(MessageBuilder.createResponse(
                             msg, ResponseStatus.INTERNAL_SERVER_ERROR));
index dc3d47b..7b1d49e 100644 (file)
@@ -33,7 +33,7 @@ import org.iotivity.cloud.base.protocols.coap.CoapRequest;
 import org.iotivity.cloud.base.protocols.coap.CoapResponse;
 import org.iotivity.cloud.base.protocols.enums.Observe;
 import org.iotivity.cloud.util.Bytes;
-import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.Channel;
 
@@ -107,7 +107,7 @@ public class CoapClient implements IRequestChannel, IResponseEventHandler {
             mChannel.writeAndFlush(request);
 
         } catch (Exception e) {
-            ErrorLogger.write(mChannel, e);
+            Log.f(mChannel, e);
         }
     }
 
index 554f52d..134afa5 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Date;
 
 import org.iotivity.cloud.base.connector.CoapClient;
 import org.iotivity.cloud.base.protocols.IResponse;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelHandlerContext;
 
@@ -88,7 +88,7 @@ public class CoapDevice extends Device {
 
         if (remainTime < 0) {
 
-            Logger.w("accessToken is expired..");
+            Log.w("accessToken is expired..");
             return true;
         }
 
index 7dbcf36..c6343f0 100644 (file)
@@ -21,7 +21,7 @@
  */
 package org.iotivity.cloud.base.protocols.coap;
 
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandler.Sharable;
@@ -41,7 +41,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
 
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        Logger.v(ctx.channel().id().asLongText().substring(26)
+        Log.v(ctx.channel().id().asLongText().substring(26)
                 + " Connected, Address: "
                 + ctx.channel().remoteAddress().toString());
 
@@ -51,7 +51,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         ctx.fireChannelInactive();
-        Logger.v(ctx.channel().id().asLongText().substring(26)
+        Log.v(ctx.channel().id().asLongText().substring(26)
                 + " Disconnected, Address: "
                 + ctx.channel().remoteAddress().toString());
     }
@@ -72,7 +72,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
                     (CoapResponse) msg);
         }
 
-        Logger.v(log);
+        Log.v(log);
 
         ctx.writeAndFlush(msg);
     }
@@ -93,7 +93,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
                     (CoapResponse) msg);
         }
 
-        Logger.v(log);
+        Log.v(log);
 
         ctx.fireChannelRead(msg);
     }
index 4f4ea70..9c1e6a4 100644 (file)
@@ -30,7 +30,7 @@ import java.util.List;
 import javax.net.ssl.SSLException;
 
 import org.iotivity.cloud.base.OCFConstants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.ChannelHandler;
@@ -91,7 +91,7 @@ public abstract class Server {
             throws CertificateException, SSLException, InterruptedException {
 
         try {
-            Logger.i("[CoapServer]startServer with tlsMode! mode= " + tlsMode);
+            Log.i("[CoapServer]startServer with tlsMode! mode= " + tlsMode);
 
             if (tlsMode == true) {
 
index 94c8e8b..6957f78 100644 (file)
@@ -85,7 +85,7 @@ public class Cbor<T> {
                 throw new PreconditionFailedException("deviceId is null");
             }
 
-            Logger.i("deviceId : " + deviceId);
+            Log.i("deviceId : " + deviceId);
 
             return deviceId;
         }
diff --git a/cloud/stack/src/main/java/org/iotivity/cloud/util/ErrorLogger.java b/cloud/stack/src/main/java/org/iotivity/cloud/util/ErrorLogger.java
deleted file mode 100644 (file)
index af173e4..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.iotivity.cloud.util;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-
-import io.netty.channel.Channel;
-
-public class ErrorLogger extends Logger {
-
-    private static FileOutputStream fos = null;
-    private static PrintStream      ps  = null;
-
-    static public void Init() throws FileNotFoundException {
-        File dir = new File("..//errLog//");
-        if (!dir.isDirectory()) {
-            System.out.println("Is Not Folder");
-            dir.mkdirs();
-        }
-        fos = new FileOutputStream("../errLog/[" + getDate() + "] error.log",
-                true);
-        ps = new PrintStream(fos);
-    }
-
-    static public void write(Channel channel, Throwable t) {
-        String log = channel.id().asLongText().substring(26) + " "
-                + t.getMessage();
-        ps.println(getTime() + " " + log);
-        t.printStackTrace(ps);
-        Logger.v(log);
-    }
-
-    protected static String getDate() {
-        Calendar calendar = Calendar.getInstance();
-        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-        return dateFormat.format(calendar.getTime());
-    }
-}
diff --git a/cloud/stack/src/main/java/org/iotivity/cloud/util/FileLogger.java b/cloud/stack/src/main/java/org/iotivity/cloud/util/FileLogger.java
deleted file mode 100644 (file)
index 2c9a9d4..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 Samsung Electronics 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 org.iotivity.cloud.util;
-
-import java.io.PrintStream;
-
-import org.apache.log4j.Logger;
-
-public class FileLogger {
-    private final static Logger logger = Logger.getLogger(FileLogger.class);
-
-    public static PrintStream createLoggingProxy(
-            final PrintStream realPrintStream) {
-        // TODO Auto-generated method stub
-        return new PrintStream(realPrintStream) {
-            public void print(final String string) {
-                realPrintStream.print(string);
-                logger.fatal(string);
-            }
-        };
-    }
-
-}
  */
 package org.iotivity.cloud.util;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 
-public class Logger {
+import org.apache.log4j.Logger;
+
+import io.netty.channel.Channel;
+
+public class Log {
 
     public static final int VERBOSE  = 0;
     public static final int DEBUG    = 1;
@@ -34,6 +42,46 @@ public class Logger {
 
     private static int      logLevel = VERBOSE;
 
+    private static FileOutputStream fos = null;
+    private static PrintStream      ps  = null;
+
+    private final static Logger logger = Logger.getLogger(Log.class);
+
+    public static void Init() throws FileNotFoundException {
+        System.setOut(Log.createLoggingProxy(System.out));
+        createfile();
+    }
+
+    public static PrintStream createLoggingProxy(
+            final PrintStream realPrintStream) {
+        // TODO Auto-generated method stub
+        return new PrintStream(realPrintStream) {
+            public void print(final String string) {
+                realPrintStream.print(string);
+                logger.fatal(string);
+            }
+        };
+    }
+
+    public static void createfile() throws FileNotFoundException{
+        File dir = new File("..//errLog//");
+        if (!dir.isDirectory()) {
+            dir.mkdirs();
+        }
+        fos = new FileOutputStream("../errLog/[" + getDate() + "] error.log",
+                true);
+        ps = new PrintStream(fos);
+    }
+
+    static public void f(Channel channel, Throwable t) {
+        String log = channel.id().asLongText().substring(26) + " "
+                + t.getMessage();
+        ps.println(getTime() + " " + log);
+        t.printStackTrace(ps);
+        Log.v(log);
+    }
+
+
     public static void setLogLevel(int level) {
         logLevel = level;
     }
@@ -118,6 +166,12 @@ public class Logger {
         return dateFormat.format(calendar.getTime());
     }
 
+    protected static String getDate() {
+        Calendar calendar = Calendar.getInstance();
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        return dateFormat.format(calendar.getTime());
+    }
+
     private static String getLogLevelString(int level) {
 
         String res = "";