# Need a simple example please

**URL:** <https://discourse.slimframework.com/t/need-a-simple-example-please/1434>\
**Category:** Questions\
**Created:** [April 24, 2017, 9:18am UTC](https://discourse.slimframework.com/t/need-a-simple-example-please/1434 "2017-04-24T09:18:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![russellharrower](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@russellharrower](https://discourse.slimframework.com/u/russellharrower)\
**Post date:** [April 24, 2017, 9:18am UTC](https://discourse.slimframework.com/t/need-a-simple-example-please/1434/1 "2017-04-24T09:18:24Z")

</div>

Ok so here is the issues:

1. MonoLog is installed via composer require mongolog/monolog
2. Slimphp is installed via composer require slim/slim “^3.0”

My index page is:

```
<?php

require 'vendor/autoload.php';

$app = new Slim\App();
$container = $app->getContainer();

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $response->write("Hello, " . $args['name']);
    return $container;
});

$app->run();
?>

```

now I don’t understand how the following document integrates monolog  
[https://www.slimframework.com/docs/tutorial/first-app.html#use-monolog-in-your-application](https://www.slimframework.com/docs/tutorial/first-app.html#use-monolog-in-your-application)

So if someone could please show me how I simply add monolog logging to my index.php file.

Thank you.

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [April 24, 2017, 11:27am UTC](https://discourse.slimframework.com/t/need-a-simple-example-please/1434/2 "2017-04-24T11:27:09Z")

</div>

Have you setup a container or configured Monolog anywhere? You might want to have a look at [slimphp/Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton) and see how it is wired together in that example, and here is the [index.php](https://github.com/slimphp/Slim-Skeleton/blob/master/public/index.php) from that example.

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [April 24, 2017, 11:38am UTC](https://discourse.slimframework.com/t/need-a-simple-example-please/1434/3 "2017-04-24T11:38:31Z")

</div>

In the First Application Walkthrough you referenced, have a look in that [index.php](https://github.com/slimphp/Tutorial-First-Application/blob/master/src/public/index.php). The logger is configured on line #22, then you can see it used on line #39.

In your example, you would likely want something like this (I have not tested it):

```php
<?php

require 'vendor/autoload.php';

$app = new Slim\App();
$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;
};

$app->get('/hello/{name}', function ($request, $response, $args) {
    $this->logger->addInfo("Hello route reached");
    return $response->write("Hello, " . $args['name']);
});

$app->run();

```

---

<div class="post-metadata">

**Author:** ![russellharrower](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@russellharrower](https://discourse.slimframework.com/u/russellharrower)\
**Post date:** [April 24, 2017, 11:48am UTC](https://discourse.slimframework.com/t/need-a-simple-example-please/1434/4 "2017-04-24T11:48:31Z")

</div>

> [@tflight](#):
>
> a look

I tried [GitHub - slimphp/Slim-Skeleton: Slim Framework 4 Skeleton Application](https://github.com/slimphp/Slim-Skeleton) however does not work with cpanel layout. In other words the slim-skeleton example is public\_html is inside public yet it needs to be in public\_html folder for cpanel to work.

It would be great if they had a version for running it in public\_html an not a sub-directory, and yes I know I could just .htaccess this but rather not.

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [April 24, 2017, 12:00pm UTC](https://discourse.slimframework.com/t/need-a-simple-example-please/1434/5 "2017-04-24T12:00:41Z")

</div>

just rename `public` to `public_html` (or move the index.php file) and it should work fine, the folder name isn’t hardcoded into Slim anywhere. I run things from a directory called `content` and don’t need to change anything else.
