Skip to content

Commit

Permalink
logging client info
Browse files Browse the repository at this point in the history
  • Loading branch information
klgd committed May 2, 2017
1 parent d1f27a9 commit 3f2c580
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"dev-master": "1.0-dev"
}
},
"suggest": {
"jenssegers/agent": "Required to use logging client info (~2.5)."
},
"config": {
"sort-packages": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function up()
$table->string('client_ip', 20)
->comment('操作者IP');

$table->string('client')
->comment('客户端信息');

$table->timestamps();

$table->index('user_id');
Expand Down
15 changes: 15 additions & 0 deletions src/Events/AbstractEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public function __construct(Model $model)
'client_ip' => request()->getClientIp(),
'type' => $this->type,
]);

if (class_exists('\Jenssegers\Agent\Agent')) {
$agent = new \Jenssegers\Agent\Agent();

$device = $agent->device();
$platform = $agent->platform();
$browser = $agent->browser();

$this->setAttribute('client', [
'device' => $device . ' ' . $agent->version($device),
'platform' => $platform . ' ' . $agent->version($platform),
'$browser' => $browser . ' ' . $agent->version($browser),
]);
}

}

public function getContent()
Expand Down
1 change: 1 addition & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function event(AbstractEvent $event)
$log->table_name = $event->getAttribute('model.table', '');
$log->content = json_encode($event->getContent());
$log->client_ip = $event->getAttribute('client_ip', '');
$log->client = json_encode($event->getAttribute('client', []));

$log->save();

Expand Down
1 change: 1 addition & 0 deletions src/Models/ActionLogModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @property string $type 操作类型
* @property string $table_name 相关的数据表
* @property string $content 操作描述
* @property string $client 客户端信息
* @property string $client_ip 操作者IP
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
Expand Down

0 comments on commit 3f2c580

Please sign in to comment.