Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMateusz Hyla
4,658 PointsMy code doesn't write anything to log file.
Hi
I rewrited just a code from this video of PHP spacename-ing with Hampton Paulk and it doesn't write anything in app.txt file. I was doing yesterday previous videos in this sections and it was writing properly.
I started to debug this script and I found that after commenting this line :
$log->addWarning("Oh Nose");
Text message : Hello World! is printing properly.
Only explanation for me is that method "addWarning" doesn't exists but I am not 100% sure.
This is all code :
<?php
require "vendor/autoload.php";
date_default_timezone_set("Europe/Warsaw");
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$log = new Logger('name');
$log->pushHandler(new StreamHandler('app.txt', Logger::WARNING));
$log->addWarning("Oh Nose");
echo 'Hello World!';
?>
Can anyone help me solving that case :-).
Cheers
1 Answer
Ted Sumner
Courses Plus Student 17,967 PointsI see two differences between my code and yours. The first is probably your issue. If not this alone, then the second:
use Monolog/Handler/Streamhandler; You have StreamHandler
Change "Oh Nose" to 'Oh Nose'
Mateusz Hyla
4,658 PointsMateusz Hyla
4,658 PointsHey
Probably Streamhandler was the issue :-p.
What is the difference beetwen making string with " and ' ?
Thank you very much Ted for help ^_^.
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsThe only difference that I am aware of is how variables are handled within the quote. Variables are rendered within double quotes and not single. So this would happen:
The first output is: My name is ted. The second output is: My name is $name.