Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

既然使用了monolog,那么在Application::initializeLogger只使用了文件流的特定形式来记录日志是否合理? #494

Closed
403studio opened this issue Aug 25, 2016 · 1 comment

Comments

@403studio
Copy link
Contributor

403studio commented Aug 25, 2016

在Application里发现,在初始化Cache的时候使用了:

if (!empty($this['config']['cache']) && $this['config']['cache'] instanceof CacheInterface) {
            $this['cache'] = $this['config']['cache'];
        } else {
            $this['cache'] = function () {
                return new FilesystemCache(sys_get_temp_dir());
            };
        }

而在日志初始化的时候却采用了另外的一种初始方式:

    private function initializeLogger()
    {
        if (Log::hasLogger()) {
            return;
        }

        $logger = new Logger('easywechat');

        if (!$this['config']['debug'] || defined('PHPUNIT_RUNNING')) {
            $logger->pushHandler(new NullHandler());
        } elseif ($logFile = $this['config']['log.file']) {
            $logger->pushHandler(new StreamHandler($logFile, $this['config']->get('log.level', Logger::WARNING)));
        }

        Log::setLogger($logger);
    }

这种只考虑使用StreamHandler的方式如果在系统希望使用统一的Mologo方式来管理日志会出现问题。是否可以考虑类似于Cache的初始化方式

elseif ($this['config']['logHandler'] instanceof LoggerInterface) {
    $logger->pushHandler($log)
} elseif ($logFile = $this['config']['log.file']) {
            $logger->pushHandler(new StreamHandler($logFile, $this['config']->get('log.level', Logger::WARNING)));
@overtrue
Copy link
Collaborator

@403studio 欢迎 PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants