public class Log
- Object
- Log
Pluggable logging framework that allows a developer to log into storage
using the file connector API. It is highly recommended to use this
class coupled with Netbeans preprocessing tags to reduce its overhead
completely in runtime.
Fields
public static final int DEBUG = 1 | Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error |
public static final int INFO = 2 | Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error |
public static final int WARNING = 3 | Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error |
public static final int ERROR = 4 | Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error |
public static final int REPORTING_NONE = 0 | Indicates that log reporting to the cloud should be disabled |
public static final int REPORTING_DEBUG = 1 | Indicates that log reporting to the cloud should occur regardless of whether an error occurred |
public static final int REPORTING_PRODUCTION = 3 | Indicates that log reporting to the cloud should occur only if an error occurred |
Constructors
protected Log() | Prevent new Log() syntax. |
Methods
public static int getReportingLevel() | Indicates the level of log reporting, this allows developers to send device logs to the cloud thus tracking crashes or functionality in the device. |
public static void setReportingLevel(int level) | Indicates the level of log reporting, this allows developers to send device logs to the cloud thus tracking crashes or functionality in the device. |
public static long getUniqueDeviceId() | Deprecated Returns a server generated unique device id that is cached locally and is only valid per application. |
public static String getUniqueDeviceKey() | Returns a server generated unique device id that is cached locally and is only valid per application. |
public static void sendLog() | Sends the current log to the cloud. |
public static void sendLogAsync() | Sends the current log to the cloud and returns immediately |
public static void install(Log newInstance) | Installs a log subclass that can replace the logging destination/behavior |
public static void p(String text) | Default println method invokes the print instance method, uses DEBUG level |
public static void p(String text, int level) | Default println method invokes the print instance method, uses given level |
public static void e(Throwable t) | This method is a shorthand form for logThrowable |
public static void deleteLog() | Deletes the current log file |
public static int getLevel() | Returns the logging level for printing log details, the lower the value the more verbose would the printouts be |
public static void setLevel(int level) | Sets the logging level for printing log details, the lower the value the more verbose would the printouts be |
public static String getLogContent() | Deprecated Returns the contents of the log as a single long string to be displayed by the application any way it sees fit |
public static void showLog() | Deprecated Places a form with the log as a TextArea on the screen, this method can be attached to appear at a given time or using a fixed global key. |
public static Log getInstance() | Returns the singleton instance of the log |
public static void bindCrashProtection(boolean consumeError) | Deprecated |
public static boolean isCrashBound() | Returns true if the user bound crash protection |
protected void logThrowable(Throwable t) | Logs an exception to the log, by default print is called with the exception details, on supported devices the stack trace is also physically written to the log |
protected void print(String text, int level) | Default log implementation prints to the console and the file connector if applicable. |
protected Writer createWriter()
throws IOException | Default method for creating the output writer into which we write, this method creates a simple log file using the file connector |
protected String getThreadAndTimeStamp() | Returns a simple string containing a timestamp and thread name. |
public boolean isFileWriteEnabled() | Indicates whether GCF’s file writing should be used to generate the log file |
public void setFileWriteEnabled(boolean fileWriteEnabled) | Indicates whether GCF’s file writing should be used to generate the log file |
public String getFileURL() | Indicates the URL where the log file is saved |
public void setFileURL(String fileURL) | Indicates the URL where the log file is saved |
public void trackFileSystem() | Activates the filesystem tracking of file open/close operations |
Inherited methods
Field details
DEBUG
public static final int DEBUG = 1Constant indicating the logging level Debug is the default and the lowest level
followed by info, warning and error
INFO
public static final int INFO = 2Constant indicating the logging level Debug is the default and the lowest level
followed by info, warning and error
WARNING
public static final int WARNING = 3Constant indicating the logging level Debug is the default and the lowest level
followed by info, warning and error
ERROR
public static final int ERROR = 4Constant indicating the logging level Debug is the default and the lowest level
followed by info, warning and error
REPORTING_NONE
public static final int REPORTING_NONE = 0Indicates that log reporting to the cloud should be disabled
REPORTING_DEBUG
public static final int REPORTING_DEBUG = 1Indicates that log reporting to the cloud should occur regardless of whether an error occurred
REPORTING_PRODUCTION
public static final int REPORTING_PRODUCTION = 3Indicates that log reporting to the cloud should occur only if an error occurred
Constructor details
Log
protected Log()Prevent new Log() syntax. Use getInstance()
Method details
getReportingLevel
public static int getReportingLevel()Indicates the level of log reporting, this allows developers to send device logs to the cloud
thus tracking crashes or functionality in the device.
Returns
one of REPORTING_NONE, REPORTING_DEBUG, REPORTING_PRODUCTION
setReportingLevel
public static void setReportingLevel(int level)Indicates the level of log reporting, this allows developers to send device logs to the cloud
thus tracking crashes or functionality in the device.
Parameters
levelint- one of REPORTING_NONE, REPORTING_DEBUG, REPORTING_PRODUCTION
getUniqueDeviceId
public static long getUniqueDeviceId()Deprecated. this will no longer work. Use
#getUniqueDeviceKey()Returns a server generated unique device id that is cached locally and is only valid per application.
Notice that this device id is specific to your application and to a specific install, it is guaranteed
to be completely unique or -1 if unavailable (which can be due to a network error). Warning: this
method might block while accessing the server!s
Returns
a unique device id
getUniqueDeviceKey
public static String getUniqueDeviceKey()Returns a server generated unique device id that is cached locally and is only valid per application.
Notice that this device id is specific to your application and to a specific install, it is guaranteed
to be completely unique or null if unavailable (which can be due to a network error). Warning: this
method might block while accessing the server!s
Returns
a unique device id
sendLog
public static void sendLog()Sends the current log to the cloud. Notice that this method is synchronous and
returns only when the sending completes
sendLogAsync
public static void sendLogAsync()Sends the current log to the cloud and returns immediately
install
public static void install(Log newInstance)Installs a log subclass that can replace the logging destination/behavior
Parameters
newInstanceLog- the new instance for the Log object
p
public static void p(String text)Default println method invokes the print instance method, uses DEBUG level
Parameters
textString- the text to print
p
public static void p(String text, int level)Default println method invokes the print instance method, uses given level
Parameters
textString- the text to print
levelint- one of DEBUG, INFO, WARNING, ERROR
e
public static void e(Throwable t)This method is a shorthand form for logThrowable
Parameters
tThrowable- the exception
deleteLog
public static void deleteLog()Deletes the current log file
getLevel
public static int getLevel()Returns the logging level for printing log details, the lower the value
the more verbose would the printouts be
Returns
one of DEBUG, INFO, WARNING, ERROR
setLevel
public static void setLevel(int level)Sets the logging level for printing log details, the lower the value
the more verbose would the printouts be
Parameters
levelint- one of DEBUG, INFO, WARNING, ERROR
getLogContent
public static String getLogContent()Deprecated. this was practical in old J2ME devices but hasn’t been maintained in ages, use sendLog() instead
Returns the contents of the log as a single long string to be displayed by
the application any way it sees fit
Returns
string containing the whole log
showLog
public static void showLog()Deprecated. this method is an outdated method that’s no longer supported
Places a form with the log as a TextArea on the screen, this method can
be attached to appear at a given time or using a fixed global key. Using
this method might cause a problem with further log output
getInstance
public static Log getInstance()Returns the singleton instance of the log
Returns
the singleton instance of the log
bindCrashProtection
public static void bindCrashProtection(boolean consumeError)Deprecated.
Replaced by com.codename1.crash.CrashProtection,
which captures the full structured crash record (Java exception
- native crash data + platform log snapshot) and uploads it to
the managed crash-reporting service. Call
CrashProtection.install()plusCrashProtection.setEnabled(true)from yourLifecycle.initinstead. This method is now a no-op.
isCrashBound
public static boolean isCrashBound()Returns true if the user bound crash protection
Returns
true if crash protection is bound
logThrowable
protected void logThrowable(Throwable t)Logs an exception to the log, by default print is called with the exception
details, on supported devices the stack trace is also physically written to
the log
protected void print(String text, int level)Default log implementation prints to the console and the file connector
if applicable. Also prepends the thread information and time before
Parameters
textString- the text to print
levelint- one of DEBUG, INFO, WARNING, ERROR
createWriter
protected Writer createWriter()
throws IOExceptionDefault method for creating the output writer into which we write, this method
creates a simple log file using the file connector
Returns
writer object
Throws
IOException- when thrown by the connector
getThreadAndTimeStamp
protected String getThreadAndTimeStamp()Returns a simple string containing a timestamp and thread name.
Returns
timestamp string for use in the log
isFileWriteEnabled
public boolean isFileWriteEnabled()Indicates whether GCF’s file writing should be used to generate the log file
Returns
the fileWriteEnabled
setFileWriteEnabled
public void setFileWriteEnabled(boolean fileWriteEnabled)Indicates whether GCF’s file writing should be used to generate the log file
Parameters
fileWriteEnabledboolean- the fileWriteEnabled to set
getFileURL
public String getFileURL()Indicates the URL where the log file is saved
Returns
the fileURL
setFileURL
public void setFileURL(String fileURL)Indicates the URL where the log file is saved
Parameters
fileURLString- the fileURL to set
trackFileSystem
public void trackFileSystem()Activates the filesystem tracking of file open/close operations