|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.system.EventLogger
public final class EventLogger
Logs events into the persistent store.
The event logger stores a sequence of bytes. What those bytes "mean" is
determined by the viewer registered to view them. So, for instance, you can
log an integer (four bytes) and register a
string viewer
: those four bytes will then be
interpreted as four ASCII characters and displayed as such.
Events are persistent across reset. The device maintains an event queue; when the log gets too full, new events push old ones out of the front of the queue. Approximately 16 K of data can be logged until the log gets too full.
To use the event logger, you should invoke one of the EventLogger.register(long, java.lang.String, int)
methods with your application's GUID to register your application to log
events. The GUID can be created in the IDE by right-clicking a String, and
selecting "Convert String to Long". You can then use the various
EventLogger.logEvent(long, byte[], int)
methods to log events in the system's event log. You can
use any of the logEvent methods as appropriate to the event data to log; it
doesn't need to be the same type as your intended viewer type: the logger
stores all data as a simple sequence of bytes in any event.
After registering your application, you can make calls to the
EventLogger.logEvent(long, byte[], int)
to log events for that application.
The EventLogger.logEvent(long, byte[], int)
method can get passed an integer or a long integer
if you are using a EventLogger.VIEWER_NUMBER
viewer type for your application or
a byte array if you are using a EventLogger.VIEWER_STRING
or
EventLogger.VIEWER_EXCEPTION
viewer type.
For example, to pass a String to EventLogger.logEvent(long, byte[])
, convert it to a byte
array using the String class' getBytes() function:
EventLogger.register(0x4c9d3452d87922f2L, "myApp", EventLogger.VIEWER_STRING); String logMessage = "An event has been logged."; if ( EventLogger.logEvent( 0x4c9d3452d87922f2L, logMessage.getBytes() ) ) { System.out.println("Log Successful!"); }
Any time you catch a Throwable object, a message is automatically logged.
To be written into the log, each posted event must either have an event
level equal to or lower then the current cut off point or be logged with the
EventLogger.ALWAYS_LOG
event level.
The default cut off point is EventLogger.WARNING
. That is, by default, only
events logged with
EventLogger.WARNING
,
EventLogger.ERROR
,
EventLogger.SEVERE_ERROR
, or
EventLogger.ALWAYS_LOG
are actually written in the log.
The log itself is 16 KB in size; each log entry uses 15 bytes for overhead, plus whatever space is used by the entry's actual data. Once the log meets or exceeds the 16 KB size, old entries will get erased as required to fit in the new entries.
To view the current event log for the device, hold down the ALT key and type "lglg".
Examples
To log a string, you can use code like this:
EventLogger.logEvent( GUID, yourString.getBytes(), level );The following example demonstrates how to log a numeric event:
// Register application for event logging. EventLogger.register(0x9c805919833654d6L, SampleApp); // Set minimum logging level for the event logger. EventLogger.setMinimumLevel(EventLogger.INFORMATION, 0x9c805919833654d6L); // Log a numeric event. EventLogger.logEvent(0x9c805919833654d6L, 12, EventLogger.INFORMATION);
Field Summary | ||
---|---|---|
static int |
ALWAYS_LOG
Always log event, regardless of severity. |
|
static int |
DEBUG_INFO
Debug information level event. |
|
static int |
ERROR
Error level event. |
|
static int |
INFORMATION
Information level event. |
|
static int |
SEVERE_ERROR
Severe level event. |
|
static long |
SYSTEM_LOG_GUID
System event log GUID. |
|
static int |
VIEWER_EXCEPTION
Exception event viewer. |
|
static int |
VIEWER_NUMBER
Number event viewer. |
|
static int |
VIEWER_STRING
String event viewer. |
|
static int |
WARNING
Warning level event. |
Method Summary | ||
---|---|---|
static void |
clearLog()
Clears the EventLog of all events. |
|
static int |
getEffectiveMinimumLevel(long guid)
Retrieves the current effective minimum logging level for the event logger with the given GUID. |
|
static int |
getInt(byte[] data)
Transmogrify a byte array into an integer. |
|
static int |
getMinimumLevel()
Retrieves the current global minimum logging level. |
|
static int |
getMinimumLevel(long guid)
Retrieves the current minimum logging level for the event logger with the given GUID. |
|
static String |
getRegisteredAppName(long forGUID)
Retrieves name of application given GUID. |
|
static int |
getRegisteredViewerType(long forGUID)
Retrieves the viewer type registered for an application given GUID. |
|
static boolean |
logEvent(long guid,
byte[] data)
Logs an EventLogger.ALWAYS_LOG level event for an application. |
|
static boolean |
logEvent(long guid,
byte[] data,
int level)
Logs an event for an application. |
|
static boolean |
logEvent(long guid,
int code)
Logs an EventLogger.ALWAYS_LOG level numeric event for an application. |
|
static boolean |
logEvent(long guid,
int code,
int level)
Logs a numeric event for an application. |
|
static boolean |
logEvent(long guid,
long value,
int level)
Logs a numeric event for an application. |
|
static boolean |
register(long guid,
String name)
Registers the calling application's name and guid. |
|
static boolean |
register(long guid,
String name,
int viewerType)
Registers the calling application's name and GUID, with a particular viewer type. |
|
static void |
setGlobalMinimumLevel(int level)
Sets the new global minimum level for logging. |
|
static void |
setMinimumLevel(int level)
Deprecated. Use EventLogger.setMinimumLevel(int, long) instead. |
|
static void |
setMinimumLevel(int level,
long guid)
Sets the new minimum level for logging for the event logger with the given GUID. |
|
static boolean |
startEventLogViewer()
Starts the event log viewer. |
|
static void |
unsetMinimumLevel(long guid)
Un-sets the GUID-specific minimum level for logging for the event logger with the given GUID. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long SYSTEM_LOG_GUID
Used for text messages.
public static final int DEBUG_INFO
public static final int INFORMATION
public static final int WARNING
public static final int ERROR
public static final int SEVERE_ERROR
public static final int ALWAYS_LOG
public static final int VIEWER_NUMBER
public static final int VIEWER_STRING
public static final int VIEWER_EXCEPTION
Method Detail |
---|
public static final boolean register(long guid, String name, int viewerType)
You must invoke this method before the logger can log events with the given GUID.
If a name/GUID has already been registered with a particular viewer type, calling this method with a new viewer type replaces the previous one.
guid
- GUID of the registering application.name
- Name of the registering application.viewerType
- Type of viewer to be used when displaying the event
(one of EventLogger.VIEWER_NUMBER
,
EventLogger.VIEWER_STRING
,
EventLogger.VIEWER_EXCEPTION
).
public static final boolean register(long guid, String name)
You must invoke this method before the logger can log events with the
given GUID. This method uses the default EventLogger.VIEWER_NUMBER
type for
displaying events.
If a name/GUID has already been registered with a viewer type other
than EventLogger.VIEWER_NUMBER
, calling this method replaces it with the
EventLogger.VIEWER_NUMBER
type..
guid
- GUID of the registering application.name
- Name of the registering application.
public static final int getRegisteredViewerType(long forGUID)
forGUID
- GUID of registered application.
EventLogger.VIEWER_NUMBER
, EventLogger.VIEWER_STRING
, EventLogger.VIEWER_EXCEPTION
.public static final String getRegisteredAppName(long forGUID)
forGUID
- GUID of the registered application.
public static final boolean logEvent(long guid, byte[] data, int level)
The invoker must provide an already-registered GUID (with one of the
EventLogger.register(long, java.lang.String, int)
methods).
This method is recommended for use with GUIDs registered as viewer
types EventLogger.VIEWER_STRING
and EventLogger.VIEWER_EXCEPTION
. The data to
be logged must be a byte[].
guid
- GUID of the application logging the event.data
- Data to log.level
- Level for this event.
public static final boolean logEvent(long guid, byte[] data)
EventLogger.ALWAYS_LOG
level event for an application.
The invoker must provide an already-registered GUID (with one of the
EventLogger.register(long, java.lang.String, int)
methods).
This method is recommended for use with GUIDs registered as viewer
types EventLogger.VIEWER_STRING
and EventLogger.VIEWER_EXCEPTION
. The data to
be logged must be a byte[].
guid
- GUID of the application logging the event.data
- Data to log.
public static final boolean logEvent(long guid, int code, int level)
The event in this case is always some integer value.
The invoker must provide an already-registered GUID (with one of the
EventLogger.register(long, java.lang.String, int)
methods).
This method is recommended for use with GUIDs registered as viewer
type EventLogger.VIEWER_NUMBER
.
guid
- GUID of the application logging the event.code
- a Numeric value representing the event code ( each Byte shifted accordingly ex: ('E'<<24)|('V'<<16)|('C'<<8)|('D')).level
- Level for this event.
public static final boolean logEvent(long guid, long value, int level)
The event in this case is always some long value.
The invoker must provide an already-registered GUID (with one of the
EventLogger.register(long, java.lang.String, int)
methods).
This method is recommended for use with GUIDs registered as viewer
type EventLogger.VIEWER_NUMBER
.
guid
- GUID of the application logging the event.value
- Numeric value of the event.level
- Level for this event.
public static final boolean logEvent(long guid, int code)
EventLogger.ALWAYS_LOG
level numeric event for an application.
The event in this case is always some integer value.
The invoker must provide an already-registered GUID (with one of the
EventLogger.register(long, java.lang.String, int)
methods).
This method is recommended for use with GUIDs registered as viewer
type EventLogger.VIEWER_NUMBER
.
guid
- GUID of the application logging the event.code
- a Numeric value representing the event code ( each Byte shifted accordingly ex: ('E'<<24)|('V'<<16)|('C'<<8)|('D')).
public static final int getMinimumLevel()
EventLogger.getEffectiveMinimumLevel(long)
public static final int getMinimumLevel(long guid)
guid
- The GUID of the event logger whose minimum level to return.
-1
if no minimum level is currently set
for the given GUID.EventLogger.setMinimumLevel(int, long)
,
EventLogger.getEffectiveMinimumLevel(long)
public static final int getEffectiveMinimumLevel(long guid)
EventLogger.setMinimumLevel(int, long)
for the given GUID. It then
checks the global minimum level returned from EventLogger.getMinimumLevel()
.
If the per-GUID minimum level has not been set, then the global minimum
level is returned. Otherwise, the more verbose of the global and
per-GUID minimum levels is returned.
Example 1: Suppose that the global minimum level is INFORMATION and no per-GUID minimum level is set for the given GUID. In this case, INFORMATION will be returned.
Example 2: Suppose that the global minimum level is DEBUG and the per-GUID minimum level is INFORMATION for the given GUID. In this case, DEBUG will be returned.
Example 3: Suppose that the global minimum level is INFORMATION and the per-GUID minimum level is DEBUG for the given GUID. In this case, DEBUG will be returned.
guid
- The GUID whose effective minimum logging level to return.
public static final void setGlobalMinimumLevel(int level)
EventLogger.WARNING
drastically
increases the number of messages logged to the event log, and may
dramatically degrade device performance. If you only want to set the
logging verbosity for your own logger, use
EventLogger.setMinimumLevel(int, long)
instead.
Note: This method contains the logic formerly used by
EventLogger.setMinimumLevel(int)
before it was changed to only set the
minimum level for the GUIDs registered by the calling application.
level
- The new minimum logging level.
IllegalArgumentException
- if the level is not supported;
supported levels are EventLogger.DEBUG_INFO
, EventLogger.INFORMATION
, and
EventLogger.WARNING
.public static final void setMinimumLevel(int level)
EventLogger.setMinimumLevel(int, long)
instead.
Previously, this method used to set the global minimum level, which
affected the minimum level of all registered loggers. This,
however, caused degraded device performance if set to a level that was
too verbose. Therefore, the behavior of this method was changed to
only set the minimum level for loggers that were registered by
the calling application. Due to the new non-deterministic behavior of
this method, it is strongly recommended to use
EventLogger.setMinimumLevel(int, long)
instead, so that the loggers whose
minimum level to affect are explicitly specified.
level
- The new minimum logging level; valid values are
EventLogger.DEBUG_INFO
, EventLogger.INFORMATION
, EventLogger.WARNING
,
EventLogger.ERROR
, and EventLogger.SEVERE_ERROR
.
IllegalArgumentException
- if the given value for
level
is not valid.
SecurityException
- if the calling application is denied access to
ApplicationPermissions.PERMISSION_DEVICE_SETTINGS
permission.public static final void setMinimumLevel(int level, long guid)
If no event logger with the given GUID is currently registered, then the given level will be saved and used as the minimum level for an event logger that is later registered with the given GUID.
Note that the level that is set by this method will not persist across device resets.
For more information on how the per-GUID minimum level is used when
determining whether or not to emit log messages to the event log, see
EventLogger.getEffectiveMinimumLevel(long)
.
level
- The new minimum logging level; valid values are
EventLogger.DEBUG_INFO
, EventLogger.INFORMATION
, EventLogger.WARNING
,
EventLogger.ERROR
, and EventLogger.SEVERE_ERROR
.guid
- The GUID of the event logger whose minimum level to set.
IllegalArgumentException
- if the given value for
level
is not valid.
SecurityException
- if the calling application is denied access to
ApplicationPermissions.PERMISSION_DEVICE_SETTINGS
permission.EventLogger.unsetMinimumLevel(long)
,
EventLogger.getMinimumLevel(long)
public static final void unsetMinimumLevel(long guid)
If no GUID-specific minimum level has been set for the given GUID using
EventLogger.setMinimumLevel(int, long)
, then this method does nothing.
Otherwise, the logging level for the event logger with the
given GUID will be changed to follow the global minimum level.
For more information on how the per-GUID minimum level is used when
determining whether or not to emit log messages to the event log, see
EventLogger.getEffectiveMinimumLevel(long)
.
guid
- The GUID of the event logger whose minimum level to unset.
SecurityException
- if the calling application is denied access to
ApplicationPermissions.PERMISSION_DEVICE_SETTINGS
permission.EventLogger.setMinimumLevel(int, long)
,
EventLogger.getMinimumLevel(long)
public static final void clearLog()
public static int getInt(byte[] data)
data
- Byte array to transmogrify.
public static boolean startEventLogViewer()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal