|
1 | 1 | # Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/<app_name>.log) |
2 | 2 | # Usage: logtail <app_name> |
3 | | -function logtail() { |
| 3 | + |
| 4 | +logpath() { |
4 | 5 | local app_name="$1" |
5 | 6 | local datetime=`date +%Y/%m/%d/%H` |
6 | 7 | local app_log_dir="{{ app_log_dir }}" |
7 | | - local logfile="${app_log_dir}/${datetime}/${app_name}.log" |
8 | | - tail -f ${logfile} | bunyan |
| 8 | + echo "${app_log_dir}/${datetime}/${app_name}.log" |
9 | 9 | } |
10 | 10 |
|
11 | | -# Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading. |
12 | | -# Usage: npmlog <app_name> |
13 | | -function npmlog() { |
| 11 | +logtail() { |
| 12 | + local app_name="$1" |
| 13 | + tail -f "$(logpath ${app_name})" | bunyan |
| 14 | +} |
| 15 | + |
| 16 | +# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/<app_name>.log) |
| 17 | +# Usage: lograw <app_name> |
| 18 | +lograw() { |
| 19 | + local app_name="$1" |
| 20 | + tail -f "$(logpath ${app_name})" |
| 21 | +} |
| 22 | + |
| 23 | +# Just display the last few lines of a log (2nd arg specifies # of lines or tail default if left blank) |
| 24 | +# Usage: loglast <app_name> [ <#_of_lines> ] |
| 25 | +loglast() { |
| 26 | + local app_name="$1" |
| 27 | + local tailopts="" |
| 28 | + # do not check contents of $2, just if exists, escape jinja2 keyword. |
| 29 | + if [ 2 -eq "{{ '${#}' }}" ] ; then |
| 30 | + tailopts="-${2}" |
| 31 | + fi |
| 32 | + tail "${tailopts}" "$(logpath ${app_name})" | bunyan |
| 33 | +} |
| 34 | + |
| 35 | +# Follow a log, grep for "${regexp}" |
| 36 | +# Usage: greplog <app_name> <regexp> |
| 37 | +greplog() { |
14 | 38 | local app_name="$1" |
15 | | - local app_log_dir="/var/log" |
16 | | - local logfile="${app_log_dir}/${app_name}.log" |
17 | | - less ${logfile} |
| 39 | + local regexp="" |
| 40 | + # again, not checking arg2, just making sure it exists, and espace jinja2 keyword. |
| 41 | + if [ 2 -eq "{{ '${#}' }}" ] ; then |
| 42 | + regexp="${2}" |
| 43 | + fi |
| 44 | + tail -f "$(logpath ${app_name})" | grep "${regexp}" | bunyan |
18 | 45 | } |
19 | 46 |
|
| 47 | +# Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading. |
| 48 | +# Usage: npmlog <app_name> |
| 49 | +npmlog() { |
| 50 | + less "$(logpath ${app_name})" |
| 51 | +} |
0 commit comments