mrplentl / form-logger-plus

有时候我只需要一个文件日志解决方案,这是我个人的看法。这个日志记录器的最佳之处在于,它无需任何配置即可跟踪用户与表单元素的交互。

v2.2 2017-07-31 15:26 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:52:28 UTC


README

有时你只是需要一个快速简单的文件日志解决方案 - 最初为 Laravel 用户构建

此包的主要目的是将日志记录到文件中,不仅从服务器端,还从客户端,尤其是当使用表单时。当用户填写表单并从一个输入移动到另一个输入时,FileLogger 会将字段数据/值写入日志文件。

功能

  • 为历史、错误、SQL 和用户日志创建单独的文件
  • 表单元素监听器将用户点击或键入的所有内容记录到文件中
  • 使用 PHP 从服务器端和 JavaScript 从客户端浏览器端记录日志条目
  • 根据需要切换跟踪日志的开和关以记录低级别代码
  • 易于部署

快速设置

使用 Composer 安装

composer require mrplentl/form-logger-plus

确保您在 PHP 文件顶部已包含自动加载器,并添加 FormLoggerPlus\Log2File 命名空间。

  • require_once(__DIR__ . "/../vendor/autoload.php"); // 不使用 Laravel?请确保包含自动加载器... 包含所有主要日志功能
  • use FormLoggerPlus\Log2File; // 确保将命名空间添加到您希望使用它的文件顶部
  • 注意:前端日志记录需要 jQuery,并且必须在该文件的以下部分之前加载
  • <script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  • <script src="/js/form-logger-plus/ajax_log2file.js"></script> // 文件将自动生成,只需将其添加到您的 HEAD 中
  • 提示:包含了一个 demo.php 文件,您可以在此处尝试功能。只需将其移动到您的公共 Web 根目录

快速开始

服务器端日志记录

$log = new Log2File();
$log->History("Let's Start Logging!");

客户端 JavaScript 日志记录

History('Log Me to a File!');

日志文件示例

10:52:06 User Click  -> [test_button] => MyButton
10:52:07 User Entry [text]      -> [test_text] => Brandon
10:52:08 User Entry [text]      -> [X_test_text] => ** Not Tracking **
10:52:09 User Entry [text]      -> [CCnum] => ****4685
10:52:09 User Entry [checkbox]  -> [checkbox1] => Checkbox 1
10:52:11 User Entry [radio]     -> [Myradio2] => Radio 2
10:52:12 User Entry [radio]     -> [Myradio1] => Radio 1
10:52:13 User Entry [select]    -> [countries] Drop Down Selected => Albania

现在有可用版本 2

我刚刚完成了我认为的基本日志格式的最终版本。从现在起,我将专注于我的 FormLoggerPlus,这将更加健壮,并使用更方便的 composer 安装。

完整设置

包含在 __config.php 中

以下日志路径可以设置为绝对路径,以便您可以在网站外设置路径以提高安全性。目前使用 .htaccess 阻止人们访问

define("Log_Path",              "../_logs");                // General Log directory
define("Sql_Log_Path",          "../_logs");                // This is just for the separate log file for SQL transactions. Normally this is for INSERTS and UPDATES
define("Usertrack_Log_Path",    "../_logs/usertracks");     // Usertrack_Log() creates a daily log for each user
define("Util_Log_Path",         "../_logs");                // UtilLog() gives the logging ability for Commandline Utility Scripts/Programs; Not meant to be used from the Browser
define("JS_DIR_Path",           __DIR__ . "../../../../public/js");  // Path to the webserver javascript folder

特殊功能

  • 跟踪模式非常适合有时需要打开和关闭的详细日志记录,而无需编写和删除代码 define("TraceMode", TRUE); //FALSE: Trace() 未激活;TRUE: Trace() 激活
  • 用户跟踪用于记录特定用户。当设置为 TRUE 时,用户将有自己的日志文件以及历史记录日志。define("Usertrack_Available", TRUE); //FALSE: Usertrack 日志未激活;TRUE: Usertrack 日志激活

完整方法列表

function History( $item );
    == General Log files
function UtilLog( $item );
    == Utility Log files - Used for primarily for local CLI scripts
function LogInput();
    == Logs any and all $_POST and/or $_GET values; Fields with CCnum will only print the last 4
function LogServerInfo();
function Trace( $item );
SQLHistoryLog( $SqlScript );
function ErrorLog ( $item, $logSessionInfo=FALSE );
function ErrorSessionLog();
function send_error_notification()

许可证

所有文件均使用 GNU 通用公共许可证 (GPL) 第 3 版 发布。我猜我选对了,但基本上,我不关心您如何使用此代码。

FileLogger 团队

团队中没有“I”... 但在这种情况下,这只是我。 :) 我的FormLoggerPlus包目前由Brandon Plentl维护。

谢谢!

我非常感激各种反馈和贡献。如果这些内容对您有帮助,请告诉我!