Log4j中如何设置输出日志文件名和路径?

发布于 2024-12-23 14:17:50 字数 114 浏览 2 评论 0原文

我正在使用 Log4j API 来维护 Android 应用程序中的日志。我是安卓新手。我已经下载了与此相关的 .JAR 文件。现在我想将日志文件存储到 SD 卡上。那么我应该在哪里写输出文件名&它的路径?

I am using Log4j API for maintaining logs in my Android Application. I am new to Android. I have Downloaded .JAR file regarding this. Now I want to store the log file on to SD Card. So where should I write output file name & its path ?

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

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

发布评论

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

评论(2

佼人 2024-12-30 14:17:50

我不知道Log4j,但是,在Android上写入文件的简单描述是这样的:

首先,在Manifest中声明写入外部存储的权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

然后,在你的代码中:

String filename = Environment.getExternalStorageDirectory() + "/" + [Your filename];

现在你可以在这个文件中写入任何内容。

I don't know about Log4j but, simple description of file writing on Android is like that:

first, declare permission in Manifest to write external storage :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

Then, in your code:

String filename = Environment.getExternalStorageDirectory() + "/" + [Your filename];

Now You can write whatever in this file.

花开浅夏 2024-12-30 14:17:50

您需要添加附加程序(将日志附加到文件或标准输出等的位置)
此处给出的配置xml文件中,您的兴趣就在这里

#define the appender named
FILE log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${user.home}/log.out

You need to add appender ( where to append the log.. to a file or standard output etc )
In the configuration xml file given here ,your interest lies here

#define the appender named
FILE log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${user.home}/log.out
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文