phplog4php

Php log4php mkdir permission denied


After moving the project from a local machine to a production machine, I get the following error:

<b>Warning</b>:  mkdir(): Permission denied in
<b>/var/www/html/findmynumber/api/v1/apache-log4php-2.3.0/src/main/php/appenders/LoggerAppenderFile.php</b> on line
<b>93</b>
<br/>
<b>Warning</b>:  log4php: [LoggerAppenderFile:myAppender]: Failed creating target directory [/var/wwww/html/findmynumber/api/v1/logs]. Closing appender. in
<b>/var/www/html/findmynumber/api/v1/apache-log4php-2.3.0/src/main/php/LoggerAppender.php</b> on line
<b>283</b>

The owner is www-data. Also the group is www-data. I even tried give full permissions(777) for the project folder but with no success.

The calls for log4php are:

include dirname(__FILE__) . "/apache-log4php-2.3.0/src/main/php/Logger.php"; 
Logger::configure(dirname(__FILE__) . '/apache-log4php-2.3.0/src/config.xml'); 
$log = Logger::getLogger('myLogger');

The config.xml looks like this:

<configuration>
  <appender name="myAppender" class="LoggerAppenderFile">
    <param name="file" value="/var/wwww/html/findmynumber/api/v1/logs/myLog.log"/>
  </appender>
  <appender name="console" class="LoggerAppenderConsole"/>
  <root>
    <appender_ref ref="console"/>
  </root>
  <logger name="myLogger">
    <level value="DEBUG"/>
    <appender_ref ref="myAppender"/>
  </logger>
</configuration>

What am I missing here?

Edit

Bellow is the function were the error appears. It is taken from the log4php files, from LoggerAppenderFile.php:

protected function openFile() { 
    $file = $this->getTargetFile(); 
    echo $file . "\n"; 
    $curr = !is_file($file); 
    echo "curr is: " . $curr . "\n"; 
    echo is_file($file) . "\n" ; 
    echo dirname($file) . "\n"; 
    // Create the target folder if needed 
    if(!is_file($file)) { 
        $dir = dirname($file); 

        if(!is_dir($dir)) { 
            $success = mkdir($dir, 0777, true); 
            if ($success === false) { 
                $this->warn("Failed creating target directory [$dir]. Closing appender."); 
                $this->closed = true; 
                return false; 
            } 
        } 
    }

As you see, I added some debug prints myself. The 93 line is the one with mkdir statement.


Solution

  • @florin problem is typo mistake in config.xml

     <appender name="myAppender" class="LoggerAppenderFile">
        <param name="file" value="/var/wwww/html/findmynumber/api/v1/logs/myLog.log"/>
      </appender>
    

    it should be like this

    /var/www/html/findmynumber/api/v1/logs/myLog.log. instead of www you kept wwww 
    

    this one you can check in this warning

    <b>Warning</b>:  log4php: [LoggerAppenderFile:myAppender]: Failed creating target directory [/var/wwww/html/findmynumber/api/v1/logs]. Closing appender. in