Problem/Motivation
There is no test coverage for syslog functionality. #1748410: Include !severity in logged events by syslog made it evident.
Ideally we would like to test what syslog() function is actually saving in the /var/log/syslog.log file. To make sure that for a given entry we get things replaced correctly:
From this:
!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message
To this:
http://example.com|1493504803|page not found|127.0.0.1|http://example.com/admin/config/development/ logging0|1||/this-page-does-not-exists
Proposed resolution
Alternative 1:
- Move the call to
syslog()
to a method of SysLog logger - Create a test module that provide its own Logger that extends SysLog and override the syslog method.
- Create a testcase that installs the custom test module and makes the assertions.
Alternative 2:
- Find a way to change the output of syslog to a file that drupal can read and inspect.
- Create a testcase that installs the custom test module and makes the assertions.
Remaining tasks
Decide on which solution is the best.
Code it.
Review the patch.
User interface changes
None
API changes
New method for the SysLog logger.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#20 | interdiff-2874069-16-20.txt | 1.25 KB | dagmar |
#20 | 2874069-20.patch | 4.35 KB | dagmar |
#16 | interdiff-2874069-15-16.txt | 712 bytes | dagmar |
#16 | 2874069-16.patch | 4.37 KB | dagmar |
#15 | 2874069-15.patch | 4.35 KB | dagmar |
Comments
Comment #2
benjifisher@dagmar, can you give a little more detail in the issue summary?
core/modules/syslog
)?syslog()
that you want to move?Searching the syslog module for "syslog(", the only place I find it is in the
log()
method ofDrupal\syslog\Logger\SysLog
. Probably I am misreading this issue, because it looks as though the code is already where you want it. I am not sure what you have in mind for this issue.Comment #3
dagmar@benjifisher, thanks for your questions.
Yes
Here: http://cgit.drupalcode.org/drupal/tree/core/modules/syslog/src/Logger/Sy...
However, I'm not sure if this is the best way to make this testable. Maybe we can find a way to change the path of the syslog file and just read it from the filesystem.
I would like to test what syslog() function is actually saving in the /var/log/syslog.log file. To make sure that for a given entry we get things replaced correctly:
From this:
!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message
To this:
http://example.com|1493504803|page not found|127.0.0.1|http://example.com/admin/config/development/ logging0|1||/this-page-does-not-exists
Comment #4
dagmarComment #5
dagmarAfter read the syslog documentation I came to the conclusion this cannot be done. The syslog path cannot be changed from php and the replace the syslog() call with a new implementation basically means having something like this: https://www.phpclasses.org/package/2787-PHP-Log-data-to-a-RFC-3164-compl...
We should encourage manual testing for tickets like: #1748410: Include !severity in logged events by syslog.
Comment #6
dagmarActually, we still can use the first approach. Here is the patch.
Comment #8
dagmarWeird, this pass in my local env. Let's try with this.
Comment #9
dagmarI had a conversation with one of the leaders of the PHP initiative. This confirms alternative 1 is not valid and the only path we have for this ticket is something like the alternative 2.
Comment #10
dawehnerIs there a reason this is a functional test. Maybe i'm a bit stubborn, but couldn't this be a kernel test here?
Comment #11
dagmarI made this a functional tests to avoid the need to fake a http request.
Comment #12
dawehnerWhy do we do a HTTP request instead of just calling to the logging API?
Comment #13
dagmarBecause we need a full log in order to test all the placeholders.
!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message
Comment #14
dawehnerMhhh, I mean you could create a request and push it onto the request stack, but I see what you mean. Do you maybe want to document that on the test?
Comment #15
dagmarActually making this a Kernel Test give us much more control about the request, thanks @dawehner.
Comment #16
dagmarRemoved the hardcoded 127.0.0.1
Comment #17
dawehnerI don't think we should "access" the current client IP, given its always artificial in the context of kernel tests ...
Comment #18
dagmarI just trying to match a placeholder with a value that makes sense. Do you think a should skip this assertion?
Comment #19
dawehnerCan't you control everything when you create a request manually?
Comment #20
dagmarOh I see what you mean. What about this?
Comment #21
dawehner+1 for that
Comment #22
catchCommitted 3958a93 and pushed to 8.4.x. Thanks!\