How can I send a message to the systemd journal from the command line?

systemd-cat is the equivalent to logger: echo ‘hello’ | systemd-cat In another terminal, running journalctl -f: Feb 07 13:38:33 localhost.localdomain cat[15162]: hello Priorities are specified just by part of the string: echo ‘hello’ | systemd-cat -p info echo ‘hello’ | systemd-cat -p warning echo ‘hello’ | systemd-cat -p emerg Warnings are bold, emergencies are bold … Read more

Log all commands run by admins on production servers

Update: 2 more things that have popped up in the comments and in follow-up questions: Using auditd this way will dramatically increase your log volume, especially if the system is heavily in use via commandline. Adjust your log retention policy. Auditd logs on the host where they are created are just as secure as other … Read more

Is there a proper way to clear logs?

You can use: > /var/log/mail.log That will truncate the log without you having to edit the file. It’s also a reliable way of getting the space back. In general it’s a bad thing to use rm on the log then recreating the filename, if another process has the file open then you don’t get the … Read more

Debugging – logging database queries

The debug log will only capture PHP-generated errors as well as things you manually send yourself. So if it is not being created right now, then there are no warnings/errors being generated by PHP right now. In order to send things manually, you use error_log(). One quick note though is that you have to set … Read more

How to add a timestamp to bash script log?

You can pipe the script’s output through a loop that prefixes the current date and time: ./script.sh | while IFS= read -r line; do printf ‘%s %s\n’ “$(date)” “$line”; done >>/var/log/logfile If you’ll be using this a lot, it’s easy to make a bash function to handle the loop: adddate() { while IFS= read -r … Read more

How to catch all PHP errors with custom error handler?

Using a tool to monitor itself is always a problematic idea, if wordpress has errors how do you know that those errors do not impact your integration code in a way which prevents them from being reported upstream? Your best option is probably to setup error reporting levels in php and if applicable in wordpress, … Read more

Sidebar button click redirect when user is not logged in instead displays it

when you want interaction between client side and server side you should use ajax . i think this Link will be very helpful to you 🙂 Put this in your javascript var data = { action: ‘is_user_logged_in’ }; jquery.(‘.x-btn-widgetbar’).on(‘click’,function(){ jQuery.post(ajaxurl, data, function(response) { if(response == ‘yes’) { // user is logged in, do your stuff … Read more

Several times request to load plugins when sending one request

That might well be, but that’s alright. There might be redirects happening, and those will result in multiple requests. The WordPress-Cron System relies on AJAX-requests, those will also show up in the log. If you load any resources (images, scripts, stylesheets) that do not exist, WordPress will be loaded and handle the 404, resulting in … Read more

Debug log file with rolling datestamp in filename?

Well, yes – there is such way. And you even have the solution already in your code… Even more – you almost solved it yourself… This line decides, where the log will be located: @ini_set( ‘error_log’, dirname(__FILE__) . ‘/wp-content/debug.log’ ); So all you need is to add date in that file name. Like this: @ini_set( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)