php.ini 为 xdebug.log 设置当前日期的动态文件夹路径

php.ini set dynamic folder path with current date for xdebug.log

所以我的问题是我的 xdebug.log 文件太大了,所以我想每天将它拆分成一个文件。 我知道如何手动执行此操作,但我想知道是否可以通过 php.ini 为新的 xdebug 文件设置动态路径,因为它是定义路径的地方。 目前我有这个:

php.ini
xdebug.remote_log="D:\Work\Project\www\xdebug.log"

我想以这样的方式结束:

php.ini
xdebug.remote_log="D:\Work\Project\www17_xdebug.log"

我知道有可能使用一些变量(我确实阅读了 php 文档,google 几个小时后)但我真的找不到明确的答案到目前为止,关于我是否可以做到这一点,是否有解决方法或如何做到这一点!

提前致谢!! (如果我错过了一些需要提供的信息,请告诉我!)

最后使用 powershell 简单地通过脚本解决方案完成了这个。

在这里你可以看到函数(你可以直接在你的 Microsoft.Powershell_profile.ps1 中添加它(更多关于如何创建的信息在这里:https://www.howtogeek.com/50236/customizing-your-powershell-profile/

function xdebugsetlogpath {
    # Set directory logs path (year\month)
    $DirPath = ("Path\To\Your\logs\" + (Get-Date -UFormat '%Y\%m'))
    # Set xdebug.log file name (day_xdebug.log)
    $NewFile = (Get-Date -UFormat '%d') + "_xdebug.log"
    # Set full file path
    $NewFilePath = ($DirPath + "\" + $NewFile)
    # Create the folder beforehand as xdebug wont do it itself
    New-Item -ItemType Directory -Force -Path $DirPath
    # Create the file (xdebug can do it but well)
    New-Item $NewFilePath
    (Get-Content C:\PHP712\php.ini) | `
        ForEach-Object { $_ -replace 'xdebug.remote_log=.*',('xdebug.remote_log="' + $NewFilePath + '"') } | `
        Set-Content C:\PHP712\php.ini
    # Don't forget to restart service
    httpd -k restart
}

将其添加到您的配置文件后,只需重新启动您的 powershell 提示符并键入 xdebugsetlogpath 即可! (不要忘记编辑您想要登录的路径!)