Re: SLog needs some constants
Franck Routier <[email protected]> Tue, 06 Jul 2010 11:39:04 +0200
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Organization | Axège sarl |
| Message-ID | <1278409144.2397.18.camel@franck-laptop> |
Hi, actually SLog is here to be the simpliest logger possible. There is already a class extending SLog, which uses Slf4j (another pretty lightweight and easy to use standard, written by the same guy who wrote log4j at first). Slf4j is only an PAI, and you can choose the actual logger, that can be log4j, commons logging, logback, etc. So I would say that instead of introducing another dependency, you can use the SLogSlf4j class, and configure you application to use log4j as the actual logger. See http://www.slf4j.org/manual.html#binding To use this logging API, you must: 1) SLog.setSlogClass(SLogSlf4j.class); somewhere early in you app (in you servlet init sequence for example) 2) make sure you have a slf4j implementation in your classpath (logback, simplelogger, etc.) HTH, Franck Le mardi 06 juillet 2010 à 10:15 +0100, John Abraham a écrit : > > I extended SLog to use Log4j. I forget why, but I couldn't do it > outside SimpleORM, so now my version of SimpleORM is dependent on > Log4J. > > > > It would be nice, actually, if SLog was replaced by log4j. Log4j is a > pretty lightweight and easy to use standard. > > > Here is my class > > > package simpleorm.utils; > > > import org.apache.log4j.Logger; > > > /** > * An implementation of SLog to allow Simpleorm to log via log4j. > * Log level is then controlled by log4j, not by SLog.slog.level. > * > * Mapping between SLog and slf4j log levels is: > * > * To use this logging API, you must: > * 1) SLog.setSlogClass(SLogLog4j.class); somewhere early in you app > (in you servlet init sequence for example) > * 2) make sure you have log4j in your classpath > * > * @author [email protected] based on original code by > [email protected] > * > */ > public class SLogLog4j extends SLog { > > Logger log = Logger.getLogger(SLogLog4j.class); > > > public int level = 10; > > > public void error(String msg) { // Rarely used, normally throw > instead. > log.error("#### -ERROR " + sessionToString() + "_" + msg); > } > > > public void warn(String msg) { > log.warn("## -WARN " + sessionToString() + "_" + msg); > } > > > < > span style="color: #000000;"> // Open, begin, commit etc. > public void connections(String msg) { > log.info(" -" + msg); > } > > > // During flushing > public boolean enableUpdates() { > return log.isDebugEnabled(); > } > > > public void updates(String msg) { > if (enableUpdates()) > log.debug(" -" + msg); > } > > > // select() or findOrCreate() > public boolean enableQueries() { > return log.isDebugEnabled(); > } > > > public void queries(String msg) { > if (enableQueries()) > log.debug(" -" + msg); > } > > > /** > * set/get per field. enableFields enables the trace line to be > surounded by > * an if test which is important as fields are an inner loop trace and > the > * StringBuffer concatenation can be very expensive! > */ > public boolean enableFields() { > return false; > } > > > public void fields(String msg) { > if (enableFields()) > log.debug(" -" + msg); > } > > > /** For detailed temporary traces during development only. */ > public boolean enableDebug() { > return log.isDebugEnabled(); > } > > > public void debug(String msg) { > log.debug(" -" + "(" + msg + ")"); > } > > > /** > * For messages that are the ouput, eg. of unit test programs. Never > * disabled. > */< > /span> > public void message(String msg) { > log.warn(" ---" + msg); > } > > > public static String arrayToString(Object[] array) { > if (array == null) > return "NULL"; > StringBuffer res = new StringBuffer("[Array "); > for (int ax = 0; ax < array.length; ax++) { > if (ax > 0) > res.append("|"); > res.append(array[ax]); > } > res.append("]"); > return res.toString(); > } > > > > } > > > > > > > > On 2010-07-06, at 9:05 AM, Noel Grandin wrote: > > > > > Hi > > > > It would be nice if the SLog class declared some constants for the > > log levels. At the very least I'd expect to see constants for > > LOG_NONE > > LOG_DEBUG > > > > > > Regards, Noel Grandin > > > > > > > > > > > > > > ____________________________________________________________________ > > Disclaimer: http://www.peralex.com/disclaimer.html > > > > > > > > > ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/SimpleORM/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/SimpleORM/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/