Class Log

java.lang.Object
com.codename1.io.Log

public class Log extends Object
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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
    static final int
    Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
    static final int
    Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
    static final int
    Indicates that log reporting to the cloud should occur regardless of whether an error occurred
    static final int
    Indicates that log reporting to the cloud should be disabled
    static final int
    Indicates that log reporting to the cloud should occur only if an error occurred
    static final int
    Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Log()
    Prevent new Log() syntax.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    bindCrashProtection(boolean consumeError)
    Binds pro based crash protection logic that will send out an email in case of an exception thrown on the EDT
    protected Writer
    Default method for creating the output writer into which we write, this method creates a simple log file using the file connector
    static void
    Deletes the current log file
    static void
    This method is a shorthand form for logThrowable
    Indicates the URL where the log file is saved
    static Log
    Returns the singleton instance of the log
    static int
    Returns the logging level for printing log details, the lower the value the more verbose would the printouts be
    static String
    Returns the contents of the log as a single long string to be displayed by the application any way it sees fit
    static int
    Indicates the level of log reporting, this allows developers to send device logs to the cloud thus tracking crashes or functionality in the device.
    protected String
    Returns a simple string containing a timestamp and thread name.
    static long
    Returns a server generated unique device id that is cached locally and is only valid per application.
    static String
    Returns a server generated unique device id that is cached locally and is only valid per application.
    static void
    install(Log newInstance)
    Installs a log subclass that can replace the logging destination/behavior
    static boolean
    Returns true if the user bound crash protection
    boolean
    Indicates whether GCF's file writing should be used to generate the log file
    protected void
    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
    static void
    p(String text)
    Default println method invokes the print instance method, uses DEBUG level
    static void
    p(String text, int level)
    Default println method invokes the print instance method, uses given level
    protected void
    print(String text, int level)
    Default log implementation prints to the console and the file connector if applicable.
    static void
    Sends the current log to the cloud.
    static void
    Sends the current log to the cloud and returns immediately
    void
    setFileURL(String fileURL)
    Indicates the URL where the log file is saved
    void
    setFileWriteEnabled(boolean fileWriteEnabled)
    Indicates whether GCF's file writing should be used to generate the log file
    static void
    setLevel(int level)
    Sets the logging level for printing log details, the lower the value the more verbose would the printouts be
    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.
    static void
    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.
    void
    Activates the filesystem tracking of file open/close operations

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEBUG

      public static final int DEBUG
      Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
      See Also:
    • INFO

      public static final int INFO
      Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
      See Also:
    • WARNING

      public static final int WARNING
      Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
      See Also:
    • ERROR

      public static final int ERROR
      Constant indicating the logging level Debug is the default and the lowest level followed by info, warning and error
      See Also:
    • REPORTING_NONE

      public static final int REPORTING_NONE
      Indicates that log reporting to the cloud should be disabled
      See Also:
    • REPORTING_DEBUG

      public static final int REPORTING_DEBUG
      Indicates that log reporting to the cloud should occur regardless of whether an error occurred
      See Also:
    • REPORTING_PRODUCTION

      public static final int REPORTING_PRODUCTION
      Indicates that log reporting to the cloud should occur only if an error occurred
      See Also:
  • 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
      • level: one of REPORTING_NONE, REPORTING_DEBUG, REPORTING_PRODUCTION
    • getUniqueDeviceId

      public static long getUniqueDeviceId()

      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

      Deprecated

      this will no longer work. Use #getUniqueDeviceKey()

    • 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
      • newInstance: 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
      • text: 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
      • text: the text to print

      • level: one of DEBUG, INFO, WARNING, ERROR

    • e

      public static void e(Throwable t)

      This method is a shorthand form for logThrowable

      Parameters
      • t: 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
      • level: one of DEBUG, INFO, WARNING, ERROR
    • getLogContent

      public static String getLogContent()

      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

      Deprecated

      this was practical in old J2ME devices but hasn't been maintained in ages, use sendLog() instead

    • showLog

      public static void showLog()

      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

      Deprecated

      this method is an outdated method that's no longer supported

    • 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)

      Binds pro based crash protection logic that will send out an email in case of an exception thrown on the EDT

      Parameters
      • consumeError: @param consumeError true will hide the error from the user, false will leave the builtin logic that defaults to showing an error dialog to the user
    • 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

      Parameters
      • t
    • print

      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
      • text: the text to print

      • level: one of DEBUG, INFO, WARNING, ERROR

    • createWriter

      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

      Returns

      writer object

      Throws
      • IOException: when thrown by the connector
      Throws:
      IOException
    • 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
      • fileWriteEnabled: 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
      • fileURL: the fileURL to set
    • trackFileSystem

      public void trackFileSystem()
      Activates the filesystem tracking of file open/close operations