File indexing completed on 2024-12-22 05:36:23

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  *
0023  * Created: 09.10.2018
0024  */
0025 class Local_Log_File
0026 {
0027     const extension = ".log";
0028 
0029     protected $logfile;
0030 
0031     /**
0032      * @inheritDoc
0033      */
0034     public function __construct($domain, $filename)
0035     {
0036         $this->initLog($domain, $filename);
0037     }
0038 
0039     /**
0040      * @return mixed
0041      */
0042     private function initLog($domain, $filename)
0043     {
0044         $fileDomainId = str_replace('.', '_', $domain);
0045         $date = date("Y-m-d_H-i-s");
0046         $date = date("Y-m-d");
0047         $this->logfile = realpath(APPLICATION_DATA . "/logs") . DIRECTORY_SEPARATOR . $date . '_' . $fileDomainId . '_' . $filename . self::extension;
0048         //$this->initFiles($this->logfile);
0049     }
0050 
0051     /**
0052      * @param $file
0053      * @param $errorFile
0054      */
0055     private function initFiles($file)
0056     {
0057         if (file_exists($file)) {
0058             file_put_contents($file, "1");
0059             unlink($file);
0060         }
0061     }
0062 
0063     /**
0064      * @param $message
0065      */
0066     public function info($message)
0067     {
0068         $timestamp = date("c");
0069         file_put_contents($this->logfile, $timestamp . " [INFO] : " . $message . PHP_EOL, FILE_APPEND);
0070     }
0071 
0072     /**
0073      * @param $message
0074      */
0075     public function err($message)
0076     {
0077         $timestamp = date("c");
0078         file_put_contents($this->logfile, $timestamp . " [ERROR] : " . $message . PHP_EOL, FILE_APPEND);
0079     }
0080 
0081 }