-//
-// Copyright (c) 2013 Ford Motor Company
-//
-package com.smartdevicelink.util;
-
-import android.util.Log;
-
-import com.smartdevicelink.proxy.SmartDeviceLinkProxyBase;
-
-public class NativeLogTool {
-
- static private boolean logToSystemEnabled = true;
- private static final int ChunkSize = 4000;
-
- private enum LogTarget {
- Info
- ,Warning
- ,Error
- }
-
- public static void setEnableState(boolean en) {
- logToSystemEnabled = en;
- } // end-method
-
- public static boolean isEnabled() {
- return logToSystemEnabled;
- } // end-method
-
- public static void logInfo(String message) {
- logInfo(SmartDeviceLinkProxyBase.TAG, message);
- }
-
- public static void logInfo(String tag, String message) {
- if (logToSystemEnabled) {
- log(LogTarget.Info, tag, message);
- }
- }
-
- public static void logWarning(String message) {
- logWarning(SmartDeviceLinkProxyBase.TAG, message);
- }
-
- public static void logWarning(String tag, String message) {
- if (logToSystemEnabled) {
- log(LogTarget.Warning, tag, message);
- }
- }
-
- public static void logError(String message) {
- logError(SmartDeviceLinkProxyBase.TAG, message);
- }
-
- public static void logError(String tag, String message) {
- if (logToSystemEnabled) {
- log(LogTarget.Error, tag, message);
- }
- }
-
- public static void logError(String message, Throwable t) {
- logError(SmartDeviceLinkProxyBase.TAG, message, t);
- }
-
- public static void logError(String tag, String message, Throwable t) {
- // If the call to logError is passed a throwable, write directly to the system log
- if (logToSystemEnabled) {
- Log.e(tag, message, t);
- }
- }
-
- private static void log(LogTarget ltarg, String source, String logMsg) {
- // Don't log empty messages
- if (logMsg == null || logMsg.length() == 0) {
- return;
- } // end-if
-
- int bytesWritten = 0;
- int substrSize = 0;
- String tag = source;
- String chunk = null;
- try {
- for (int idx=0;idx < logMsg.length();idx += substrSize) {
- substrSize = Math.min(ChunkSize, logMsg.length() - idx);
- chunk = logMsg.substring(idx, idx + substrSize);
- switch (ltarg) {
- case Info:
- bytesWritten = Log.i(tag, chunk);
- break;
- case Warning:
- bytesWritten = Log.w(tag, chunk);
- break;
- case Error:
- bytesWritten = Log.e(tag, chunk);
- break;
- } // end-switch
- if (bytesWritten < chunk.length()) {
- Log.e(SmartDeviceLinkProxyBase.TAG, "Calling Log.e: msg length=" + chunk.length() + ", bytesWritten=" + bytesWritten);
- } // end-if
- } // end-while
- } catch (Exception ex) {
- Log.e(SmartDeviceLinkProxyBase.TAG, "Failure writing " + ltarg.name() + " fragments to android log:" + ex.toString());
- } // end-catch
- } // end-method
-}
+package com.smartdevicelink.util;\r
+\r
+import android.util.Log;\r
+\r
+import com.smartdevicelink.proxy.SmartDeviceLinkProxyBase;\r
+\r
+public class NativeLogTool {\r
+ \r
+ static private boolean logToSystemEnabled = true;\r
+ private static final int ChunkSize = 4000;\r
+ \r
+ private enum LogTarget {\r
+ Info\r
+ ,Warning\r
+ ,Error\r
+ }\r
+\r
+ public static void setEnableState(boolean en) {\r
+ logToSystemEnabled = en;\r
+ } // end-method\r
+\r
+ public static boolean isEnabled() {\r
+ return logToSystemEnabled;\r
+ } // end-method\r
+ \r
+ public static void logInfo(String message) {\r
+ logInfo(SmartDeviceLinkProxyBase.TAG, message);\r
+ }\r
+ \r
+ public static void logInfo(String tag, String message) {\r
+ if (logToSystemEnabled) {\r
+ log(LogTarget.Info, tag, message);\r
+ }\r
+ }\r
+ \r
+ public static void logWarning(String message) {\r
+ logWarning(SmartDeviceLinkProxyBase.TAG, message);\r
+ }\r
+ \r
+ public static void logWarning(String tag, String message) {\r
+ if (logToSystemEnabled) {\r
+ log(LogTarget.Warning, tag, message);\r
+ }\r
+ }\r
+ \r
+ public static void logError(String message) {\r
+ logError(SmartDeviceLinkProxyBase.TAG, message);\r
+ }\r
+ \r
+ public static void logError(String tag, String message) {\r
+ if (logToSystemEnabled) {\r
+ log(LogTarget.Error, tag, message);\r
+ }\r
+ }\r
+ \r
+ public static void logError(String message, Throwable t) {\r
+ logError(SmartDeviceLinkProxyBase.TAG, message, t);\r
+ }\r
+ \r
+ public static void logError(String tag, String message, Throwable t) {\r
+ // If the call to logError is passed a throwable, write directly to the system log\r
+ if (logToSystemEnabled) {\r
+ Log.e(tag, message, t);\r
+ }\r
+ }\r
+ \r
+ private static void log(LogTarget ltarg, String source, String logMsg) {\r
+ // Don't log empty messages\r
+ if (logMsg == null || logMsg.length() == 0) {\r
+ return;\r
+ } // end-if\r
+\r
+ int bytesWritten = 0;\r
+ int substrSize = 0;\r
+ String tag = source;\r
+ String chunk = null;\r
+ try {\r
+ for (int idx=0;idx < logMsg.length();idx += substrSize) {\r
+ substrSize = Math.min(ChunkSize, logMsg.length() - idx);\r
+ chunk = logMsg.substring(idx, idx + substrSize);\r
+ switch (ltarg) {\r
+ case Info:\r
+ bytesWritten = Log.i(tag, chunk);\r
+ break;\r
+ case Warning:\r
+ bytesWritten = Log.w(tag, chunk);\r
+ break;\r
+ case Error:\r
+ bytesWritten = Log.e(tag, chunk);\r
+ break;\r
+ } // end-switch\r
+ if (bytesWritten < chunk.length()) {\r
+ Log.e(SmartDeviceLinkProxyBase.TAG, "Calling Log.e: msg length=" + chunk.length() + ", bytesWritten=" + bytesWritten);\r
+ } // end-if\r
+ } // end-while\r
+ } catch (Exception ex) {\r
+ Log.e(SmartDeviceLinkProxyBase.TAG, "Failure writing " + ltarg.name() + " fragments to android log:" + ex.toString());\r
+ } // end-catch\r
+ } // end-method\r
+}\r