Просмотр исходного кода

Fix logging environment constants (#2745)

* Fix logging environment constants

* COPY_LOG_TO_SYSLOG was only working when Syslog was used
* FRESHRSS_ENV was not properly used to set logging level

* Simplify code

Always call `openlog()` even when it is not used

* Always specify syslog properties

https://github.com/FreshRSS/FreshRSS/pull/2745#discussion_r362207445

* $username is also needed further down

* No new line in syslog
Alexandre Alapetite 6 лет назад
Родитель
Сommit
acc50df0ef
6 измененных файлов с 19 добавлено и 21 удалено
  1. 0 1
      app/Models/Entry.php
  2. 0 1
      app/actualize_script.php
  3. 13 10
      lib/Minz/Log.php
  4. 0 1
      lib/favicons.php
  5. 6 7
      lib/lib_rss.php
  6. 0 1
      p/i/index.php

+ 0 - 1
app/Models/Entry.php

@@ -322,7 +322,6 @@ class FreshRSS_Entry extends Minz_Model {
 		$feed_timeout = empty($attributes['timeout']) ? 0 : intval($attributes['timeout']);
 
 		if ($system_conf->simplepie_syslog_enabled) {
-			prepareSyslog();
 			syslog(LOG_INFO, 'FreshRSS GET ' . SimplePie_Misc::url_remove_credentials($url));
 		}
 

+ 0 - 1
app/actualize_script.php

@@ -12,7 +12,6 @@ if (defined('STDOUT')) {
 	fwrite(STDOUT, 'Starting feed actualization at ' . $begin_date->format('c') . "\n");	//Unbuffered
 }
 
-prepareSyslog();
 syslog(LOG_INFO, 'FreshRSS Start feeds actualization...');
 
 // Set the header params ($_GET) to call the FRSS application.

+ 13 - 10
lib/Minz/Log.php

@@ -20,21 +20,24 @@ class Minz_Log {
 	 * @throws Minz_PermissionDeniedException
 	 */
 	public static function record ($information, $level, $file_name = null) {
-		try {
-			$conf = Minz_Configuration::get('system');
-			$env = $conf->environment;
-		} catch (Minz_ConfigurationException $e) {
-			$env = 'production';
+		$env = getenv('FRESHRSS_ENV');
+		if ($env == '') {
+			try {
+				$conf = Minz_Configuration::get('system');
+				$env = $conf->environment;
+			} catch (Minz_ConfigurationException $e) {
+				$env = 'production';
+			}
 		}
 
 		if (! ($env === 'silent'
 		       || ($env === 'production'
 		       && ($level >= LOG_NOTICE)))) {
+			$username = Minz_Session::param('currentUser', '');
+			if ($username == '') {
+				$username = '_';
+			}
 			if ($file_name === null) {
-				$username = Minz_Session::param('currentUser', '');
-				if ($username == '') {
-					$username = '_';
-				}
 				$file_name = join_path(USERS_PATH, $username, 'log.txt');
 			}
 
@@ -60,7 +63,7 @@ class Minz_Log {
 			     . ' --- ' . $information . "\n";
 
 			if (defined('COPY_LOG_TO_SYSLOG') && COPY_LOG_TO_SYSLOG) {
-				syslog($level, '[' . $username . '] ' . $log);
+				syslog($level, '[' . $username . '] ' . trim($log));
 			}
 
 			self::ensureMaxLogSize($file_name);

+ 0 - 1
lib/favicons.php

@@ -22,7 +22,6 @@ function isImgMime($content) {
 }
 
 function downloadHttp(&$url, $curlOptions = array()) {
-	prepareSyslog();
 	syslog(LOG_INFO, 'FreshRSS Favicon GET ' . $url);
 	if (substr($url, 0, 2) === '//') {
 		$url = 'https:' . $url;

+ 6 - 7
lib/lib_rss.php

@@ -9,6 +9,12 @@ if (!function_exists('mb_strcut')) {
 	}
 }
 
+if (COPY_SYSLOG_TO_STDERR) {
+	openlog('FreshRSS', LOG_CONS | LOG_ODELAY | LOG_PID | LOG_PERROR, LOG_USER);
+} else {
+	openlog('FreshRSS', LOG_CONS | LOG_ODELAY | LOG_PID, LOG_USER);
+}
+
 /**
  * Build a directory path by concatenating a list of directory names.
  *
@@ -188,19 +194,12 @@ function html_only_entity_decode($text) {
 	return strtr($text, $htmlEntitiesOnly);
 }
 
-function prepareSyslog() {
-	return COPY_SYSLOG_TO_STDERR ? openlog("FreshRSS", LOG_PERROR | LOG_PID, LOG_USER) : false;
-}
-
 function customSimplePie($attributes = array()) {
 	$system_conf = Minz_Configuration::get('system');
 	$limits = $system_conf->limits;
 	$simplePie = new SimplePie();
 	$simplePie->set_useragent(FRESHRSS_USERAGENT);
 	$simplePie->set_syslog($system_conf->simplepie_syslog_enabled);
-	if ($system_conf->simplepie_syslog_enabled) {
-		prepareSyslog();
-	}
 	$simplePie->set_cache_location(CACHE_PATH);
 	$simplePie->set_cache_duration($limits['cache_duration']);
 

+ 0 - 1
p/i/index.php

@@ -50,7 +50,6 @@ if (file_exists(DATA_PATH . '/do-install.txt')) {
 		echo '### Fatal error! ###<br />', "\n";
 		Minz_Log::error($e->getMessage());
 		echo 'See logs files.';
-		prepareSyslog();
 		syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $e->getMessage());
 	}
 }