Short syntax to display all Nginx logs at once aesthetically, in stdout

pntshere asked:

This is how I display all Nginx logs at once aesthetically (with headings and spacing), in stdout, for comfortable debugging.

Input:

printf '\n\n General: \n\n'; nginx -t; printf '\n\n Access: \n\n'; tail /var/log/nginx/access.log; printf '\n\n Errors: \n\n'; tail /var/log/nginx/error.log

Output:

 General:

     ...

 Access:

     ...

 Errors:

     ...

As you can see, the command is quite long or “heavy”.

Is there a shorter (formal?) way to achieve that?

My answer:


I don’t see any way to make the commands shorter, but you can wrap them in a bash function that you can execute later using the function name rather than pasting (or typing!) that command again.

For instance, you could put a function in your .bashrc like:

nginxlogs () {
    printf '\n\n General: \n\n'
    nginx -t
    printf '\n\n Access: \n\n'
    tail /var/log/nginx/access.log
    printf '\n\n Errors: \n\n'
    tail /var/log/nginx/error.log
}

Now when you run nginxlogs from your bash shell, everything will appear.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.