aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/log
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/log')
-rw-r--r--lib/private/log/errorhandler.php97
-rw-r--r--lib/private/log/errorlog.php45
-rw-r--r--lib/private/log/owncloud.php180
-rw-r--r--lib/private/log/rotate.php50
-rw-r--r--lib/private/log/syslog.php52
5 files changed, 0 insertions, 424 deletions
diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php
deleted file mode 100644
index 27cde4aa242..00000000000
--- a/lib/private/log/errorhandler.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-/**
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Björn Schießle <schiessle@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Log;
-
-use OCP\ILogger;
-
-class ErrorHandler {
- /** @var ILogger */
- private static $logger;
-
- /**
- * remove password in URLs
- * @param string $msg
- * @return string
- */
- protected static function removePassword($msg) {
- return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
- }
-
- public static function register($debug=false) {
- $handler = new ErrorHandler();
-
- if ($debug) {
- set_error_handler(array($handler, 'onAll'), E_ALL);
- } else {
- set_error_handler(array($handler, 'onError'));
- }
- register_shutdown_function(array($handler, 'onShutdown'));
- set_exception_handler(array($handler, 'onException'));
- }
-
- public static function setLogger(ILogger $logger) {
- self::$logger = $logger;
- }
-
- //Fatal errors handler
- public static function onShutdown() {
- $error = error_get_last();
- if($error && self::$logger) {
- //ob_end_clean();
- $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line'];
- self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
- }
- }
-
- /**
- * Uncaught exception handler
- *
- * @param \Exception $exception
- */
- public static function onException($exception) {
- $class = get_class($exception);
- $msg = $exception->getMessage();
- $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine();
- self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']);
- }
-
- //Recoverable errors handler
- public static function onError($number, $message, $file, $line) {
- if (error_reporting() === 0) {
- return;
- }
- $msg = $message . ' at ' . $file . '#' . $line;
- self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
-
- }
-
- //Recoverable handler which catch all errors, warnings and notices
- public static function onAll($number, $message, $file, $line) {
- $msg = $message . ' at ' . $file . '#' . $line;
- self::$logger->debug(self::removePassword($msg), array('app' => 'PHP'));
-
- }
-
-}
diff --git a/lib/private/log/errorlog.php b/lib/private/log/errorlog.php
deleted file mode 100644
index ad3605136d0..00000000000
--- a/lib/private/log/errorlog.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Christian Kampka <christian@kampka.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-class OC_Log_Errorlog {
-
-
- /**
- * Init class data
- */
- public static function init() {
- }
-
- /**
- * write a message in the log
- * @param string $app
- * @param string $message
- * @param int $level
- */
- public static function write($app, $message, $level) {
- error_log('[owncloud]['.$app.']['.$level.'] '.$message);
- }
-}
-
diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php
deleted file mode 100644
index 9c106299e4c..00000000000
--- a/lib/private/log/owncloud.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-/**
- * @author Andreas Fischer <bantu@owncloud.com>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Christian Schnidrig <christian.schnidrig@switch.ch>
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/**
- * logging utilities
- *
- * Log is saved at data/owncloud.log (on default)
- */
-
-class OC_Log_Owncloud {
- static protected $logFile;
-
- /**
- * Init class data
- */
- public static function init() {
- $systemConfig = \OC::$server->getSystemConfig();
- $defaultLogFile = $systemConfig->getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log';
- self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile);
-
- /**
- * Fall back to default log file if specified logfile does not exist
- * and can not be created.
- */
- if (!file_exists(self::$logFile)) {
- if(!is_writable(dirname(self::$logFile))) {
- self::$logFile = $defaultLogFile;
- } else {
- if(!touch(self::$logFile)) {
- self::$logFile = $defaultLogFile;
- }
- }
- }
- }
-
- /**
- * write a message in the log
- * @param string $app
- * @param string $message
- * @param int $level
- */
- public static function write($app, $message, $level) {
- $config = \OC::$server->getSystemConfig();
-
- // default to ISO8601
- $format = $config->getValue('logdateformat', 'c');
- $logTimeZone = $config->getValue( "logtimezone", 'UTC' );
- try {
- $timezone = new DateTimeZone($logTimeZone);
- } catch (Exception $e) {
- $timezone = new DateTimeZone('UTC');
- }
- $time = DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""));
- if ($time === false) {
- $time = new DateTime(null, $timezone);
- } else {
- // apply timezone if $time is created from UNIX timestamp
- $time->setTimezone($timezone);
- }
- $request = \OC::$server->getRequest();
- $reqId = $request->getId();
- $remoteAddr = $request->getRemoteAddress();
- // remove username/passwords from URLs before writing the to the log file
- $time = $time->format($format);
- $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
- $method = is_string($request->getMethod()) ? $request->getMethod() : '--';
- if(\OC::$server->getConfig()->getSystemValue('installed', false)) {
- $userObj = \OC::$server->getUserSession()->getUser();
- } else {
- $userObj = null;
- }
- $user = !is_null($userObj) ? $userObj->getUID() : '--';
- $entry = compact(
- 'reqId',
- 'remoteAddr',
- 'app',
- 'message',
- 'level',
- 'time',
- 'method',
- 'url',
- 'user'
- );
- $entry = json_encode($entry);
- $handle = @fopen(self::$logFile, 'a');
- @chmod(self::$logFile, 0640);
- if ($handle) {
- fwrite($handle, $entry."\n");
- fclose($handle);
- } else {
- // Fall back to error_log
- error_log($entry);
- }
- if (php_sapi_name() === 'cli-server') {
- error_log($message, 4);
- }
- }
-
- /**
- * get entries from the log in reverse chronological order
- * @param int $limit
- * @param int $offset
- * @return array
- */
- public static function getEntries($limit=50, $offset=0) {
- self::init();
- $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN);
- $entries = array();
- $handle = @fopen(self::$logFile, 'rb');
- if ($handle) {
- fseek($handle, 0, SEEK_END);
- $pos = ftell($handle);
- $line = '';
- $entriesCount = 0;
- $lines = 0;
- // Loop through each character of the file looking for new lines
- while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) {
- fseek($handle, $pos);
- $ch = fgetc($handle);
- if ($ch == "\n" || $pos == 0) {
- if ($line != '') {
- // Add the first character if at the start of the file,
- // because it doesn't hit the else in the loop
- if ($pos == 0) {
- $line = $ch.$line;
- }
- $entry = json_decode($line);
- // Add the line as an entry if it is passed the offset and is equal or above the log level
- if ($entry->level >= $minLevel) {
- $lines++;
- if ($lines > $offset) {
- $entries[] = $entry;
- $entriesCount++;
- }
- }
- $line = '';
- }
- } else {
- $line = $ch.$line;
- }
- $pos--;
- }
- fclose($handle);
- }
- return $entries;
- }
-
- /**
- * @return string
- */
- public static function getLogFilePath() {
- return self::$logFile;
- }
-}
diff --git a/lib/private/log/rotate.php b/lib/private/log/rotate.php
deleted file mode 100644
index 458661c82d0..00000000000
--- a/lib/private/log/rotate.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Log;
-
-/**
- * This rotates the current logfile to a new name, this way the total log usage
- * will stay limited and older entries are available for a while longer.
- * For more professional log management set the 'logfile' config to a different
- * location and manage that with your own tools.
- */
-class Rotate extends \OC\BackgroundJob\Job {
- private $max_log_size;
- public function run($logFile) {
- $this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', false);
- if ($this->max_log_size) {
- $filesize = @filesize($logFile);
- if ($filesize >= $this->max_log_size) {
- $this->rotate($logFile);
- }
- }
- }
-
- protected function rotate($logfile) {
- $rotatedLogfile = $logfile.'.1';
- rename($logfile, $rotatedLogfile);
- $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
- \OCP\Util::writeLog('OC\Log\Rotate', $msg, \OCP\Util::WARN);
- }
-}
diff --git a/lib/private/log/syslog.php b/lib/private/log/syslog.php
deleted file mode 100644
index 96cf463d042..00000000000
--- a/lib/private/log/syslog.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/**
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-class OC_Log_Syslog {
- static protected $levels = array(
- \OCP\Util::DEBUG => LOG_DEBUG,
- \OCP\Util::INFO => LOG_INFO,
- \OCP\Util::WARN => LOG_WARNING,
- \OCP\Util::ERROR => LOG_ERR,
- \OCP\Util::FATAL => LOG_CRIT,
- );
-
- /**
- * Init class data
- */
- public static function init() {
- openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "ownCloud"), LOG_PID | LOG_CONS, LOG_USER);
- // Close at shutdown
- register_shutdown_function('closelog');
- }
-
- /**
- * write a message in the log
- * @param string $app
- * @param string $message
- * @param int $level
- */
- public static function write($app, $message, $level) {
- $syslog_level = self::$levels[$level];
- syslog($syslog_level, '{'.$app.'} '.$message);
- }
-}