PHPackages                             aliirfaan/laravel-simple-access-log - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. aliirfaan/laravel-simple-access-log

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

aliirfaan/laravel-simple-access-log
===================================

This package creates a database table to save access logs and exposes events to log user access.

5.0.0(1y ago)035MITPHP

Since Jan 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aliirfaan/laravel-simple-access-log)[ Packagist](https://packagist.org/packages/aliirfaan/laravel-simple-access-log)[ RSS](/packages/aliirfaan-laravel-simple-access-log/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)DependenciesVersions (11)Used By (0)

Laravel Simple Access Log
=========================

[](#laravel-simple-access-log)

Many systems need to log user access for auditing purposes. This package creates a database table with sensible fields for logging access.

Features
--------

[](#features)

- Table structure to keep access logs
- Events for common access operations like login success, login failure, logout
- Configurable connection if using a different database for recording logs
- Use custom model

Table fields
------------

[](#table-fields)

Migration schema to explain available fields.

```
Schema::connection(config('simple-access-log.access_log_db_connection'))->create('lsac_access_logs', function (Blueprint $table) {
    $table->id();
    $table->dateTime('ac_date_time', $precision = 0)->index('ac_date_time_index');
    $table->string('ac_actor_id')->nullable()->index('ac_actor_id_index')->comment('User id in application. Can be null in cases where an action is performed programmatically.');
    $table->string('ac_actor_type', 255)->nullable()->index('ac_actor_type_index')->comment('Actor type in application. Useful if you are logging multiple types of users. Example: admin, user, guest');
    $table->string('ac_actor_globac_uid')->nullable()->index('ac_actor_globac_uid_index')->comment('User id if using a single sign on facility.');
    $table->string('ac_actor_username', 255)->nullable()->index('ac_actor_username_index')->comment('Username in application.');
    $table->string('ac_actor_group', 255)->nullable()->index('ac_actor_group_index')->comment('User role/group in application.');
    $table->string('ac_device_id', 255)->nullable()->index('ac_device_id_index')->comment('Device identifier.');
    $table->string('ac_event_name', 255)->nullable()->index('ac_event_name_index')->comment('Common name for the event that can be used to filter down to similar events. Example: user.login.success, user.login.failure, user.logout');
    $table->ipAddress('ac_ip_addr')->nullable()->index('ac_ip_addr_index');
    $table->string('ac_server', 255)->nullable()->index('ac_server_index')->comment('Server ids or names, server location. Example: uat, production, testing, 192.168.2.10');
    $table->string('ac_version', 255)->nullable()->index('ac_version_index')->comment('Version of the code/release that is sending the events.');
    $table->timestamps();
 });
```

Events
------

[](#events)

You can dispatch these events to record logs. You can also listen to these events if you want additional processing.

- LoginSucceeded
- LoginFailed
- LoggedOut

Requirements
------------

[](#requirements)

- [Composer](https://getcomposer.org/)
- [Laravel](http://laravel.com/)
- [MySQL 4.x +](https://www.mysql.com/) VARBINARY data type is available as from 4.x

Installation
------------

[](#installation)

You can install this package on an existing Laravel project with using composer:

```
 $ composer require aliirfaan/laravel-simple-access-log
```

Register the ServiceProvider by editing **config/app.php** file and adding to providers array:

```
  aliirfaan\LaravelSimpleAccessLog\SimpleAccessLogProvider::class,
```

Note: use the following for Laravel &lt;5.1 versions:

```
 'aliirfaan\LaravelSimpleAccessLog\SimpleAccessLogProvider',
```

Publish files with:

```
 $ php artisan vendor:publish --provider="aliirfaan\LaravelSimpleAccessLog\SimpleAccessLogProvider"
```

or by using only `php artisan vendor:publish` and select the `aliirfaan\LaravelSimpleAccessLog\SimpleAccessLogProvider` from the outputted list.

Apply the migrations:

```
 $ php artisan migrate
```

Configuration
-------------

[](#configuration)

This package publishes an `simple-access-log.php` file inside your applications's `config` folder which contains the settings for this package. Most of the variables are bound to environment variables, but you are free to directly edit this file, or add the configuration keys to the `.env` file.

access\_log\_db\_connection | String
The database connection to use. Defaults to environment variable 'DB\_CONNECTION'.

```
'access_log_db_connection' => env('ACCESS_LOG_DB_CONNECTION', env('DB_CONNECTION'))
```

access\_log\_model | String The model you want to use. The model must implement aliirfaan\\LaravelSimpleAccessLog\\Contracts\\SimpleAccessLog

```
'access_log_model' => aliirfaan\LaravelSimpleAccessLog\Models\SimpleAccessLog::class,
```

should\_prune | Boolean Whether to prune records

```
'should_prune' => env('ACCESS_LOG_SHOULD_PRUNE', false),
```

prune\_days | Numeric to delete records older than prune\_days

```
'prune_days' => env('ACCESS_LOG_PRUNE_DAYS', 30),
```

Usage
-----

[](#usage)

```
