If you mean all the accessed routes, then you could use middleware that runs at the end and stores the logs.
module.exports = strapi => {
return {
// can also be async
initialize() {
strapi.app.use(async (ctx, next) => {
await next();
await strapi.config.functions['storeLogs'](ctx);
});
},
};
};
Where storeLogs is your custom function that accepts the ctx param and gets all the necessary data from it ( ctx.state.user - contains the information about logged in user, ctx.request.body - contains the body requests for POST/PUT etc.)
But if you mean the create/update/delete of some entities then you should use webhooks. Build an API that stores all the requests. Now you have an activity log for create/update/delete actions.
Hey guys, I’ve been thinking about the same thing. Well, not exactly the afterCreate lifecycle but about implementing a detailed activity log. I need it to constantly monitor several user’s actions and do some stuff accordingly.
So, I tried to find any information in what direction should I dig - middleware, hooks, or anything else. Admittedly, I thought middleware will be most likely the thing but here I see Sunnyson says that middleware has only limited info about the actions and it would be better to use webhooks.
I find it a bit unhandy to have another small app to collect only “log entries”. The question is if there is a better solution or Hooks + Another app is the best way to receive the information mentioned below:
What item was modified and in what collection
What was done to the item - disabled, modified fields (possibly, ideally)
ctx and various parts of it are prototypes, you won’t see them if you just console.log(ctx). To actually see/interact with them you would need to log them with console.log(ctx.request.body) ect.