Using Hooks in my Application

Dear all,

in my application I am trying to use hooks to listen to events happening in the NC platform, like uploading/renaming/deleting files etc. I am following the instructions of the manual:

however that seems to break the hole installation after activating the application. The source of the disaster seems to be these two lines:

$app = new Application();

I know that the manuals might be currently outdated and I have a blurry impression that registering services in the container might also be a depreciated method. However I am not sure how I can use hooks in my application. Could anybody shine light into this matter?

Thank you very much in advance!

You can check the source from the apps Activity.


May I ask what you are actually trying to achieve?

@NoMoreGlitchies - If you want to look at a simple app which uses hook, look at:

The register method is really simple

	public function register() {
		$reference = $this;
		$callback = function (Node $node) use($reference) {
		$this->root->listen('\OC\Files', 'postCreate', $callback);

Thank you guys. Looking at the examples makes it easy, especially the simpler one.
What I want to do is monitor user activity (from all the users) and export it to a log file in a specific format, so that I can parse it directly with a simple script. I know that the NextCloud log contains everything possible but making a simple custom app is the target!

You know there is this app called “admin_audit” which does exactly that?
It’s shipped in the default package.

Hi Nick, I am aware of the tool in the admin panel under the name Log, but is it what you refer to?

The admin_audit app writes to the default log, yes.
But you can also manually read the log file, filter entries for app === 'admin_audit' and user === 'target' then you don’t need to write all the code yourself.

1 Like

is it possible to have a look at the admin audit log entries in the instant Demo ?