Hi For your information, I proposed it on the issue tracker: https://github.com/owncloud/core/issues/19134
Hopefully it gets accepted. I included it on my app and it works like a charm. Best regards Josef -----Original Message----- From: Josef Meile [mailto:[email protected]] Sent: Donnerstag, 17. September 2015 16:18 To: [email protected] Subject: RE: Log authenticated user I just updated my code in order to make it look more elegant without that ugly static stuff: public function setUserHeader() { $container = $this->getContainer(); $session = $container->query('OCP\IUserSession'); $headerValue = 'Anonymous'; if ($session->isLoggedIn()) { $headerValue = $session->getUser()->getUID(); } header('X-OCUser: ' . $headerValue); } -----Original Message----- From: Josef Meile [mailto:[email protected]] Sent: Donnerstag, 17. September 2015 11:26 To: [email protected] Subject: RE: Log authenticated user Hi 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 line): 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: 10.0.2.2 - 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 Josef From: Josef Meile [mailto:[email protected]] Sent: Mittwoch, 16. September 2015 16:14 To: [email protected] Subject: Log authenticated user Hi 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 Josef _______________________________________________ Devel mailing list [email protected] http://mailman.owncloud.org/mailman/listinfo/devel
