This should help make BlackBerry application error logging easier. To see your event-log you can type Alt+LGLG on your home screen. You can also use javaloader.exe (comes in the bin folder of the JDE) to export the log to a text file.

Javaloader -u eventlog > textfile.txt

Using the class below, you must change the unique bundle ID and name to match your application. This can be done for you when you add any new resource file to your project. Within the class used to access the resource strings will be BUNDLE_ID and BUNDLE_NAME. Replace those values in the class below.

Download the class below:

Logger.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ca.dftr.lib.error;
 
/*
 * Logger.java
 */
import net.rim.device.api.system.EventLogger;
import ca.dftr.lib.resources.libResource;
 
public class Logger {
 
	public static int LEVEL_INFO = EventLogger.INFORMATION;
	public static int LEVEL_WARNING = EventLogger.WARNING;
	public static int LEVEL_ERROR = EventLogger.ERROR;
	public static int LEVEL_SEVERE_ERROR = EventLogger.SEVERE_ERROR;
 
	public static String LOG_PREFIX_INFO = "Info: ";
	public static String LOG_PREFIX_WARN = "Warning: ";
	public static String LOG_PREFIX_ERROR = "Error: ";
	public static String LOG_PREFIX_SEVERE = "Severe Error: ";
 
	//Must put in your unique bundle ID and name.
	static {
		EventLogger.register(libResource.BUNDLE_ID, libResource.BUNDLE_NAME, EventLogger.VIEWER_STRING);
	}
 
	public static void logEventInfo(String eventData) {
		Logger.logEvent(Logger.LEVEL_INFO, Logger.LOG_PREFIX_INFO + eventData);
	}
 
	public static void logEventWarn(String eventData) {
		Logger.logEvent(Logger.LEVEL_WARNING, Logger.LOG_PREFIX_WARN + eventData);
	}
 
	public static void logEventError(String eventData) {
		Logger.logEvent(Logger.LEVEL_ERROR, Logger.LOG_PREFIX_ERROR + eventData);
	}
 
	public static void logEventSevere(String eventData) {
		Logger.logEvent(Logger.LEVEL_SEVERE_ERROR, Logger.LOG_PREFIX_SEVERE + eventData);
	}
 
	/**
	 * Log Event.
	 * Note: The event will only end up in the log depending on the
	 * EventLogViewer min log level. Accessed via alt+LGLG on home screen
	 */
	public static void logEvent(int level, String eventData) {
		EventLogger.logEvent(libResource.BUNDLE_ID, eventData.getBytes(), level);
		System.out.println(eventData);
	}
}