Yii Log to console (STDOUT)


(Andrekramer84) #1

Yii has some methods for logging: to a db, website, email or file. But I’m using a cloud hosting service(heroku), which uses a console (heroku logs) to display logs. From the documentation I read that to get your logs in the console, you have to output your logs using stdout (http://nl.php.net/manual/en/features.commandline.io-streams.php).

Is this already possible with yii? And if not, how do I hook into the Yii::log() to alsoo output the message using stdout.


(Johannes) #2

You could extend CLogRoute defining your own console log route. You will only have to implement your own version of processLogs($logs) e.g.: using stdout. This route could then be used as your standard logroute defined in the main.php config

greetings,

Hannes


(Johannes) #3

btw.: Heroku supports PHP? Didn’t know that


(Andrekramer84) #4

Yes since a while now.


heroku create --stack cedar

Your repository needs a php file in the root though. So you can’t have

/framework

/public_html

---- /index.php

---- /protected/

And there’s a few other quirks, but nothing big. I create all my facebook apps with it (facebook has buildin heroku support).

Do you have an example of a logger using stdout. The whole concept of stdout is new to me, and I can’t quite grasp it.


(Johannes) #5

Thanks for the info,

I never tried that and I don’t know if that will even work but I would try something like:


class StdOutRoute extends CLogRoute

{

    public function processLogs($logs)

    {

        $STDOUT = fopen("php://stdout", "w");

        foreach($logs as $log)

            fwrite($STDOUT, $log[0]); //write the message [1] = level, [2]=category

        fclose($STDOUT);

    }

}


(Andrekramer84) #6

Thanks I’ll give that a try :)


(Andrekramer84) #7

Ow, people reading this and are interested in heroku, atm it runs on Apache server v2.2.22 and PHP 5.3.10. It has free SSL, addons for MySQL, MongoDB, CouchDB and tons of others. Basic stuff is free, so handy to test out your code in ssl


(Crogiez) #8

hello

i am french developper on facebook

i try to write some data on heroku log

i try this evening in paris

and i confirm tomorow (or not ;-()

regards


(Crogiez) #9

no error in log

but i see no my_data in logs !!!

i work in php


(Crogiez) #10

i can write on a file with data

$fp = fopen ("my_secret_file.txt", "r");

$contenu = fgets ($fp, 255);

fclose ($fp);

echo 'Notre fichier contient : '.$contenu;

$contenu = $contenu.$my_secret_data.’;’;

echo 'Notre fichier contient : '.$contenu;

$fp = fopen ("results.txt", "a+");

fputs ($fp, $contenu);

fclose ($fp);

are you happy ??? yes i am

regards


(Icecappacino) #11

Anyone care to right a tutorial on how to install Yii on a Heroku server?


(Aarondfrancis) #12

I’ve got a lot of info on my blog in regards to Heroku, you can check it out at aaronfrancis.com


(Yiiframework Com) #13

Thanks, good approach! I wrapped this into an extension: http://www.yiiframework.com/extension/yii-streamlog/