0

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?

pntshere
  • 187
  • 2
  • 2
  • 7

1 Answers1

0

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.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940