Page 1 of 1
Tracing from custom class.
Posted: 23 Feb 2011, 14:00
by Rotty956
Hey everyone
How would one trace messages from the custom class one that isn't inheriting and smartfox classes? Can I import something? Do I need to extend a base class? Do I need create an object of some sort?
Posted: 24 Feb 2011, 05:37
by tchen
1) Include the library log4j-1.2.15.jar
2) Then edit log4j.properties and include a line for your namespace
log4j.category.com.mycompany=TRACE,consoleAppender,fileAppender
3) Add import org.apache.log4j.Logger to your code
4) When logging, use
Logger.getLogger(MyClass.class).trace("Yadda Yadda");
Posted: 25 Feb 2011, 07:44
by rav
Is it good practice to keep static reference on SFSExtension class? and call something like that:
MySFSExtension.getInst()._trace("aaa")
or
MySFSExtension._strace("bbb")
Code: Select all
class MySFSExtension extends SFSExtension
{
private static MySFSExtension ext;
public void init()
{
ext= this;
}
public static SFSExtension getInst()
{
return ext;
}
public static void _strace(String msg)
{
getInst()._strace("strace from MySFSExtension : " + msg);
}
public void _trace(String msg)
{
trace("trace from MySFSExtension : " + msg);
}
}
Posted: 25 Feb 2011, 23:22
by tchen
What you have works, but it's opening a Pandora's box - especially once you start having state in that static object.
Log4j is a relatively common logger used in Java and its also what SFS is using directly under the hood whenever you call SFSExtension.trace.
You also get the added benefit of not having tangled dependencies, and the additional ability to categorize your log categories.