【问题标题】:How to log "send failed" to a file instead of showing a pop-up message如何将“发送失败”记录到文件而不是显示弹出消息
【发布时间】:2015-01-13 20:17:43
【问题描述】:

我在 Linux 上使用 Flex 4.1,但我想这个问题一定是所有 Flex 版本的共同问题。

我正在开发一个通过 BlazeDS 连接到 Java 后端(在 Tomcat 中)的 Flex 客户端前端。所有这些在 99.9% 的情况下都可以正常工作。但是,有时(假设客户端浏览器已打开几个小时),用户会收到一条弹出消息,提示“发送失败”。这似乎是一个无害的暂时性错误——如果用户关闭弹出窗口,前端会照常进行,并且似乎继续按预期工作。

有没有办法将“发送失败”消息写入日志文件而不是打开弹出消息?

作为一个单独的问题,如果有人看到偶尔的、短暂的“发送失败”错误,我很想听听。如果你有办法让它们消失,那就太好了。

【问题讨论】:

  • 一个单独的问题应该是一个单独的问题。

标签: actionscript-3 apache-flex flex4 blazeds


【解决方案1】:

解决方案 1:使用简单的trace() feature

  1. 安装debugger version of Flash Player
  2. 在您的 mm.cfg 文件中将 TraceOutputFileEnable 设置为 1
  3. 您的应用程序日志将在“flashlog.txt”文件中(参见Log file location
  4. 使用trace("message") 将您的消息记录到“flashlog.txt”文件中。

解决方案 2:Use logging API

<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    creationComplete="initLogging();"
    height="600">

    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout>

    <fx:Script>
        <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.logging.targets.*;
        import mx.logging.*;

        [Bindable]
        public var myData:ArrayCollection;

        private function initLogging():void {
            /* Create a target. */
            var logTarget:TraceTarget = new TraceTarget();

            /* Log only messages for the classes in the mx.rpc.* and 
               mx.messaging packages. */
            logTarget.filters=["mx.rpc.*","mx.messaging.*"];

            /* Log all log levels. */
            logTarget.level = LogEventLevel.ALL;

            /* Add date, time, category, and log level to the output. */
            logTarget.includeDate = true;
            logTarget.includeTime = true;
            logTarget.includeCategory = true;
            logTarget.includeLevel = true;

            /* Begin logging. */
            Log.addTarget(logTarget);
        }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- HTTPService is in the mx.rpc.http.* package -->
        <mx:HTTPService id="srv" 
            url="../assets/trace_example_data.xml" 
            useProxy="false" 
            result="myData=ArrayCollection(srv.lastResult.data.result)"/>
    </fx:Declarations>

    <mx:LineChart id="chart" dataProvider="{myData}" showDataTips="true">
        <mx:horizontalAxis>
            <mx:CategoryAxis categoryField="month"/>
        </mx:horizontalAxis>
        <mx:series>
            <mx:LineSeries yField="apple" name="Apple"/>
            <mx:LineSeries yField="orange" name="Orange"/>
            <mx:LineSeries yField="banana" name="Banana"/>
        </mx:series>
    </mx:LineChart>

    <s:Button id="b1" click="srv.send();" label="Load Data"/>

</s:Application>

【讨论】:

    猜你喜欢
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多