我试图写一个奖励系统,其中用户如果下载完整的文件,会得到奖励积分,那么我的日志格式应该是什么。
search了很多后,这是我第一次了解它,并没有做过自定义日志。
首先应该为定制日志编辑哪个文件 ,因为这个东西我不能find。 我使用默认的Apache,PHP5和MySQL安装的Ubuntu服务器
# I use this commands and they work fine nano /etc/apache2/apache2.conf /etc/init.d/apache2 restart
我认为这是我需要为我的目的而做的
LogLevel notice LogFormat "%f %u %x %o" rewards CustomLog /var/www/logs/rewards_log rewards
这是命令还是有缺失? 有什么特殊的地方我需要添加这个?
还有一件事是%o是发送的文件大小,是否可以只logging特定目录中的文件? 或者大于10MB的文件。
谢谢。
Apache服务器文档是你的朋友: http : //httpd.apache.org/docs/2.1/mod/mod_log_config.html#customlog
CustomLog条目要么在全局范围内,要么在虚拟主机中。 在Ubuntu中,你应该有一个站点可用和站点启用的目录。 如果你不使用虚拟主机,这应该在/ etc / apache2 / sites-availabe / default文件中
据我所知,你不能做每个目录的自定义日志,但是这不应该太难用你用来parsingapache日志
你有没有想过使用Web平台来处理下载,并将这些下载logging到数据库? Apache看起来很麻烦。
下面是Myna中的一个例子,但是您可以在PHP,ColdFusion等中执行类似的操作:
示例链接:
<a href="/myna/download.sjs?f=somefile.pdf">
download.sjs页面:
// assumes a table a called "downloads" in the database "my_app" // also assumes that the user has authenticated and has auth cookie var downloads = new Myna.DataManager("my_app").getManager("downloads") //clean the filename var filename = $req.rawData.f.replace(/\.\.\//g,""); //get the data...should really check for failure here var data = new Myna.File("file:/var/files/" + filename).readBinary(); //log the download to the DB downloads.create({ userid:$cookie.getAuthUserId(), filename:f, ts:new Date() }) //send the binary data to the browser $res.prinBinary(data,"application/octet-stream",filename);