spatie / activitylog Goto Github PK
View Code? Open in Web Editor NEWA very simple activity logger to monitor the users of your website or application
Home Page: https://spatie.be/opensource/laravel
License: MIT License
A very simple activity logger to monitor the users of your website or application
Home Page: https://spatie.be/opensource/laravel
License: MIT License
Thank you for such a nice module. It works great. Its simple and working.
I just need to know why Activity::cleanLog(); is not working? Its showing this error
BadMethodCallException in Builder.php line 2161:
Call to undefined method Illuminate\Database\Query\Builder::cleanLog()
I am just using it normally, like below i have a controller with name LogsController and i have used use Spatie\Activitylog\Models\Activity;
in which i have just 2 functions as below:
public function index()
{
$latestActivities = Activity::with('user')->latest()->get();
return view('logs.logs')->with('logs', $latestActivities);
}
public function clearlog(){
Activity::cleanLog();
Activity::log('Logs cleared By : '.Auth::user()->name);
\Session::flash('success', 'Logs deleted successfully');
}
I have defined a route for this:
Route::get('logs/clearlog', 'LogsController@clearlog');
Route::resource('logs', 'LogsController');
I dont know where i am making mistake. Please help me get this thing straight. I am new to laravel.
Thank you!
Is there a config option to choose a different table name than the default "activity_log" for the migration? Would be great to have.
could you plz add a screenshots for the project,
or link for the demo
like pimpmylog project
As most read queries will be in the form of
select * from `activity_log` order by `created_at` desc limit 50
creating an index on the "created_at" field can speed things up
Good Day,
Every time I run php artisan migrate:refresh
I get the following exception : [Symfony\Component\Debug\Exception\FatalErrorException] Class 'CreateActivityLogTable' not found
How do I go about rectifying this error? Currently I am circumventing it by manually deleting my database and doing fresh migrations and seeds.
Regards,
Can you please add possibility to change primary key from user_id to any other in config?
How to log extra column in activity log table, for example model name.
Hi, Nice work, everything works perfectly.
One suggestion.
Instead of creating an entry on every event and ramping up the database calls why not store all the events in an array and running a batch insert at the end of the request with the __destruct method?
On normal request this isn't an issue but if looping through data and creating entries the query count is 2x.
Something like this might work?
I am using the package oauth2-server-laravel for authenticating users. I was wondering if you could help point me in the right direction to modify this package to get the user ID when using this solution.
It appears that I need to replace the bit of code in ActivitylogSupervisor.php __contruct method that deals with the Illuminate Auth\Guard contract but I am unsure of what those changes might be at this time. Any help at all would be greatly appreciated as this package provides all I need withholding this one critical piece.
log() expects parameter 1 to be float, string given?
Hi,
this is a Feature request.
I think it's useful to have a command to clear the database table, basically doing what Activity::cleanLog();
already does. This would be useful to clear the database table in develeopment environments or scripts.
I'm not used to package creation, so it might take some time to step through that and submit a PR.
Feel free to close this issue if you don't support that idea.
Anyone found a good way to fire an event on a many to many relationship attach/detach/sync?
Hi,
I'm trying to use this package with Laravel 5.1 and I'm getting the error that's on the title.
I've followed all the installation steps successfully but when I try to call the simple example that's on manual logging I'm getting this error.
BadMethodCallException thrown with message "Call to undefined method Illuminate\Database\Query\Builder::log()"
Stacktrace:
#68 BadMethodCallException in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2099
#67 Illuminate\Database\Query\Builder:__call in [internal]:0
#66 Illuminate\Database\Query\Builder:log in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:949
#65 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:949
#64 Illuminate\Database\Eloquent\Builder:__call in [internal]:0
#63 Illuminate\Database\Eloquent\Builder:log in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3499
#62 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3499
#61 Illuminate\Database\Eloquent\Model:__call in [internal]:0
#60 Spatie\Activitylog\Models\Activity:log in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3513
#59 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3513
#58 Illuminate\Database\Eloquent\Model:__callStatic in /var/www/html/eo-wallet/app/Http/Models/v1/Bet365/Balance.php:52
#57 Spatie\Activitylog\Models\Activity:log in /var/www/html/eo-wallet/app/Http/Models/v1/Bet365/Balance.php:52
#56 App\Http\Models\v1\Bet365\Balance:getBalance in /var/www/html/eo-wallet/app/Http/Models/v1/Wallet.php:48
#55 App\Http\Models\v1\Wallet:getBalance in /var/www/html/eo-wallet/app/Http/Controllers/v1/BalanceController.php:92
#54 App\Http\Controllers\v1\BalanceController:getBalance in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:256
#53 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:256
#52 Illuminate\Routing\Controller:callAction in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:164
#51 Illuminate\Routing\ControllerDispatcher:call in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:112
#50 Illuminate\Routing\ControllerDispatcher:Illuminate\Routing{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:139
#49 call_user_func in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:139
#48 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#47 call_user_func in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#46 Illuminate\Pipeline\Pipeline:then in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:114
#45 Illuminate\Routing\ControllerDispatcher:callWithinStack in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:69
#44 Illuminate\Routing\ControllerDispatcher:dispatch in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Route.php:203
#43 Illuminate\Routing\Route:runWithCustomDispatcher in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Route.php:134
#42 Illuminate\Routing\Route:run in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Router.php:708
#41 Illuminate\Routing\Router:Illuminate\Routing{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:139
#40 call_user_func in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:139
#39 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/app/Http/Middleware/v1/WalletUserAuth.php:67
#38 App\Http\Middleware\v1\WalletUserAuth:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#37 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#36 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/app/Http/Middleware/v1/GetBalanceParametersValidator.php:56
#35 App\Http\Middleware\v1\GetBalanceParametersValidator:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#34 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#33 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#32 call_user_func in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#31 Illuminate\Pipeline\Pipeline:then in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Router.php:710
#30 Illuminate\Routing\Router:runRouteWithinStack in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Router.php:675
#29 Illuminate\Routing\Router:dispatchToRoute in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Routing/Router.php:635
#28 Illuminate\Routing\Router:dispatch in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:236
#27 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:139
#26 call_user_func in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:139
#25 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php:49
#24 Barryvdh\Debugbar\Middleware\Debugbar:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#23 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#22 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:50
#21 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#20 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#19 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#18 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#17 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:62
#15 Illuminate\Session\Middleware\StartSession:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#14 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#12 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#11 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
#9 Illuminate\Cookie\Middleware\EncryptCookies:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#8 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:44
#6 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#5 call_user_func_array in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#3 call_user_func in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#2 Illuminate\Pipeline\Pipeline:then in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:122
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /var/www/html/eo-wallet/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:87
#0 Illuminate\Foundation\Http\Kernel:handle in /var/www/html/eo-wallet/public/index.php:54
Do you have any clues on how to make this work?
Thanks.
Hey, great package if it works.
Currently i am getting the above error.
I use the log in my controller after the save method
use Spatie\Activitylog\Models\Activity;
$report->save();
Activity::log('Report was saved);
return Redirect::route('reports.index')->withSuccess(
'Report erfolgreich angelegt.'
);
EDIT: I have to use
use Activity;
We have a multi-tenancy setup with multiple databases for each tenant and a main shared one. I would like to be able to do simple logging on a tenant database connection (not the main).
I read your comment here: #42 but that will only work for model event logging.
I would like to do a simple activity()->log('Look mum, I logged something');
that would go to a tenant database. Is there any clean way of setting the connection?
I would like to log the activity of events that happen on a model just like your example. Since the create, update, delete functions are being called by an API there is no logged in user. I'm getting this error when making my API call.
exception 'ErrorException' with message 'Argument 1 passed to BFCampaigns\SourceCode::Spatie\Activitylog\{closure}() must implement interface Spatie\Activitylog\logsActivityInterface, instance of BFCampaigns\SourceCode given' in /app/vendor/spatie/activitylog/src/Spatie/Activitylog/LogsActivity.php:10
Is there a way to assign events without a logged in user to some default system user account?
Hi,
The path to Guard changed in Laravel 5.2 from Illuminate\Auth\Guard;
to Illuminate\Contracts\Auth\Guard;
. This will need to be updated in ActivitylogSupervisor.php
Thanks,
Xavier
hello
i have used the "casuer" function to get information from the model that causes the activity log, but for some reason the "subject" function doesn't work for me
当使用insert,update 进行数据操作的时候,不能在数据库查看到日志,只有在save操作的时候,才能在数据库看到日志。如何才能使用 insert update 时,也能在数据库查看到日志
Hi,
Just have to say that this is a great package. I would however live to log activities to another database rather. Is there a way I can achieve this?
Thanks
Hello,
I try to add Log Model Events. It's working fine with my models but when i try to implement it to my App\User model i have this error
PHP Fatal error: Trait method bootLogsActivity has not been applied, because there are collisions with other trait methods on App\User in laravel/app/User.php on line 80
I use at top this way
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Spatie\Permission\Traits\HasRoles;
use Spatie\Activitylog\LogsActivityInterface;
use Spatie\Activitylog\LogsActivity;
class User extends Model implements
AuthenticatableContract,
AuthorizableContract,
LogsActivityInterface,
CanResetPasswordContract
{
// LOGS
use LogsActivity;
Thanks.
I'm trying to implement logging on a model of mine. Namely, when a value is updated, I'd like to log what the previous value was, and what the new value is. Is there a straightforward way to do this using ActivityLog?
Is it possible that when using the trait LogsActivity in your model, and implementing the corresponding interface, the model isn't yet subscribed to the model events?
I've seen a past post with the same title, but the answer there didn't help me, probably cause im very new to laravel...
-> #21
So this package works great for logging standard messages like 'Model created', 'Model updated', and so on, but how can I log the previous values of the changes?
Example, model 'Product' price changes from 150 to 160, or Product title changes..
I tried a couple of things, working with events/handlers, creating a new trait, but nothing worked so far for me...
Btw im using laravel 5.0
Can anyone assist me with this please?
Thanks in advance!
What is the best way to change the User Facade to Sentinel ?
Should i create a __construct somewhere and override this function ?
Or how should i change it ?
Because if i want to pass the user_id i get a
FatalErrorException in ActivitylogSupervisor.php line 45:
Class 'User' not found
$user = Sentinel::getUser();
Activity::log('Report ' . $report->id . ' wurde erstellt von', $user->id);
Hello, Freek.
Because in ServiceProvider there is no checks if migration was already published before it's duplucating after each vendor:publish
command.
Hi,
I use Log model events, so I've implemented the interface in my User model and add the trait, but the bootLogsActivity
method is never called. So I've tried the code below in my model:
protected static function boot()
{
self::bootLogsActivity();
}
public function getActivityDescriptionForEvent($eventName)
{
dd($eventName);
if($eventName == 'updated')
{
return trans('activity.user.updated', ['name' => $this->profile->present()->fullName]);
}
return '';
}
The die and dump is never called. What's wrong in my case ?
Hello, Thanks for the wonderful script. Just one doubt. How can we add more fields like content_type & id so that we can fetch records based on content_type. Thanks in advance.
Is it possible to configure the plugin so that logs never get deleted? Is there a config for that?
Whenever I use php artisan vendor:publish
it creates a new migration, even if an existing already exists. Did I do something wrong or a bug?
Only happens for this package
in controller
use Spatie\Activitylog\Models\Activity;
$latestActivities = Activity::with('user')->latest()->limit(100)->get(); // this code works
but i can not use this code :
Activity::log("You have updated your basic user information");
error :
Call to undefined method Illuminate\Database\Query\Builder::log()
when i use Activity;
error is . class activity not found or is used
i changed use Spatie\Activitylog\Models\Activity as activitymodel
not solved my problem
Hi, thanks for this grate package.
my question is how can i retrieve activity logs for the currently logged in user only.
should i just create a new model and repository for the table activity_log and work the old way or is there a way in your package to get logs of Auth::user().
And also related question for removing all logs from the database because this
Activity::cleanLog();
is not removing them should i go with my own repository solution ?
Thanks!
Hello,
I am able to store the activity log without any issue. But when i am trying to fetch it by following lines
$latestActivities = Activity::with('user')->latest()->limit(100)->get();
I am getting issue as below:
Call to undefined method Spatie\Activitylog\ActivitylogSupervisor::with()
Can you please help??
This package is perfect for logging actions with simple messages "Jack updated Post id:123.", but when it comes to logging complex actions with deep details I believe having the field as text/json
and allow logging actions in a json format would make it more flexible.
Activity::log([
'action' => 'update',
'updates' => [
['name' => ['old name', 'new name'],
['price' => [36, 78]]
]
]);
This will allow logging actions in more detail, and also can be handy when logging messages in a multilingual application.
I noticed when there is a Mass Update nothing is logged.
is it possible to log, other user user information like location, platforms and browser details of the active user
Dear all,
I have imported ActivityLog V1 into my project.
All was fine until I put the first line in the manual in my Controller.
activity()->log('Look mum, I logged something');
Unfortunately this shows the following error :
(1/1) FatalThrowableError
Type error: Argument 1 passed to Spatie\Activitylog\ActivityLogger::useLog() must be of the type string, null given, called in /var/www/public/plevoets/vendor/spatie/laravel-activitylog/src/helpers.php on line 11
Am I forgetting anything ?
Best regards,
Davy
I use Activity::cleanLog(); to clean up the database table, return true but not delete the logs of table.
/**
* [destroy description]
* @return [type] [description]
*/
public function destroy()
{
if (Activity::cleanLog()):
flash()->success('Logs excluídos com sucesso.');
else:
// Exibe a mensagem de sucesso
flash()->warning('Um erro ocorreu ao excluir os logs, tente novamente.');
endif;
// Redireciona para listagem de logs
return redirect()->route('painel.logs.index');
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.