黑莓日志文件 [英] Blackberry log file
问题描述
有没有使用BlackBerry API创建日志文件的方法?
Is there a method for creating a log file using a blackberry api ?
喜欢的东西log4j的?
Something like log4j ?
我要保存运行模拟器在PC上此日志文件,这可能吗?
I'd like to save this log file on pc running the emulator, is this possible ?
推荐答案
目前Antair,我们的黑莓应用开发过程中,我们通常包括在开发调试控制台建立我们的应用程序。
At Antair, during development of our BlackBerry applications, we often include a debug console in the dev builds of our apps.
使用调试控制台,所有的调试输出命中输出画面时dev的版本是在模拟器上运行,而当开发构建物理试验设备上运行,调试输出自动依然存在,可查看在专用的屏幕,可以通过菜单选项或按钮上拉。随着一点点的code的修改,就可以轻松拥有的调试日志被重新路由到一个文件,通过电子邮件发送或通过网络连接发送。
With the debug console, all debug output hits the output screen when the dev build is running in the simulator, and when the dev build runs on a physical test device, the debug output is automatically persisted and is available to view on a dedicated screen that can be pulled up via a menu option or button. With a little code modification, you can easily have the debug log be rerouted to a file, emailed or sent over a network connection.
在code以下是我们在我们公司使用调试控制台的精简版。
The code below is a stripped-down version of the debug console we use at our company.
使用控制台是容易的。在项目中包含的code,填写 PERSISTENCE_GUID 作为您的应用程序中,调试日志将 TAGID 字符串,以确定您的应用程序名称,当你想输出调试语句,只需调用 Debug.print(事情发生在这里......);
Using the console is easy. Include the code in your project, fill out the PERSISTENCE_GUID for your application, set the TAGID string to identify your application name in the debug logs, and when you want to output a debug statement, simply call Debug.print("Something happened here…");
调试输出的每一行,无论是在输出窗口在模拟器中运行时,并在设备上查看时调试控制台屏幕,将包含调试信息,在其上进行呼叫的线程数(用线程/ UI调试),以及日期/日志报表的时间,用毫秒时间戳性能分析。
Each line of the debug output, both in the output window when running in a simulator, and in the debug console screen when viewed on a device, will contain your debug message, the thread number on which the call was made (useful for thread/ui debugging), and the date/time of the log statement, with a millisecond timestamp for performance profiling.
要查看真实设备的调试控制台中,将简单的在一个呼叫 pushScreen(新AntairLogScreen())。屏幕上有一个内置的菜单项,清除持久日志信息,并会解雇自己像一个普通的应用程序屏幕。
To view the debug console on a real device, simple put in a call to pushScreen(new AntairLogScreen()). The screen has a built-in menu item to clear the persisted log messages, and will dismiss itself like a regular application screen.
如果您正在运行的RIM编译器preprocessor开发,QA之间切换,并且产品构建,您可以简单地把在呼叫设置的 Debug.ENABLED = FALSE 作为一切,但在开发版本,并调试控制台将在那里当你需要调试和悄悄离去,当你不需要它。
If you’re running the RIM compiler preprocessor to switch between development, QA, and production builds, you can simply put in a call to set Debug.ENABLED = false for everything but the development builds, and the debug console will be there when you need to debug and go away quietly when you don’t need it.
在code如下。
// ---------------------------------------------------------------------------
// Antair Debug Log (for the BlackBerry API)
// http://www.antair.com
// ---------------------------------------------------------------------------
package com.antair.examples.debug;
import net.rim.device.api.i18n.SimpleDateFormat;
import java.util.Date;
import net.rim.device.api.collection.util.BigVector;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.Persistable;
final class Debug implements Persistable
{
final static boolean ENABLED = true;
final static String TAGID = "MY_PROJECT";
final static long PERSISTENCE_GUID = /* YOUR OWN PERSISTENCE GUID */;
private BigVector _messages = new BigVector();
static String print(String str)
{
if ( Debug.ENABLED )
{
StringBuffer sb = new StringBuffer();
sb.append(TAGID);
sb.append("\n");
sb.append(Thread.currentThread().toString());
sb.append("\n");
sb.append(new SimpleDateFormat("MM/dd/yy HH:mm:ss:SSS").format(
new Date()));
sb.append("\n");
sb.append(str); sb.append("\n");
str = sb.toString();
System.out.println(str);
System.out.flush();
Debug d = load();
d._messages.addElement(str);
save(d);
}
return str;
}
static BigVector getPersistedMessages()
{
return load()._messages;
}
static void clearPersistedMessages()
{
save(new Debug());
}
private static Debug load()
{
Debug d = null;
try
{
PersistentObject po =
PersistentStore.getPersistentObject(Debug.PERSISTENCE_GUID);
synchronized(po)
{
Object obj = po.getContents();
d = (obj == null) ? new Debug() : (Debug)obj;
}
}
catch ( Exception e )
{
d = new Debug();
}
return d;
}
private static void save(Debug d)
{
try
{
PersistentObject po =
PersistentStore.getPersistentObject(Debug.PERSISTENCE_GUID);
synchronized(po)
{
po.setContents(d);
po.commit();
}
}
catch ( Exception e )
{
}
}
}
final class ClearAntairLogScreenMenuItem extends MenuItem
{
ClearAntairLogScreenMenuItem(int position)
{
super("Clear Log", position, 0);
}
public void run()
{
Debug.clearPersistedMessages();
}
}
final class AntairLogScreen extends MainScreen
{
AntairLogScreen()
{
super(MainScreen.DEFAULT_CLOSE|MainScreen.DEFAULT_MENU);
StringBuffer text = new StringBuffer();
BigVector logItems = Debug.getPersistedMessages();
for ( int i = 0 ; i < logItems.size() ; ++i )
{
text.append((String)logItems.elementAt(i) + "\n");
}
add(new RichTextField(text.toString()));
}
protected void makeMenu ( Menu menu, int instance )
{
menu.add(new ClearAntairLogScreenMenuItem(100000));
}
}
这篇关于黑莓日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!