Php application logging, how to print messages on console in laravel

class YeahMyController extends BaseController { public function getSomething() { Console::info("mymessage"); // Currently, I"m running the application using artisan (which runs PHP"s built-in development web hệ thống under the hood):

php artisan serveI would lượt thích to lớn log console messages to the STDOUT pipe for the artisan process.

Bạn đang xem: Php application logging, how to print messages on console in laravel




This can be done with the following PHP function:

error_log("Some message here.");Found the answer here: Print something in PHPhường built-in web server



The question relates to lớn serving via artisan & so Jrop"s answer is ikhuyễn mãi giảm giá in that case. I.e, error_log logging khổng lồ the apache log.

However, if your serving via a standard web hệ thống then simply use the Laravel specific logging functions:

Log::info("This is some useful information.");Log::warning("Something could be going wrong.");Log::error("Something is really going wrong.");With current versions of laravel like this for info:

info("This is some useful information.");This logs khổng lồ Laravel"s log file located at /laravel/storage/logs/laravel-.log (laravel 5.0). Monitor the log - linux/osx: tail -f /laravel/storage/logs/laravel-.log


I haven"t tried this myself, but a quiông xã dig through the library suggests you can do this:

$output = new SymfonyComponentConsoleOutputConsoleOutput();$output->writeln("my message");I couldn"t find a shortcut for this, so you would probably want lớn create a facade lớn avoid duplication.

Xem thêm: Code Website Quản Lý Nhân Sự Php Full Code, Cài Đặt Và Tải Source Code Quản Lý Nhân

It"s very simple.

You can gọi it from anywhere in APP.

$out = new SymfonyComponentConsoleOutputConsoleOutput();$out->writeln("Hello from Terminal");
For better explain Dave sầu Morrissey"s answer I have made these steps for wrap with Console Output class in a laravel facade.

1) Create a Facade in your prefer thư mục (in my case appFacades):

class ConsoleOutput đầu ra extends Facade protected static function getFacadeAccessor() return "consoleOutput"; 2) Register a new Service Provider in appProviders as follow:

class ConsoleOutputServiceProvider extends ServiceProvider public function register() App::bind("consoleOutput", function() return new SymfonyComponentConsoleOutputConsoleOutput(); );

3) Add all this stuffs in configapp.php file, registering the provider and alias.

"providers" => < //other providers AppProvidersConsoleOutputServiceProvider::class >, "aliases" => < //other aliases "ConsoleOutput" => AppFacadesConsoleOutput::class, >,That"s it, now in any place of your Laravel application, just Gọi your method in this way: