Silalahi logger implementation

Hi ,

I am trying to implement one logger which i can use in any function to write custom log. Silalahi is working good , but when i try to implement same in below way it is not working, any help will be appreciated.
Seems logger is not getting how to call this.

sample code.

<?php require "vendor/autoload.php"; $app = new \Slim\App(); use Monolog\Logger; $container = new \Slim\Container(); $app = new \Slim\App($container); $app->add(new Silalahi\Slim\Logger( [ 'path' => '/var/log/', 'name' => 'main_logger_', 'name_format' => 'Y-m-d', 'extension' => 'log', 'message_format' => '[%label%] %date% %message%' ] ) ); $app->group('/login', function() { $this->put('/wines/{id}', 'updateWine',function ($request,$response,$args) {}); } ); function updateWine($request, $response, $args) { // Info level log $this->logger->write("This message from logger class library", Silalahi\Slim\Logger::INFO); $id=$args['id']; $value = json_decode($request->getBody()); } $app->run(); ?>

You’ve not defined it anywhere as ‘logger’. You’ve added it to the app, not the container which I think is usually the idea.

$container['logger'] = function($container) {
	return new Silalahi\Slim\Logger([
		'path' => '/var/log/',
		'name' => 'main_logger_',
		'name_format' => 'Y-m-d',
		'extension' => 'log',
		'message_format' => '[%label%] %date% %message%'
	]);
};

and then when you use it:

$this->container->logger->write("This message from logger class library", Silalahi\Slim\Logger::INFO);

1 Like