Answers.Body: <p>In answer to your second question:</p>
  
  <blockquote>
    <ol start="2">
    <li>What is the best way to log and follow my controller actions in Craft CP side?</li>
    </ol>
  </blockquote>
  
  <p>You can log actions to a plugin-specific log file like this:</p>
  
  <pre><code>MyPluginNamePlugin::log('Controller action triggered', LogLevel::Info, true);
  </code></pre>
  
  <p>Setting the third parameter to <code>true</code> forces the logging to happen, even if you are not in <code>devMode</code>.</p>
  
  <p>The log file can be found in the <code>craft/storage/runtime/logs/</code> directory and will be called <code>mypluginname.log</code>.</p>
  
  <p>To view logs in the CP visit <code>/admin/utils/logs</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-05T17:22:07.353Z
Answers.LastActivityDate: 2016-10-28T13:48:24.650Z
Answers.LastEditDate: 2016-10-28T13:48:24.650Z
Answers.UserDisplayName: Steve Rowling
Body: <p>I am making a plugin which has a controller to be called every hour.<br>
  My server environment is using <strong>Anacron</strong>.  </p>
  
  <p>So I wrote this anacron job:<br>
  <code>1@hourly 0 cron.hourly wget http://www.mydomain.com/actions/controlername</code></p>
  
  <p>And I got 2 questions:  </p>
  
  <ol>
  <li>How to log my cron job into a file on the server? (so I can follow when it has been triggered)</li>
  <li>What is the best way to log and follow my controller actions in Craft CP side?</li>
  </ol>
  
Tags: <plugin-development><controller><cron>
Title: Call Craft controller with cron job
ThreadText: # Call Craft controller with cron job
  
  (Asked by: username_0 on 2016-08-05)
  
  I am making a plugin which has a controller to be called every hour.  
  My server environment is using **Anacron**.
  
  So I wrote this anacron job:  
  `1@hourly 0 cron.hourly wget http://www.mydomain.com/actions/controlername`
  
  And I got 2 questions:
  
  1. How to log my cron job into a file on the server? (so I can follow when it has been triggered)
  2. What is the best way to log and follow my controller actions in Craft CP side?
  
  **Tags:** plugin-development, controller, cron
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-05. Score: 4
  
  In answer to your second question:
  
  > 2. What is the best way to log and follow my controller actions in Craft CP side?
  
  You can log actions to a plugin-specific log file like this:
  
  ```
  MyPluginNamePlugin::log('Controller action triggered', LogLevel::Info, true);
  
  ```
  
  Setting the third parameter to `true` forces the logging to happen, even if you are not in `devMode`.
  
  The log file can be found in the `craft/storage/runtime/logs/` directory and will be called `mypluginname.log`.
  
  To view logs in the CP visit `/admin/utils/logs`
  
  
  ---
  
  