Zephyr
(Andrekramer84)
April 4, 2012, 7:44am
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.
Haensel
(Johannes)
April 4, 2012, 12:05pm
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
Haensel
(Johannes)
April 4, 2012, 12:09pm
3
btw.: Heroku supports PHP? Didn’t know that
Zephyr
(Andrekramer84)
April 4, 2012, 1:21pm
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.
Haensel
(Johannes)
April 4, 2012, 1:46pm
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);
}
}
Zephyr
(Andrekramer84)
April 4, 2012, 2:19pm
6
Haensel:
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);
}
}
Thanks I’ll give that a try
Zephyr
(Andrekramer84)
April 4, 2012, 2:29pm
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
(Crogiez)
May 16, 2012, 12:09pm
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
(Crogiez)
May 16, 2012, 4:56pm
9
no error in log
but i see no my_data in logs !!!
i work in php
crogiez
(Crogiez)
May 16, 2012, 5:07pm
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
isekream
(Icecappacino)
October 12, 2012, 9:08pm
11
Anyone care to right a tutorial on how to install Yii on a Heroku server?
I’ve got a lot of info on my blog in regards to Heroku, you can check it out at aaronfrancis.com
motin
(Yiiframework Com)
March 11, 2015, 11:02pm
13
Haensel:
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);
}
}
Thanks, good approach! I wrapped this into an extension: http://www.yiiframework.com/extension/yii-streamlog/
grigori
(Public)
August 13, 2019, 9:54pm
14
No need to define the custom target as a class, you can use FileTarget
'targets' => [
[
'class' => FileTarget::class,
'logFile' => 'php://stdout',
1 Like
azophy
(Abdurrahman Shofy Adianto)
November 26, 2020, 4:22am
15
thanks! this should be included in the docs