[owncloud-devel] Log authenticated user

Josef Meile jmeile at hotmail.com
Thu Sep 17 09:25:56 GMT 2015


I solved this problem as follows:

I have an app, so, I added the header on "myapp/appinfo/app.php":
$headerValue = 'Anonymous';
if (\OC_User::isLoggedIn()) {
    $headerValue = \OC_User::getUser();
header('X-OCUser: ' . $headerValue);

Then in my apache config file, I added (Everything must be on the same
LogFormat "%h - %{X-OCUser}o %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\"" ownCloud

Finally, on the VirtualHost I put:
CustomLog ${APACHE_LOG_DIR}/owncloud_access.log owncloud

That's it, now I get: - user_login [17/Sep/2015:11:11:33 +0200] "GET
/owncloud/index.php/..." 200 192 "http://localhost/owncloud/index.php/..."
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"

This could be added to the "lib/base.php" file at the beginning of the
handleRequest function. I will propose this as a feature. I think It would
be nice to see the logged user in the apache access log.

Please also note that if you don't defined ownCloud as a virtual host, this
means that you have the default installation and it is configured as a
directory: http://yourdomain/owncloud, then you will have to define the
custom log differently; I tried several options, but the only thing that
worked for me was to define the apache access log for the default
virtualhost as follows:
CustomLog ${APACHE_LOG_DIR}/ access.log ownCloud

Nothing else worked for me. Anyway, in my production server, ownCloud is
installed on a VirtualHost, so, this isn't really a problem for me.

Best regards

From: Josef Meile [mailto:jmeile at hotmail.com] 
Sent: Mittwoch, 16. September 2015 16:14
To: devel at owncloud.org
Subject: Log authenticated user


In the apache logs I always see things like:
xxx.xxx.xxx.xxx - - [16/Sep/2015:15:13:05 +0200] "POST /index.php/heartbeat
HTTP/1.1" 200 -

If you see, just after the IP, it comes two dashes with an space in between:
"- -".

I have seen this in other applications and I could solved it by setting an
http header, I defined this custom log type:
LogFormat "%h - %{X-OCUser}o %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\"" ownCloud

Then you can use it for your apache logs as follows:
CustomLog logs/access_log ownCloud

I think the best would be before rendering an ownCloud and just after the
user gets authenticated. Something like this should be added:
$request->setHeader('X-OCUser', currentUser);

Where can I set this?

Best regards

More information about the Devel mailing list