记录到 Flex 中的本地文件

发布于 2024-11-03 11:54:58 字数 211 浏览 1 评论 0原文

我的应用程序前端是用 Flex 3 开发的。 对于日志记录,我们有时使用跟踪和记录器,但我们没有特定的方法将日志存储在用户计算机的本地文件中。

事实上,我从 Adob​​e livedocs 中了解到,flashplayer 会自行管理 flashlog.txt 文件中的所有日志。

还有其他方法可以维护日志副本吗?每次执行“注销”时,flashlog.txt 都会被清除。

I have my application frontend developed in Flex 3.
For logging, we are using traces and Logger at times yet we dont have a specific way to store logs in a local file of User's machine.

In fact, what I learned from Adobe livedocs is that flashplayer manages itself all logs in flashlog.txt file.

Is there any other way I can maintain a copy of logs? flashlog.txt gets cleared everytime we perform "Logout".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丘比特射中我 2024-11-10 11:54:58

您没有提到您的应用程序是桌面应用程序还是基于浏览器的应用程序。

对于桌面应用程序,您可以编写一个新类;

import mx.core.mx_internal; 
use namespace mx_internal;

public class LoggingFileTarget extends LineFormattedTarget {
        private const DEFAULT_LOG_PATH:String = "C:/mylogfile.txt";

        private var log:File;

        public function LoggingFileTarget(logFile:File = null) {
            if(logFile != null) {
                log = logFile;
            } else {
                log = new File(DEFAULT_LOG_PATH);
            }
        }

        public function get logURI():String {
            return log.url;
        }

        mx_internal override function internalLog(message:String):void {
            write(message);
        }           

        private function write(msg:String):void {               
            var fs:FileStream = new FileStream();
            try {
                fs.open(log, FileMode.APPEND);
                fs.writeUTFBytes(msg + "\n");
                fs.close();
            } catch(e:Error) {
                trace("FATAL:: Unable to write to log file.");
            }
        }

        public function clear():void {
            var fs:FileStream = new FileStream();
            fs.open(log, FileMode.WRITE);
            fs.writeUTFBytes("");
            fs.close();                     
        }
    }

对于基于浏览器的应用程序,您可以继续写入内存中的字符串或本地共享对象。使用共享的本地对象,不断附加到日志,然后通过网络调用进行整理。

You have not mentioned whether your application is a desktop application, or a browser based.

In case of a desktop application you can write a new class,

import mx.core.mx_internal; 
use namespace mx_internal;

public class LoggingFileTarget extends LineFormattedTarget {
        private const DEFAULT_LOG_PATH:String = "C:/mylogfile.txt";

        private var log:File;

        public function LoggingFileTarget(logFile:File = null) {
            if(logFile != null) {
                log = logFile;
            } else {
                log = new File(DEFAULT_LOG_PATH);
            }
        }

        public function get logURI():String {
            return log.url;
        }

        mx_internal override function internalLog(message:String):void {
            write(message);
        }           

        private function write(msg:String):void {               
            var fs:FileStream = new FileStream();
            try {
                fs.open(log, FileMode.APPEND);
                fs.writeUTFBytes(msg + "\n");
                fs.close();
            } catch(e:Error) {
                trace("FATAL:: Unable to write to log file.");
            }
        }

        public function clear():void {
            var fs:FileStream = new FileStream();
            fs.open(log, FileMode.WRITE);
            fs.writeUTFBytes("");
            fs.close();                     
        }
    }

In case of a browser based application, you can keep writing either to an in-memory string, or to a local shared object. Using a shared local object, keep appending to logs, and then collate via a web call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文