欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Regulus343/ActivityLog ActivityLog 活动日志 记录操作日志 操作的日志

A simple and clean Laravel activity logger for monitoring user activity on a website or web application.
PHP
 
Upload filesFind file
New pull request
Latest commit 7f9c40b 16 days ago@Regulus343  added function description

 readme.md

ActivityLog

A simple and clean Laravel 5 activity logger for monitoring user activity on a website or web application.

Installation

Basic installation, service provider registration, and aliasing:

To install ActivityLog, make sure "regulus/activity-log" has been added to Laravel 5's composer.json file.

"require": {
	"regulus/activity-log": "0.6.*"
},

Then run php composer.phar update from the command line. Composer will install the ActivityLog package. Now, all you have to do is register the service provider and set up ActivityLog's alias. In app/config/app.php, add this to the providers array:

Regulus\ActivityLog\ActivityLogServiceProvider::class,

And add this to the aliases array:

'Activity' => Regulus\ActivityLog\Models\Activity::class,

Publishing migrations and configuration:

To publish this package's configuration and migrations, run this from the command line:

php artisan vendor:publish

You will now be able to edit the config file in config/log.php if you wish to customize the configuration of ActivityLog.

Note: Migrations are only published; remember to run them when ready.

To run migration to create ActivityLog's table, run this from the command line:

php artisan migrate

Basic Usage

Logging user activity:

	Activity::log([
		'contentId'   => $user->id,
		'contentType' => 'User',
		'action'      => 'Create',
		'description' => 'Created a User',
		'details'     => 'Username: '.$user->username,
		'updated'     => (bool) $id,
	]);

The above code will log an activity for the currently logged in user. The IP address will automatically be saved as well and the developer flag will be set if the user has a developer session variable set to true. This can be used to differentiate activities between the developer and the website administrator. The updated boolean, if set to true, will replace all instances of "Create" or "Add" with "Update" in the description and details fields.

Advanced Usage

As of version 0.6.0, ActivityLog has built in the ability to dynamically create descriptions based on language keys in Laravel's language files. If you would like to enable this feature without having to set language_key to true when you use the log()function, change defaults.language_key to true in the config file (it is not present by default so you will have to add it).

Logging user activity with language keys:

	Activity::log([
		'contentType' => 'Record',
		'description' => [
			'created_items', [ // "activity-log::descriptions.created_items" is ":user created :number :items."
				'number' => 2,
				'items'  => 'SPL|labels.record', // "labels.record" in this example has a string of "Record|Records"
			],
		],
		'details' => [
			'record',
			'This is Some Kind of Record',
		],
		'data' => [
			'category' => 'Content',
		],
	]);

	echo $activity->getDescription(); // may output "Unknown User created 2 records."

	echo $activity->getDetails(); // may output "Record: This is Some Kind of Record"

	echo $activity->getData('category'); // will output "Content"

In the example above, the items replacement variable in the description has a number of specified properties before the |character which separates them from the actual language variable. The available properties are as follows:

S - Return the "singular" string (in the case of "labels.record", "Record")
P - Return the "plural" string (in the case of "labels.record", "Records")
A - Prepend the string with "a" or "an" (example: "a record" instead of just "record")
L - Convert the string to lowercase

In our example above, you will see both singular ("S") and plural ("P") are being used. When both are used, the description builder looks for a number replacement variable to decide whether the singular or plural form should be used.

Note: The user replacement variable is automatically set based on the record's user ID.

Getting Linked Content

Set up the content_types config array like the following example:

	'item' => [
		'uri'       => 'view/:id',
		'subdomain' => 'items',
		'model'     => 'App\Models\Item',
	],

You can use getContentItem() to get the item based on the specified model (assuming, in the case of the above specified example, that your content type is set to "Item"). You can also use getUrl() to get the URL of the content item or getLinkedDescription() to get a linked description for the item.

Displaying Action Icons

Display an action icon based on config setup:

	echo $activity->getIconMarkup();

You can also use getIcon() to get just the icon class from which to build your own icon markup.


来自  https://github.com/Regulus343/ActivityLog

一个简单干净的Laravel活动记录器,用于监控网站或Web应用程序上的用户活动。
PHP
 
