[Java] Logging
[Java] Logging
SF server writes things to log files, with severity level like INFO, WARN, ERROR, etc. Obviously there is functionality inside SF to do this; is this exposed so that I can use it from my Java extension? Is SF using Log4J internally or is this a custom logger the SF developers wrote?
Thanks.
Thanks.
Yes you can. We don't use log4j, we use the java.util.logging package
If you use Actionscript we provide a specific object for logging (check the docs)
Under Java you can access the logger as a static member like this:
If you use Actionscript we provide a specific object for logging (check the docs)
Under Java you can access the logger as a static member like this:
Code: Select all
SmartFoxServer.log.info("Hello!")Sorry but as far as I can see from your JavaDocs (http://www.smartfoxserver.com/docs/docP ... index.html) there is no SmartFoxServer class. And I can't see any SFS class with a log attribute. Am I missing something?
Yes this is correct.
We are trying to avoid exposing all the classes in the javadocs and I admit it's not an easy task
We'd like to simplify the access to the framework as much as possible avoiding dozens of classes (with relative fields and methods) that developers will never use and that would just confuse them.
In doing this a few minor things have escaped (the logger is one) but the support board is here just for this sort of issues.
Hope it helps
We are trying to avoid exposing all the classes in the javadocs and I admit it's not an easy task
We'd like to simplify the access to the framework as much as possible avoiding dozens of classes (with relative fields and methods) that developers will never use and that would just confuse them.
In doing this a few minor things have escaped (the logger is one) but the support board is here just for this sort of issues.
Hope it helps
redirect SFS logging to Log4J
Hi!
I use Log4J for logging my own stuff but I would like to find the SFS log output in the same file. Is there a way to intercept the SFS logging?
I use Log4J for logging my own stuff but I would like to find the SFS log output in the same file. Is there a way to intercept the SFS logging?
I just came across this possibility:
I'll try that and post the result...
Code: Select all
SmartFoxServer.log.addHandler(new MyHandler());It's actually quite easy. For those who are interested I post my utility class:
Having that you just need to call
at program startup.
Code: Select all
public class SFSLog4JLogger extends java.util.logging.Handler {
private static final org.apache.log4j.Logger log =
org.apache.log4j.Logger.getLogger(SFSLog4JLogger.class);
@Override
public void close() throws SecurityException {}
@Override
public void flush() {}
@Override
public void publish(final java.util.logging.LogRecord record) {
// build msg (get more info out of the record if you like to)
String msg = record.getMessage();
// find level
org.apache.log4j.Level level = org.apache.log4j.Level.INFO;
if (java.util.logging.Level.SEVERE.equals(record.getLevel())) {
level = org.apache.log4j.Level.ERROR;
} else if (java.util.logging.Level.WARNING.equals(record.getLevel())) {
level = org.apache.log4j.Level.WARN;
} else if (java.util.logging.Level.INFO.equals(record.getLevel()) ||
java.util.logging.Level.CONFIG.equals(record.getLevel())) {
level = org.apache.log4j.Level.INFO;
} else if (java.util.logging.Level.FINE.equals(record.getLevel()) ||
java.util.logging.Level.FINER.equals(record.getLevel())) {
level = org.apache.log4j.Level.DEBUG;
} else if (java.util.logging.Level.FINEST.equals(record.getLevel())) {
level = org.apache.log4j.Level.TRACE;
}
// log
log.log(record.getSourceClassName(), level, msg, record.getThrown());
}
}
Code: Select all
SmartFoxServer.log.addHandler(new SFSLog4JLogger());async logging
Do you have a best practice to handle async logging other than using the Log4j Async appender thorough log4j logger?
asynchronous logging
asynchronous logging that in common logging is usually handled by
AsyncAppender.
Have you any best practice to avoid "in process logging" and process blocking or using the Log4JHandler with AsyncAppender is the recommended way?
Is there a built-in way to persist events on DB(for logging needs)?
Filippo
AsyncAppender.
Have you any best practice to avoid "in process logging" and process blocking or using the Log4JHandler with AsyncAppender is the recommended way?
Is there a built-in way to persist events on DB(for logging needs)?
Filippo
I see, put in simple words ... you're going to log to a potentially "slow" device (i.e. the DB) and wish to avoid blocking the current thread... right?
We don't have a best practice for this, and I've never used asynchronous logging myself, so I am not able to help here.
If Log4J helps in this regards it would probably be ok to use it.
An alternative is to add more threads to the ExtensionHandler stage of the server (see chapter 2.2). This way you don't incur into problems with "slow" operations.
Cheers
We don't have a best practice for this, and I've never used asynchronous logging myself, so I am not able to help here.
If Log4J helps in this regards it would probably be ok to use it.
An alternative is to add more threads to the ExtensionHandler stage of the server (see chapter 2.2). This way you don't incur into problems with "slow" operations.
Cheers