Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created an additional logger that logs to the systemd journal #9760

Closed
wants to merge 4 commits into from

Conversation

jernst
Copy link
Contributor

@jernst jernst commented Jun 6, 2018

Usage: in config.php:

'log_type' => 'systemd'

and all messages sent to the logger will go to the journal, mapped similarly to the syslog logger. This requires the php-systemd extension from here: https://github.com/systemd/php-systemd.

Advantage: a single place where to look what might be wrong with a running system.

@jernst
Copy link
Contributor Author

jernst commented Jun 6, 2018

These failing tests seem unrelated to anything I did ...

@go2sh
Copy link
Contributor

go2sh commented Jun 6, 2018

You need to sign of your commits. ;-) See CONTRIBUTING.md

Added a unit test

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
@codecov
Copy link

codecov bot commented Jun 6, 2018

Codecov Report

Merging #9760 into master will decrease coverage by <.01%.
The diff coverage is 18.75%.

@@             Coverage Diff              @@
##             master    #9760      +/-   ##
============================================
- Coverage     51.92%   51.91%   -0.01%     
- Complexity    25808    25812       +4     
============================================
  Files          1637     1638       +1     
  Lines         95513    95526      +13     
  Branches       1318     1318              
============================================
+ Hits          49593    49595       +2     
- Misses        45920    45931      +11
Impacted Files Coverage Δ Complexity Δ
config/config.sample.php 0% <ø> (ø) 0 <0> (ø) ⬇️
lib/private/Log/Systemdlog.php 0% <0%> (ø) 3 <3> (?)
lib/private/Log/Syslog.php 0% <0%> (ø) 3 <0> (ø) ⬇️
lib/private/Log/LogFactory.php 100% <100%> (ø) 12 <0> (+1) ⬆️
core/Command/Log/Manage.php 78.02% <50%> (ø) 28 <0> (ø) ⬇️

@jernst
Copy link
Contributor Author

jernst commented Jun 6, 2018

@go2sh Done.

@go2sh
Copy link
Contributor

go2sh commented Jun 7, 2018

BTW. I like this a lot. :-)

The other build failure is related to the absence of php-systemd in the ci images triggering an undefined function error. Regarding the dependency, someone from the core team should have a look. @MorrisJobke

@blizzz
Copy link
Member

blizzz commented Jun 11, 2018

Works nicely! For NC 14 it should work with PHP 7.0, however it seems not to be the case yet: systemd/php-systemd#5

Otherwise, do you know about (Debian) packages for CI?

P.S.: There's actually a PR to get 7.0 running, but it is without reaction since mid 2016: systemd/php-systemd#6, latest commit from 2014. It seems dead, eh? :(

@jernst
Copy link
Contributor Author

jernst commented Jun 11, 2018

I developed this against PHP 7.2 on Arch / UBOS using this patch: systemd/php-systemd#6 (I guess I should have mentioned that earlier).

Here is how I build the package: https://github.com/uboslinux/ubos-php/tree/master/php-systemd which comes from Arch AUR here: https://aur.archlinux.org/packages/php-systemd/

Sorry, I'm not current on how to build packages for debian, it's been a few years ...

@jernst
Copy link
Contributor Author

jernst commented Jun 11, 2018

That php-systemd patch just got merged: systemd/php-systemd#6

