Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging kohana日志文件权限:组不可写_Logging_Filesystems_File Permissions - Fatal编程技术网

Logging kohana日志文件权限:组不可写

Logging kohana日志文件权限:组不可写,logging,filesystems,file-permissions,Logging,Filesystems,File Permissions,我们正在Kohana中开发一个API,我们遇到了一个问题,即我们的日志文件没有组的写入权限。以下是11月目录的外观: .../application/logs/2013/11$ ls -al total 2520 drwxr-sr-x 2 xyz wwwxyz 4096 Nov 26 09:12 . drwxr-sr-x 9 xyz wwwxyz 4096 Nov 14 09:55 .. -rw-r--r-- 1 xyz wwwxyz 5769 Nov 14 09:55 04.

我们正在Kohana中开发一个API,我们遇到了一个问题,即我们的日志文件没有组的写入权限。以下是11月目录的外观:

.../application/logs/2013/11$ ls -al
total 2520
drwxr-sr-x 2 xyz wwwxyz    4096 Nov 26 09:12 .
drwxr-sr-x 9 xyz wwwxyz    4096 Nov 14 09:55 ..
-rw-r--r-- 1 xyz wwwxyz    5769 Nov 14 09:55 04.php
-rw-r--r-- 1 xyz wwwxyz 2511368 Nov 14 09:55 05.php
-rw-r--r-- 1 xyz wwwxyz     876 Nov 14 09:55 06.php
-rw-r--r-- 1 xyz wwwxyz     876 Nov 14 09:55 12.php
-rw-r--r-- 1 xyz wwwxyz     300 Nov 14 09:55 13.php
-rw-r--r-- 1 xyz wwwxyz    1961 Nov 26 08:45 14.php
-rw-r--r-- 1 xyz wwwxyz    1961 Nov 26 08:45 22.php
-rw-rw-r-- 1 xyz wwwxyz   21165 Nov 26 09:25 26.php
wwwxyz
是apache用户。已手动修改今日日志文件(2013年11月26日),以使应用程序能够运行

这是我们在应用程序中手动使用日志文件的方式:

Log::instance()->add(Log::INFO,$content)

这是一个访问日志(它存储所有API命令日志)

日志::实例()->添加(日志::错误,$e->getFile()。:'。$e->getLine()。。$e->getMessage())

这是一个错误日志(在try/catch语句中)


目前,我们需要为新创建的日志文件手动设置组(g+w)的可写权限。由于这种解决方案从长远来看是不可接受的,我们希望找到这种情况的原因。

我想我终于找到了解决方案。Kohana的默认日志文件编写器如下所示:

public function write(array $messages)
{
    // Set the yearly directory name
    $directory = $this->_directory.date('Y');

    if ( ! is_dir($directory))
    {
        // Create the yearly directory
        mkdir($directory, 02777);

        // Set permissions (must be manually set to fix umask issues)
        chmod($directory, 02777);
    }

    // Add the month to the directory
    $directory .= DIRECTORY_SEPARATOR.date('m');

    if ( ! is_dir($directory))
    {
        // Create the monthly directory
        mkdir($directory, 02777);

        // Set permissions (must be manually set to fix umask issues)
        chmod($directory, 02777);
    }

    // Set the name of the log file
    $filename = $directory.DIRECTORY_SEPARATOR.date('d').EXT;

    if ( ! file_exists($filename))
    {
        // Create the log file
        file_put_contents($filename, Kohana::FILE_SECURITY.' ?>'.PHP_EOL);

        // Allow anyone to write to log files
        chmod($filename, 0666);
    }

    foreach ($messages as $message)
    {
        // Write each message into the log file
        // Format: time --- level: body
        file_put_contents($filename, PHP_EOL.$message['time'].' --- '.$this->_log_levels[$message['level']].': '.$message['body'], FILE_APPEND);
    }
}
如果您的
日志
目录为空,则它可以正常工作-创建年目录,然后创建月目录,最后创建日日志文件(所有日志文件都具有适当的权限,覆盖umask设置)。我们的问题是由于部署-我们在jenkins上使用rsync。我们有
-rl
标志,而不是od
-rlp
(保留权限)。在jenkins测试期间,我们运行cURL测试,间接创建日志文件。如果没有
-p
标志,则使用应用
g-w
的umask复制日志文件,因此apache用户没有写入日志文件的权限