??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
]]>
使用FrontPage可以很方便的预览vm文gQ见梁夏峰的?font color="#ff0000">Velocity之Web实践》一文:http://www.javayou.com/showlog.jspe?log_id=528Q其中这栯道:“
打开FrontPageQ或其他cM工具Q网늼辑器Q点?quot;工具Q选项Q配|编辑器"Q上面列ZFrontPage能打开的文Ӟ点击dQ填入文件类型:vmQ编辑器名称QFrontPageQ命令:C:\Program Files\Microsoft Office\Office\frontpg.exeQFrontPageq行的完整\径,可从已有的文件类型中Copy出完整\径)Q点L开界面的确定后Q我们从FrontPage的文件菜单中选择打开文gQ选择上面新徏的sample.vmQ怎么P~辑、预览和修改都一目了然吧Q如下图Q,即不清楚VTL的,也可以通过单的手册查询知道Q一般都不会用到吧)Q这样对于网设计师、开发h员和l护人员来说Q都是很Ҏ的事。而如果你使用了一些开发工P如Jbuilder则在toolsQproference的编辑类型里Q在Html档增?vm的支持,则就可以q行~辑和用html预览器预览了Q其他的开发工兯己摸索吧?font color="#000000"> ”
然而在DreamWeaver中我怎么h配置也不行。于是用google大神上网求助Q终于发Cq个好东西:DreamWeaver的Velocity插gQ?a >http://velocity.gilluminate.com/Q作者比我强多了Q自己动手,丰衣食啊,呵呵。下载后用用DreamWeaver的插件管理器安装Q对Q就是那个VelocitySuite.mxp文g?/font>
q样一来,DreamWeaver在编辑vm时能提供的功能就大大过其他html~辑器了。爽啊?/p>
不过作者还说了几个注意点,如果你在使用q程中觉得有问题Q可以去他的主页http://velocity.gilluminate.com/看看。这里就不再多言了?br />
原文作者:天才 Kylin目组
log4j?br />单的说log4j是帮助开发h员进行日志输出管理的APIcd。它最重要的特点就import org.apache.log4j.*;
public class LogTest {
static Logger logger = Logger.getLogger(LogTest.class.getName());
public static void main(String[] args) {
PropertyConfigurator.configure ( “.\\src\log4j.properties”)Q?br />logger.debug("Debug ...");
logger.info("Info ...");
logger.warn("Warn ...");
logger.error("Error ...");
}
}
E序说明Q?br />?static Logger logger = Logger.getLogger(LogTest.class.getName());是创徏一个属于LogTestcȝLogger对象Q创建时要告知Logger你当前的Class是什么?br />?font size="2"> PropertyConfigurator.configure ( “log4j.properties”)是说用当前工E目录下的src文g夹中的log4j.properties文g作ؓ配置文g。若log4j.properties攑֜工程根目录下也可不写此句Q程序会自动扑ֈ配置文g?br />?logger.debug是输出debug的信息,logger.info是输出提示信息Qlogger.warn是昄警告信息Qlogger.error是昄错误信息?br />下面是配|文件log4j.properties的内容:
log4j.rootCategory=DEBUG, stdoutQR
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log.txt
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy MMM dd HH:mm:ss} %-5p %c - %m%n
E序说明Q?br />?log4j.rootCategory=DEBUG, stdoutQR
是说我要显C所有优先权{於和高于Debug的信息?br />"stdout"Q?rdquo;R”表示我定义了两个输出?随便什么名字都??br />②下面的三行说stdout输出端其实是标准输出ConsoleQ也是屏幕。输出的格式是PatternLayout。{换方式是%5p (%F:%L) - %m%nQ即前五格用来显CZ先权Q再昄当前的文件名Q加当前的行数。最后是logger.debug()或logger.info()或logger.warn()或logger.error()里的信息?n表示回RI?br />③再加上下面六行则log信息不光昄在屏q上Q而且被保存在一个叫"log.txt"的文仉Q文件最大ؓ100KB。如果文件大超q?00KBQ文件会被备份成"log.txt.1"Q新?quot;log.txt"l箋记录log信息?br />接下来我们可以改变log4j.propertiesQ而不需重新~译可以控制log信息是否昄、log信息的输出端cd、输出方式、输出格式,{等。D例如下:
①在log4j.properties文g里把"log4j.rootCategory=DEBUG,stdout,R"改写?quot;log4j.rootCategory=OFF, stdout,R"Q这h有的log信息都不会显CZQ解决了本文开始提出的问题?br />②在log4j.properties文g里把"log4j.rootCategory=DEBUG,stdout,R"改写?quot;log4j.rootCategory=INFO, stdout,R"Q这样只昄INFO, WARN, ERROR的log信息Q而DEBUG信息不会被显C;
在webE序中用log4j注意问题
1?nbsp; ׃jsp或servlet在执行状态时没有当前路径概念Q所有用PropertyConfigurator.configureQStringQ语句找log4j.properties文g时要l出相对于当前jsp或servlet的\径{化成Z个绝对的文gpȝ路径。方法是使用servletcontext.getrealpath(string)语句。例Q?br />//得到当前jsp路径
String prefix = getServletContext().getRealPath("/");
//dlog4j.properties
PropertyConfigurator.configure(prefix+"\\WEB-INF\\log4j.properties");
2、相应的log4j.properties讄某个属性时也要在程序中讄l对路径。例Q?br />log4j.appender.R.File属性设|日志文件存放位|。我们可以用d.properties配置文g的方法进行灵z设|?br />
log4e使用说明
在了解了log4j的功能后Q我们肯定会我们的程序中~写一些Log4j日志记录。对于用Eclipse的程序员Log4e是我们最得力的log4j日志~写助手Q现在开始Log4e之旅?br />Log4e是一个免费的Eclipse PluginQ它可帮助你在你的Java工程中快速加入LogQ?我们可以?a >http://log4e.jayefem.de/index.php/Download|站上下载Log4e最新版本。下载后相应文件夹拯到Eclipse的插件目录下Q重新EclipseQ在首选项中会多出一?span>Log4e选项?br />Log4e可以有多个插入LogZ个方法、类Q当然也可以在当前位|插入LogQ同时其也可以把Sysout.out.println()的{换ؓlogQ所有的q一切只需要你点点鼠标或者按一ơ快捷键?font size="2">
Log4e的实例参?a >http://log4e.jayefem.de
原文来自?a >http://log4e.jayefem.de/index.php/Log4E:FAQ
If you are already familiar with your logging framework you might want to skip this section.
This chapter gives you a slight idea of how to make the initial setup of your logger. This is NOT supported by Log4E at the moment and was not the intended use at the beginning of this project.
Log4E does not ship any logging framework which means that you have to download and install it for yourself!
Examples are available for Log4j, Commons Logging, JDK 1.4 Logging (again: you have to do this for yourself).
.../MyEclipseProject/ .../MyEclipseProject/src/log4j.properties .../MyEclipseProject/src/com/mycompany/myapp/...
3. Edit the 'log4j.properties' to declare your own categories, log levels and appenders (which means the output like standard out or a log file).
log4j.properties example:
####################################################################### # Categories and levels ####################################################################### log4j.rootCategory=ERROR, FileApp, ConApp log4j.category.de.jayefem=DEBUG ####################################################################### # Appenders ####################################################################### # ConApp is set to be a ConsoleAppender. log4j.appender.ConApp=org.apache.log4j.ConsoleAppender # ConApp uses PatternLayout. log4j.appender.ConApp.layout=org.apache.log4j.PatternLayout # Define Pattern log4j.appender.ConApp.layout.ConversionPattern=%d [%t] %-5p %c - %m%n # FileApp log4j.appender.FileApp=org.apache.log4j.RollingFileAppender log4j.appender.FileApp.File=D:/proj/Devel/Java/de.jayefem.log4e/log/log4e.log log4j.appender.FileApp.MaxFileSize=500KB # Keep one backup file log4j.appender.FileApp.MaxBackupIndex=1 log4j.appender.FileApp.layout=org.apache.log4j.PatternLayout log4j.appender.FileApp.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
"de.jayefem", "ConApp", "FileApp" and the path to the logfile are selfdefined. All other words are keywords of Log4j.
4. That's all. Have fun.
Note that there are much more possibilities to configure Log4j. Check http://logging.apache.org/ for more.
Jakarta Commons Logging Framework is a wrapper for all common logging frameworks. If you want to use it, you have to install it AND the underlying logging framework. To install the Commons Logging download it from http://jakarta.apache.org/commons/logging/ and put the commons-logging.jar in your lib directory.
The Commons Logging Frameworks uses Log4j by default. When Log4j isn't found in classpath and JDK 1.4 or higher is being used, the JDK 1.4 logger will be used. If none of the above applies, Commons Logging will fall back to the internal SimpleLog.
It is also possible to specify the logging framework directly:
1. Create a new file 'commons-logging.properties' and put it in your classpath. To be more concrete: Put it in your source directory, the file will be copied by Eclipse automatically to your build directory.
For example:
.../MyEclipseProject/ .../MyEclipseProject/src/commons-logging.properties .../MyEclipseProject/src/com/mycompany/myapp/...2. Edit the 'commons-logging.properties'.
# #org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl # SimpleLog #org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog # JDK 1.4 logger #org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger # Avalon Toolkit #org.apache.commons.logging.Log=org.apache.commons.logging.impl.LogKitLogger # Log4j org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
1. Create a new file 'simplelog.properties' and put it in your classpath. To be more concrete: Put it in your source directory, the file will be copied by Eclipse automatically to your build directory.
For example:
.../MyEclipseProject/ .../MyEclipseProject/src/simplelog.properties .../MyEclipseProject/src/com/mycompany/myapp/...2. Edit the 'simplelog.properties' to declare your own categories and log levels.
# Default logging detail level for all instances of SimpleLog. Must be one of # ("trace", "debug", "info", "warn", "error", or "fatal"). If not specified, # defaults to "info". org.apache.commons.logging.simplelog.defaultlog=warn # Logging detail level for a SimpleLog instance named "xxxxx". Must be one of # ("trace", "debug", "info", "warn", "error", or "fatal"). If not specified, the # default logging detail level is used. org.apache.commons.logging.simplelog.log.de.jayefem.log4e=debug # Set to true if you want the Log instance name to be included in output # messages. Defaults to false. org.apache.commons.logging.simplelog.showlogname=false # Set to true if you want the last componet of the name to be included in # output messages. Defaults to true. org.apache.commons.logging.simplelog.showShortLogname=true # Set to true if you want the current date and time to be included in output # messages. Default is false. org.apache.commons.logging.simplelog.showdatetime=true
See http://jakarta.apache.org/commons/logging/ for more.
logging.properties example:
# handlers handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler # general level .level=INFO # file handler java.util.logging.FileHandler.pattern = %h/java%u.log java.util.logging.FileHandler.limit = 50000 java.util.logging.FileHandler.count = 1 java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter # console handler java.util.logging.ConsoleHandler.level = FINEST java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter test.de.jayefem.log4e.logkits.JDK1_4_Logging.level = FINEST
Since I am not an expert of JDK 1.4 logging there might be better ways to configure the logging framework. Suggestions are welcome.
See http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html for more information.
最q发现Weblogic也是用的log4jQ呵c?/p>