public function write(string $app, $message, int $level) {
$journal_level = $this->levels[$level];
sd_journal_send('PRIORITY='.$journal_level,
'SYSLOG_IDENTIFIER=nextcloud',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of hardcoding nextcloud, it might be better to get the name from ThemingDefaults::getName() or have it configurable as syslog does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I was thinking about that, but then stopped myself from overcomplicating matters :-). If this turns out to be a problem in practice, we can simply extend it in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we can reuse the syslog_tag config option, as it cannot be used in parallel anyway. Extra effort would only to rename it to something more generic, it requires a repair step though. Since you require IConfig in the constructor, but don't use it, it should either go, or just read the setting and store it in a class member. Then you need to just pass it as SYSLOG_IDENTIFIER. Does not really make things more complicated.

Another thing is that we should check whether sd_journal_send is available, to react decently if the module is not loaded. I'd check it in the constructor, too, and throw a HintException if it is not available.

@blizzz
Copy link
Member

blizzz commented Jun 12, 2018

I believe i taught the Debian 8 that we use in the test case to compile that module. I'll give a final and push tomorrow.

*
* @author Johannes Ernst <jernst@indiecomputing.com>
*
* @license AGPL-3.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if this is licensed under GNU AGPL version 3 or any later version - cc @schiessle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@blizzz
Copy link
Member

blizzz commented Jun 13, 2018

@jernst I added php-systemd to the corresponding CI container. To have effect, please apply this patch for CI to work:

diff --git a/.drone.yml b/.drone.yml
index 26a72c9b43..cf9b262abb 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -53,7 +53,7 @@ pipeline:
       matrix:
         TESTS: syntax-php7.1
   phan:
-    image: nextcloudci/php7.2:php7.2-11
+    image: nextcloudci/php7.2:php7.2-12
     commands:
       - composer install
       - composer require --dev "phan/phan:0.11.1"
@@ -170,7 +170,7 @@ pipeline:
         DB: NODB
         PHP: 7.1
   nodb-php7.2:
-    image: nextcloudci/php7.2:php7.2-11
+    image: nextcloudci/php7.2:php7.2-12
     commands:
       - NOCOVERAGE=true TEST_SELECTION=NODB ./autotest.sh sqlite
     when:
@@ -194,7 +194,7 @@ pipeline:
         DB: sqlite
         PHP: 7.1
   sqlite-php7.2:
-    image: nextcloudci/php7.2:php7.2-11
+    image: nextcloudci/php7.2:php7.2-12
     commands:
       - NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh sqlite
     when:
@@ -218,7 +218,7 @@ pipeline:
         DB: mysql
         PHP: 7.1
   mysql-php7.2:
-    image: nextcloudci/php7.2:php7.2-11
+    image: nextcloudci/php7.2:php7.2-12
     commands:
       - NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh mysql
     when:
@@ -292,7 +292,7 @@ pipeline:
         DB: mysqlmb4
         PHP: 7.1
   mysqlmb4-php7.2:
-    image: nextcloudci/php7.2:php7.2-11
+    image: nextcloudci/php7.2:php7.2-12
     commands:
       - NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh mysqlmb4
     when:

@jernst and may I ask for another favor? in config/sample.config.php update the comment about 'log_type' => 'file' to reflect the other options and also state that the php-systemd module is needed for the systemd type. Also update the doc about 'syslog_tag' if going for it as suggested ^

jernst added a commit to jernst/nextcloud-server that referenced this pull request Jun 13, 2018
@jernst
Copy link
Contributor Author

jernst commented Jun 13, 2018

Hang on, this was done in a hurry, will fix when I have more time.

@MorrisJobke MorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jun 13, 2018
@@ -39,7 +39,7 @@ class Syslog implements IWriter {
];

public function __construct(IConfig $config) {
openlog($config->getSystemValue('syslog_tag', 'ownCloud'), LOG_PID | LOG_CONS, LOG_USER);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be mentioned in #7827 after merge.

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
jernst added a commit to jernst/nextcloud-server that referenced this pull request Jun 18, 2018
Changed name of default system (not systemd) logger from ownCloud to Nextcloud, to be consistent
Fixed license per nextcloud#9760 (comment)
Pulled upstream updates
Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
jernst added a commit to jernst/nextcloud-server that referenced this pull request Jun 18, 2018
Changed name of default system (not systemd) logger from ownCloud to Nextcloud, to be consistent
Fixed license per nextcloud#9760 (comment)
Pulled upstream updates

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
Changed name of default system (not systemd) logger from ownCloud to Nextcloud, to be consistent
Fixed license per nextcloud#9760 (comment)
Pulled upstream updates

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
@jernst
Copy link
Contributor Author

jernst commented Jun 18, 2018

This should be better. Manually tested to 1) actually log to the journal, 2) syslog_tag works with journal, 3) HintException is thrown if the PHP systemd module is not active. Also signed commit, and call the extension system not php-system (that's the name of the package) in the comments, as the php.ini file needs extension=systemd.so.

@blizzz
Copy link
Member

blizzz commented Jun 18, 2018

@jernst This looks good! could you commit the patch in #9760 (comment) to make the tests pass?

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
@jernst
Copy link
Contributor Author

jernst commented Jun 28, 2018

This integration test failure seems unrelated to this PR?

@blizzz
Copy link
Member

blizzz commented Jun 28, 2018

It is nothing that i have seen failing before. Locally I also get different results. I restart the tests, if it reoccurs, could you rebase? if it still reoccurs, it could be related… though it appears strange.

@blizzz
Copy link
Member

blizzz commented Jun 28, 2018

@jernst So, locally I have RedisTest succeeding. Perhaps there was a glitch inbetween. Could you rebase to current master and force-push?

blizzz pushed a commit that referenced this pull request Jun 29, 2018
Changed name of default system (not systemd) logger from ownCloud to Nextcloud, to be consistent
Fixed license per #9760 (comment)
Pulled upstream updates

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
blizzz pushed a commit that referenced this pull request Jun 29, 2018
Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
@blizzz blizzz mentioned this pull request Jun 29, 2018
@blizzz
Copy link
Member

blizzz commented Jun 29, 2018

I put #10048 in place as today is feature freeze. If that runs through, we may merge it today.

@blizzz
Copy link
Member

blizzz commented Jun 29, 2018

→ continue in #10048

@blizzz blizzz closed this Jun 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants