Slim Framework logs and Cloud Foundry

Hello,
I have a question about Slim Framework’s logs and Cloud Foundry.
I have an app that uses the Slim logs this way :

$app = new \Slim\Slim ( array (
        'log.writer' => new logHelper ( array (
                'path' => LOG_DIRECTORY_PATH,
                'fileName' => 'myapp_mycollection',
                'extension' => 'log',
                'messageFormat' => '%host% - %user% [%dateTime%] "%referer%" "%userAgent%" : %message%' 
        ) ) 
    ) );
$app->log->setEnabled ( true );
$app->log->info("My Log here");

This works perfectly fine by the way on a non-CF environment.

Now I’m migrating my app to CF.
I’d like to know if there’s a way I can still use the Slim log.writer ?

I’ve tried this approach (found on another forum):

$_ENV['SLIM_MODE'] = 'development';
$app = new \Slim\Slim ( );
$app->configureMode('development', function () use ($app) {
        $app->config(array(
            'log.enable' => true,
            'log.level' => \Slim\Log::DEBUG,
            'debug' => true
        ));
 });

But with no luck, I can’t find the “My log here” anywhere… (doesn’t seem to return any error either)
Is there anyone here who knows if it’s possible to keep using the log.writer on CF and how to ?
I’m kinda new on the CF part, thanks in advance for any help guys!

Perhaps the first version runs on Windows, and CF runs on Linux?
(Linux has to have writing rights for the ‘user’ that runs the php in the directory where the logfile is created.)

which version of slim you are using? v3 or v2?

V2 :slight_smile: (2.3.1)
I can change to a higher version, as long as I use a V2

Am not a CF user, but I guess the first thing you should do is to look at the output from $_ENV using getenv function and see if it does set the value that you want or not. Also check the values from array_key_exists('ENVIRONMENT', $_SERVER) and see if it has the SLIM_MODE set to development or not .

Last thing check that you are using the same PHP version.

That’s all I have in my mind in my mind to be honest.

1 Like

I use Monolog… perhaps it’s worth trying (but I can’t promise you run into the same trouble)

A snippet from my config:

$container = $app->getContainer();

// Register logger on container
$container['logger'] = function($container) {
    $settings = $container->get('settings');
    $logger = new \Monolog\Logger('shop');
    $file_handler = new \Monolog\Handler\StreamHandler('../logs/' . $settings['logfile'].'.log');
    $logger->pushHandler($file_handler);
    return $logger;
};

Usage:

$container['logger']->addInfo('Environment ' . $config['env'] . ' loaded');
1 Like