summaryrefslogtreecommitdiffstats
path: root/lib/private/Log/File.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-04-24 22:14:00 +0200
committerMorris Jobke <hey@morrisjobke.de>2018-04-26 12:00:06 +0200
commit5fbf184134f34633bc150b2e0210c4a97ec285a9 (patch)
treebdc4d79196f1268cf8d5df488c9b31705ceb82a0 /lib/private/Log/File.php
parentb7e8ab97e731b77ef2ec519bfb98019516b7f682 (diff)
downloadnextcloud-server-5fbf184134f34633bc150b2e0210c4a97ec285a9.tar.gz
nextcloud-server-5fbf184134f34633bc150b2e0210c4a97ec285a9.zip
destaticfy Log classes
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/Log/File.php')
-rw-r--r--lib/private/Log/File.php52
1 files changed, 22 insertions, 30 deletions
diff --git a/lib/private/Log/File.php b/lib/private/Log/File.php
index 755c4729c7a..639e4de8ac7 100644
--- a/lib/private/Log/File.php
+++ b/lib/private/Log/File.php
@@ -45,28 +45,21 @@ use OCP\ILogger;
* Log is saved at data/nextcloud.log (on default)
*/
-class File {
- static protected $logFile;
+class File implements IWritable, IFileBased {
+ /** @var string */
+ protected $logFile;
- /**
- * Init class data
- */
- public static function init() {
- $systemConfig = \OC::$server->getSystemConfig();
- $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.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;
- }
+ public function __construct(string $path, string $fallbackPath = '') {
+ $this->logFile = $path;
+ if (!file_exists($this->logFile)) {
+ if(
+ (
+ !is_writable(dirname($this->logFile))
+ || !touch($this->logFile)
+ )
+ && $fallbackPath !== ''
+ ) {
+ $this->logFile = $fallbackPath;
}
}
}
@@ -77,7 +70,7 @@ class File {
* @param string|array $message
* @param int $level
*/
- public static function write($app, $message, $level) {
+ public function write($app, $message, $level) {
$config = \OC::$server->getSystemConfig();
// default to ISO8601
@@ -137,9 +130,9 @@ class File {
}
}
$entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR);
- $handle = @fopen(self::$logFile, 'a');
- if ((fileperms(self::$logFile) & 0777) != 0640) {
- @chmod(self::$logFile, 0640);
+ $handle = @fopen($this->logFile, 'a');
+ if ((fileperms($this->logFile) & 0777) != 0640) {
+ @chmod($this->logFile, 0640);
}
if ($handle) {
fwrite($handle, $entry."\n");
@@ -159,11 +152,10 @@ class File {
* @param int $offset
* @return array
*/
- public static function getEntries($limit=50, $offset=0) {
- self::init();
+ public function getEntries($limit=50, $offset=0) {
$minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", ILogger::WARN);
$entries = array();
- $handle = @fopen(self::$logFile, 'rb');
+ $handle = @fopen($this->logFile, 'rb');
if ($handle) {
fseek($handle, 0, SEEK_END);
$pos = ftell($handle);
@@ -205,7 +197,7 @@ class File {
/**
* @return string
*/
- public static function getLogFilePath() {
- return self::$logFile;
+ public function getLogFilePath() {
+ return $this->logFile;
}
}