我真的不能回答你的问题根据您提供的信息,但它是一个缓慢的新闻天在这里,所以弹奏,一个工作Silex的网站有工作记录。所有的文件都在Github,但我会在这里重复它们以便于阅读。
composer.json
{
"require" : {
"silex/silex" : "^2.0",
"monolog/monolog" : "^1.0"
},
"autoload" : {
"psr-4" : {
"community\\" : "src/"
}
}
}
公共/ index.php的
<?php
use \community\app\Application;
require_once realpath(__DIR__ . '/../vendor/autoload.php');
$app = new Application();
$app["debug"] = true;
$app->run();
SRC /应用/ Application.php
<?php
namespace community\app;
use \Silex\Application as SilexApplication;
use Silex\Provider\MonologServiceProvider;
class Application extends SilexApplication {
function __construct() {
parent::__construct();
$this->registerServices();
$this->mountControllers();
}
function registerServices(){
$this->register(new MonologServiceProvider(), [
"monolog.logfile" => realpath(__DIR__ . "/../../log") . "/general.log"
]);
}
function mountControllers() {
$this->get('/testLog', 'community\controller\TestLogController::doGet');
}
}
SRC /控制器/ TestLogController.php
<?php
namespace community\controller;
use community\app\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class TestLogController {
public function doGet(Request $request, Application $app) {
$app["monolog"]->info("hi!");
return new Response("All good", Response::HTTP_OK);
}
}
写入日志/ general.log如下:
[2016-12-28 13:58:05] app.INFO: hi! [] []
一件事我注意到的是,如果日志文件的路径塞子,然后独白似乎只是把它咽下去(这是不完全理想)。这可能是你的问题。
无论如何,抓住上面的代码并解决它。希望你能解决你和我之间的差异,并让你的工作。
'realpath(__DIR__。'/../ files/logs/log.log')'给了你什么?你期待的文件位置? –