# Slim Framework logs and Cloud Foundry

**URL:** <https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670>\
**Category:** Questions\
**Created:** [July 12, 2017, 10:11am UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670 "2017-07-12T10:11:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simhamed](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@simhamed](https://discourse.slimframework.com/u/simhamed)\
**Post date:** [July 12, 2017, 10:11am UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670/1 "2017-07-12T10:11:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![marcelloh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/marcelloh/32/404_2.png) [@marcelloh](https://discourse.slimframework.com/u/marcelloh)\
**Post date:** [July 12, 2017, 1:14pm UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670/2 "2017-07-12T13:14:14Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![zaher](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/zaher/32/442_2.png) [@zaher](https://discourse.slimframework.com/u/zaher)\
**Post date:** [July 13, 2017, 8:55pm UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670/3 "2017-07-13T20:55:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![simhamed](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@simhamed](https://discourse.slimframework.com/u/simhamed)\
**Post date:** [July 17, 2017, 7:19am UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670/4 "2017-07-17T07:19:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zaher](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/zaher/32/442_2.png) [@zaher](https://discourse.slimframework.com/u/zaher)\
**Post date:** [July 17, 2017, 7:58am UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670/5 "2017-07-17T07:58:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marcelloh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/marcelloh/32/404_2.png) [@marcelloh](https://discourse.slimframework.com/u/marcelloh)\
**Post date:** [July 19, 2017, 5:52am UTC](https://discourse.slimframework.com/t/slim-framework-logs-and-cloud-foundry/1670/6 "2017-07-19T05:52:06Z")

</div>

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');
```
