// Wrappers in Nice for the Apache Commons logging library. // Copyright (C) 2004 Bryn Keller // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import org.apache.commons.logging.*; //Clarify the Nice version: we don't allow nulls for the String argument. Log getLog(String name) = native Log LogFactory.getLog(String); void main(String[] args) { let log = getLog("Foo"); log.info(){ return "test"; } log.info(when: false){ System.out.println("This code doesn't get run"); return "You'll never see this"; } log.trace(when: true) { System.out.println("The TRACE level isn't enabled by default, so you won't see the following TRACE. But our condition was true, so the code DID run!"); return "You won't see this"; } log.error(err: new Exception("Hey!")) { return "Add an exception if you like."; } log.fatal("Of course, you can still use the old Java version, too!"); } /** * Writes an INFO message to the log, calling the provided method * to generate the message string. The method is only called if the * when parameter evalutates to true. By default, the * when parameter is true if the appropriate log level * is enabled on the logger. */ void info(Log logger, void->String message, ?Throwable err = null, boolean when = logger.isInfoEnabled()) { if (when) { info(logger, message(), err); } } /** * Writes a WARN message to the log, calling the provided method * to generate the message string. The method is only called if the * when parameter evalutates to true. By default, the * when parameter is true if the appropriate log level * is enabled on the logger. */ void warn(Log logger, void->String message, ?Throwable err = null, boolean when = logger.isWarnEnabled()) { if (when) { warn(logger, message(), err); } } /** * Writes an ERROR message to the log, calling the provided method * to generate the message string. The method is only called if the * when parameter evalutates to true. By default, the * when parameter is true if the appropriate log level * is enabled on the logger. */ void error(Log logger, void->String message, ?Throwable err = null, boolean when = logger.isErrorEnabled()) { if (when) { error(logger, message(), err); } } /** * Writes a FATAL message to the log, calling the provided method * to generate the message string. The method is only called if the * when parameter evalutates to true. By default, the * when parameter is true if the appropriate log level * is enabled on the logger. */ void fatal(Log logger, void->String message, ?Throwable err = null, boolean when = logger.isFatalEnabled()) { if (when) { fatal(logger, message(), err); } } /** * Writes a DEBUG message to the log, calling the provided method * to generate the message string. The method is only called if the * when parameter evalutates to true. By default, the * when parameter is true if the appropriate log level * is enabled on the logger. */ void debug(Log logger, void->String message, ?Throwable err = null, boolean when = logger.isDebugEnabled()) { if (when) { debug(logger, message(), err); } } /** * Writes a TRACE message to the log, calling the provided method * to generate the message string. The method is only called if the * when parameter evalutates to true. By default, the * when parameter is true if the appropriate log level * is enabled on the logger. */ void trace(Log logger, void->String message, ?Throwable err = null, boolean when = logger.isTraceEnabled()) { if (when) { trace(logger, message(), err); } }