上传文件查找文件
新拉请求
最新提交 7f9c40b 16 days ago@Regulus343  增加了功能描述

 readme.md

活动日志

一个简单干净的Laravel 5活动记录器,用于监控网站或Web应用程序上的用户活动。

安装

基本安装,服务提供商注册和别名:

要安装ActivityLog,请确保在Laravel 5的composer.json文件中添加了“regulus / activity-log” 

"require": {
	"regulus/activity-log": "0.6.*"
},

然后从命令行运行php composer.phar updateComposer将安装ActivityLog包。现在,您所要做的就是注册服务提供商并设置ActivityLog的别名。app/config/app.php,将其添加到providers数组中:

Regulus\ActivityLog\ActivityLogServiceProvider::class,

并将其添加到aliases数组中:

'Activity' => Regulus\ActivityLog\Models\Activity::class,

发布迁移和配置:

要发布此软件包的配置和迁移,请从命令行运行此软件包:

php artisan vendor:publish

config/log.php如果要自定义ActivityLog 的配置,现在可以编辑配置文件

注意:迁移仅发布; 记得准备运行它们。

要运行迁移以创建ActivityLog表,请从命令行运行:

php artisan migrate

基本用法

记录用户活动:

	Activity :: log([ 
' contentId ' => $ user - > id' contentType ' => ' User '' action ' => ' Create '' description ' => '创建用户'' details ' = > '用户名:'$用户- > 用户名'更新'=>bool$ id	]);		    
		  
		       
		  
		      
		     

上述代码将记录当前登录用户的活动。IP地址也将自动保存,developer如果用户developer设置会话变量,则该标志将被设置true这可以用于区分开发人员和网站管理员之间的活动。updated布尔值,如果设置为true,将取代“创建”或与“更新”“添加”的所有实例descriptiondetails领域。

高级用法

从版本开始0.6.0,ActivityLog内置了基于Laravel语言文件中的语言键动态创建描述的功能。如果您想启用此功能,而无需设置language_keytrue当您使用log()函数,改变defaults.language_keytrue在配置文件中(它不存在默认情况下,所以你必须将其添加)。

使用语言键记录用户活动:

	活动::日志([ 
'的contentType ' => '记录''描述' => [ ' created_items ',[ // “活动日志:: descriptions.created_items”是“:用户创建的:编号:项目”。  number ' => 2' items ' => ' SPL | labels.record '// “labels.record”在这个例子中有一个字符串“Record | Records” 			],		],' details ' => [ ' record ''这是某种记录'		],' data ' => [ ' category ' => ' Content '		],	]);category ' => ' Content '],]);category ' => ' Content '],]);		  
		 
			
				  
				   


		 
			
			

		 
			  



	echo  $ activity - > getDescription(); //可能输出“未知用户创建了2条记录”。

	echo  $ activity - > getDetails(); //可能会输出“记录:这是某种记录”

	echo  $ activity - > getData(' category '); //将输出“内容”

在上面的例子中,描述中的items替换变量在将|它们与实际语言变量分开的字符之前具有一定数量的指定属性可用属性如下:

S - Return the "singular" string (in the case of "labels.record", "Record")
P - Return the "plural" string (in the case of "labels.record", "Records")
A - Prepend the string with "a" or "an" (example: "a record" instead of just "record")
L - Convert the string to lowercase

在上面的例子中,您将看到使用单数(“S”)和复数(“P”)。当使用两者时,描述构建器将查找number替换变量来确定是否应使用单数形式或复数形式。

注:user更换变量是基于记录的用户ID自动设置。

获取链接内容

设置content_types配置数组,如下例所示:

	' item '  => [
 ' uri ' => ' view /:id ' ' subdomain ' => ' items ' ' model ' => ' App \ Models \ Item '	]		        
		  
		      

您可以使用getContentItem()根据指定的模型获取项目(假设在上述指定示例的情况下,您的内容类型设置为“项目”)。您还可以使用getUrl()获取内容项目的URL或getLinkedDescription()获取该项目的链接描述。

显示动作图标

显示基于配置设置的动作图标:

	echo  $ activity - > getIconMarkup();

您也可以使用getIcon()来创建自己的图标标记的图标类。

来自  https://github.com/Regulus343/ActivityLog
普通分类: