简体   繁体   English

如何使用Log4J设置我的BlazeDS实现?

[英]How can I setup my BlazeDS implementation with Log4J?

I'm writing a Flex app on top of a Java web application using BlazeDS. 我正在使用BlazeDS在Java Web应用程序上编写Flex应用程序。 BlazeDS has logging inside of it, but I want to set it up to Use the same logging framework I have in my application. BlazeDS已在其中记录,但我想将其设置为使用我在我的应用程序中使用的相同日志框架。

Is there a way to setup BlazeDS to use Log4J? 有没有办法设置BlazeDS使用Log4J? Or am I stuck with the Flex logging stuff that's already baked into BlazeDS? 还是我坚持使用已经在BlazeDS中烘焙的Flex日志记录?

No, out of box BlazeDS does not support log4j or other frameworks directly. 不,开箱即用BlazeDS不直接支持log4j或其他框架。

However, it's really simple to add support for your favourite logging framework; 但是,添加对您喜欢的日志记录框架的支持非常简单; I used the following to get the output into SLF4J : 我使用以下内容将输出输入SLF4J

package example;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import flex.messaging.log.AbstractTarget;
import flex.messaging.log.LogEvent;

public class Slf4jTarget extends AbstractTarget {
    // log4j levels:   OFF - FATAL - ERROR - WARN - INFO - DEBUG - TRACE - ALL
    // blazeds levels:  NONE - FATAL - ERROR - WARN - INFO - DEBUG - ALL

    @Override
    public void logEvent(LogEvent event) {
        Logger log = LoggerFactory.getLogger(event.logger.getCategory());

        if (event.level >= LogEvent.ERROR)
            log.error(event.message, event.throwable);
        else if (event.level >= LogEvent.WARN)
            log.warn(event.message, event.throwable);
        else if (event.level >= LogEvent.INFO)
             log.info(event.message, event.throwable);
        else if (event.level >= LogEvent.DEBUG)
             log.debug(event.message, event.throwable);
        else
             log.trace(event.message, event.throwable);
    }
}

.. and to use it, enable it in services-config.xml : ..并使用它,在services-config.xml启用它:

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
    <logging>
        <target class="example.Slf4jTarget" level="Info">
    </logging>
</services-config>

Use CommonsLoggingTarget. 使用CommonsLoggingTarget。

See http://static.springsource.org/spring-flex/docs/1.0.x/javadoc-api/org/springframework/flex/core/CommonsLoggingTarget.html . 请参阅http://static.springsource.org/spring-flex/docs/1.0.x/javadoc-api/org/springframework/flex/core/CommonsLoggingTarget.html

Just be careful with setting log level in service-config.xml. 请注意在service-config.xml中设置日志级别。 If you set it to "All", and define "blazeds" logger in log4j.xml, then there will be a lot of redundant log messages generated by BlazeDS/LCDS, which might have significant performance impact. 如果将其设置为“All”,并在log4j.xml中定义“blazeds”记录器,则BlazeDS / LCDS将生成大量冗余日志消息,这可能会对性能产生重大影响。

I don't believe that there is anything built-in that allows you to redirect Blaze DS logging output to log4j, commons-logging, etc. However this JIRA issue may be of use to you: 我不相信有任何内置允许您将Blaze DS日志记录输出重定向到log4j,commons-logging等。但是这个JIRA问题可能对您有用:

http://jira.springframework.org/browse/FLEX-18 http://jira.springframework.org/browse/FLEX-18

Includes a Java class to redirect output and sample configuration for services-config.xml 包含一个Java类,用于重定向services-config.xml的输出和示例配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM