From today, you are my personal hero here.
But please tell me:
Your add-on installed.
Cron-Job Add-on installed
Cron-job with crontab -e added
Method for logging added to the job/file
Is this correct?
if ($this->doLogger == 1)
{
$this->log("message", ['title' => $title, 'message' => $message]);
}
($title and $message are two vars that should be send to the forum by API.)
...
Should this be in the admin log; there i see the cronjob and some html garbage.
Or in the server-log?
Or in your own log? I dont see any.
Okay, there's a couple of things happening here.
First up, the CLI job runner will output information to the console rather than to log files.
We normally run the Job Runner via Unix cron with the
-q
flag to suppress all unnecessary output - so you won't see any logging.
You would need to change the flags to increase the verbosity level:
- Quiet:
cmd.php -q hg:run-jobs
- Normal:
cmd.php hg:run-jobs
- Verbose:
cmd.php -v hg:run-jobs
- Very Verbose:
cmd.php -vv hg:run-jobs
- Debug:
cmd.php -vvv hg:run-jobs
However, even with all that turned on - when triggered via Unix cron, you won't see this output - unless your Unix cron system is configured to send you emails with the contents of any output generated (which can lead to you receiving a LOT of emails from your server!!).
If you are debugging a Job or XF Cron task on a dev server, I suggest you simply run the Job Runner manually from your console - don't trigger it via Unix cron. That way you'll see all output based on the verbosity level you specify on the command line.
If you want to run a specific Cron task manually, Beta 3 introduced two new commands (which I haven't really documented yet) - see below.
If you're trying to debug an issue with a Job running in production then you can force the Unix cron to output all information to a file:
Bash:
cmd.php -vvv hg:run-jobs --time=180 > /var/log/xenforo/`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1
... the above command will store all output in a file with the filename corresponding to the time the task was executed, in the
/var/log/xenforo
directory - you should make sure this path exists and that it is writable by the unix user that your cron task executes as.
The new commands for working with XF cron tasks are:
Show Crons
The
hg:show-crons
command will list all of your active XF cron tasks
Bash:
$ cmd.php hg:show-crons
19 active cron entries found
+---------------------------+----------------------+--------------------------+
| ID | Next Run (UTC+10:00) | Addon |
+---------------------------+----------------------+--------------------------+
| forumStatistics | 29-Sep-2020 06:53 | XF |
| emailBounce | 29-Sep-2020 06:53 | XF |
| warningExpiry | 29-Sep-2020 06:55 | XF |
| rebuildSearchForumCache | 29-Sep-2020 07:00 | XF |
| memberStatsCache | 29-Sep-2020 07:00 | XF |
| feeder | 29-Sep-2020 07:02 | XF |
| cleanUpHourly | 29-Sep-2020 07:10 | XF |
| emailUnsubscribe | 29-Sep-2020 07:13 | XF |
| userGroupPromotions | 29-Sep-2020 07:20 | XF |
| views | 29-Sep-2020 07:30 | XF |
| trophy | 29-Sep-2020 07:40 | XF |
| expireTempUserChanges | 29-Sep-2020 07:42 | XF |
| deleteExpiredBans | 29-Sep-2020 07:45 | XF |
| downgradeExpired | 29-Sep-2020 07:50 | XF |
| fileCheck | 29-Sep-2020 10:10 | XF |
| dailyStats | 29-Sep-2020 10:30 | XF |
| cleanUpDaily | 29-Sep-2020 13:00 | XF |
| activitySummaryEmail | 30-Sep-2020 00:20 | XF |
| sitemap | 30-Sep-2020 15:37 | XF |
+---------------------------+----------------------+--------------------------+
The current time is: 29-Sep-2020 06:52:05 (UTC+10:00)
There are three command line options you can specify:
-a
or --all
shows all cron tasks, including disabled tasks
-m
or --method
includes the class::method
for each cron task
-s
or --sort
specifies the sort column for the list (date, id or addon)
You can use this tool to quickly identify the ID of the cron task you want to run - which you then use on the other new command ...
Run Cron
The
hg:run-cron
command will execute an XF cron task - simply specify a cron ID as the argument.
For example:
cmd.php hg:run-cron activitySummaryEmail
will run the "Send activity summary email" cron task.
By default, disabled cron tasks cannot be run - so you can override this by specifying the
-f
or
--force
option on the command line.
The same verbosity flags work here - so specify
-v
,
-vv
or
-vvv
to generate the desired level of output.