プロジェクト

全般

プロフィール

Vote #70748

未完了

easy logging of usernames in apache access logs via custom response header

Admin Redmine さんがほぼ4年前に追加. ほぼ4年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Administration_8
対象バージョン:
-
開始日:
2011/09/20
期日:
進捗率:

100%

予定工数:
category_id:
8
version_id:
0
issue_org_id:
9281
author_id:
39649
assigned_to_id:
0
comments:
5
status_id:
1
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

journals

Can you provide an information how to configure Apache web sever to see this information in the access log? I've added this line in my httpd.conf:
<pre>LogFormat "%h %l %u %t \"%r\" %>s %b" common</pre>
but there is just '-' instead of a user name in the log file:

<pre>192.168.xxx.xxx - - [26/Sep/2011:13:35:14 +0200] "GET /javascripts/application.js?1310384844 HTTP/1.1" 304 229 "https://xxxx/projects/xxxx" "Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"</pre>

From my point of view there should be :
<pre><code class="ruby">response.headers["X-Username"] = User.current.login</code></pre>
instead of:
<pre><code class="ruby">response.headers["X-Username"] = User.current.name(:username)</code></pre>
because the login is unique, not the user name.
--------------------------------------------------------------------------------
> Can you provide an information how to configure Apache web sever to see this information in the access log?

Rather than "%s" you should use "%{X-Username}o".

For example, I've created an "alternate" logging scheme in my httpd.conf:

<pre>
LogFormat "%{%F %Tz}t %h %{X-Username}o \"%r\" %>s %O %D" alternate
</pre>

...and then in the redmine-specific config:
<pre>
CustomLog /var/log/apache2/access_redmine.log alternate
</pre>

...which yields log lines like this:
<pre>
2011-09-26 14:03:50z xxx.xxx.xxx.xxx rhailey "GET /news/3 HTTP/1.1" 200 3790 313207
</pre>

> From my point of view there should be [...] instead of [...]
> because the login is unique, not the user name.

I'm not familiar with the inner workings of redmine, or ruby in general. It took me some time to come up with that patch, and at one time I had tried 'login' and it did not work (in retrospect, it was probably a different issue).

As best I can tell, the name(:username) syntax reduces to 'login', but at the cost of a function call.

--------------------------------------------------------------------------------
...typo, I meant rather than "%u"...
--------------------------------------------------------------------------------
Thanks. It works fine now. Unfortunately the user is not logged by all log records:

<pre>192.xxx.xxx.xxx - - picmank [27/Sep/2011:09:35:13 +0200] "GET /my/account HTTP/1.1" 200 6612 "https://xxx/" "Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"
192.xxx.xxx.xxx - - - [27/Sep/2011:09:35:13 +0200] "GET /javascripts/prototype.js?1310384844 HTTP/1.1" 304 229 "https://xxx/my/account" "Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"</pre>

--------------------------------------------------------------------------------

> ... the user is not logged by all log records:

True, it is unfortunate that this does not log the usernames that access static files, but it gets all the "important" log lines (GET with database access, and POST modifications).

I'm not sure logging usernames for static final access is practical (can you intercept a request for a file?).

In any event, I'm glad it's working for you.

--------------------------------------------------------------------------------

Admin Redmine さんがほぼ4年前に更新

  • カテゴリAdministration_8 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0