1

I am trying to log sone info on my plugins service work like below:

Craft::info(
  Craft::t('mapitapi',
          'Sleeping for 1 secs ..saved funding entry: ' . $element->id . ':' . $element->title . '| lsoa:' . $element->lsoacode),
           __METHOD__
         );

But nothing appears in the logs. Do i need to include something in the namespace? Or??

4
  • Info + Debug logs may get filtered out based on the application's environment. What is your ENVIRONMENT set as, in .env? Commented Dec 16, 2021 at 22:57
  • thanks for reply - .env is set like ENVIRONMENT=dev
    – joomkit
    Commented Dec 16, 2021 at 23:00
  • Ok, checks out… hmm! You will have a few log files, depending on where this is running. In a front-end "web" request, it'll go to web.log, but for the queue (regardless of how it's running), it goes in queue.log, and (unsurprisingly) the CLI outputs to console.log! Make sure you're looking in the correct file, and if the volume of data is too large to scan, you can run tail -f storage/logs/{file}.log | grep {your method or class name}. Commented Dec 16, 2021 at 23:04
  • It was in the queue log! Doh! Thx 🙏
    – joomkit
    Commented Dec 16, 2021 at 23:09

1 Answer 1

2

At first, I didn't internalize the substance of the log message, and assumed the logger was filtering out your statement due to the target's configured "levels."

However, considering that sleep() is typically avoided in user-facing web requests, it occurred to me that we're looking at some code that is in a queue job or console command.

Craft maintains a discrete log file for each context:

  1. Web requests log to storage/logs/web.log;
  2. Queue jobs (not really a "request type" per se) log to storage/logs/queue.log;
  3. The CLI logs to storage/logs/console.log;

Some plugins or modules may create and log to other files, and via app.php, log targets can be configured to ignore or otherwise filter and redirect log statements based on the environment.

For an in-depth look at Craft's logging system, check out Zen and the Art of Craft CMS Log File Reading on nystudio107.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.