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

Slim v3 support? #14

Open
JoshWillik opened this issue Mar 19, 2016 · 5 comments
Open

Slim v3 support? #14

JoshWillik opened this issue Mar 19, 2016 · 5 comments

Comments

@JoshWillik
Copy link
Contributor

Does this library support Slim v3?

It doesn't mention any version requirement in README.md and I'm getting an error that Slim\Log colud not be found.

I looked in Slim's source, and v2 has a \Slim\Log, while 3v does not.

@Flynsarmy
Copy link
Owner

Not sure. I don't use slim.

@JoshWillik
Copy link
Contributor Author

But this is a slim plugin...
Which I assume you wrote...

@Flynsarmy
Copy link
Owner

Yea, I played around with Slim ages back but only for long enough to write this package which got far more popular than I was anticipating.

I don't have a solution for the logger issue - perhaps send a PR to grab the array from config or something?

@GenieTim
Copy link

GenieTim commented Apr 3, 2016

For Slim V 3.0, you can use monolog as is, you do not need this library.

Example implementation:

 //after initiating slim
 $container = $app->getContainer();

 $container['logger'] = function($c) {
     $logger = new \Monolog\Logger('my_logger');
     $file_handler = new \Monolog\Handler\StreamHandler("../logs/app.log");
     $logger->pushHandler($file_handler);
    return $logger;
 } ;

And usage in route:

$this->logger->addInfo("YEY! I am logging...");

@kgustine
Copy link

kgustine commented Apr 9, 2016

I concur with @BernhardWebstudio

Slim v2 Setup:

$logger = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array(
    'name' => 'myProject',
    'handlers' => [
        new \Monolog\Handler\ChromePHPHandler(\Monolog\Logger::DEBUG),
        new \Monolog\Handler\RotatingFileHandler(__DIR__ . "/../logs/myProject.log", 3, \Monolog\Logger::DEBUG)
    ],
    'processors' => [
        new Monolog\Processor\WebProcessor(),
        new Monolog\Processor\UidProcessor()
    ]
));

$app = new \Slim\Slim([
    'mode'              => 'development',
    'templates.path'    => '../app/template',
    'cookies.encrypt'   => true,
    'log.writer'        => $logger,
    'log.level'         => \Slim\Log::DEBUG,
]);

with usage:
$app->log->debug('Processing Route: /hello');

Slim v3 Setup:

$container['logger'] = function($c) {
    $logger = new \Monolog\Logger('myProject');     
    $logger->pushHandler(new \Monolog\Handler\ChromePHPHandler(\Monolog\Logger::DEBUG));   
    $logger->pushHandler(new \Monolog\Handler\RotatingFileHandler("../logs/myProject.log", 3, \Monolog\Logger::DEBUG));
    $logger->pushProcessor(new Monolog\Processor\WebProcessor());
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    return $logger;
};

with usage:
$this->logger->debug("Processing Route: /hello");

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

4 participants