|
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 | +} |
| 10 | + |
| 11 | +logtail() { |
| 12 | + local app_name="$1" |
| 13 | + tail -f $(logpath ${app_name}) | bunyan |
9 | 14 | } |
10 | 15 |
|
11 | 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) |
12 | 17 | # Usage: lograw <app_name> |
13 | | -function lograw() { |
| 18 | +lograw() { |
14 | 19 | local app_name="$1" |
15 | | - local datetime=`date +%Y/%m/%d/%H` |
16 | | - local app_log_dir="{{ app_log_dir }}" |
17 | | - local logfile="${app_log_dir}/${datetime}/${app_name}.log" |
18 | | - tail -f ${logfile} |
| 20 | + tail -f $(logpath ${app_name}) |
19 | 21 | } |
20 | 22 |
|
21 | 23 | # Just display the last few lines of a log (2nd arg specifies # of lines or tail default if left blank) |
22 | 24 | # Usage: loglast <app_name> [ <#_of_lines> ] |
23 | | -function loglast() { |
| 25 | +loglast() { |
24 | 26 | local app_name="$1" |
25 | | - local datetime=`date +%Y/%m/%d/%H` |
26 | | - local app_log_dir="{{ app_log_dir }}" |
27 | | - local logfile="${app_log_dir}/${datetime}/${app_name}.log" |
28 | 27 | local tailopts="" |
29 | 28 | # trusting YOU, the user, not to fsck this up |
30 | 29 | if [ 2 -eq ${#} ] ; then |
31 | 30 | tailopts="-${2}" |
32 | 31 | fi |
33 | | - tail ${tailopts} ${logfile} | bunyan |
| 32 | + tail ${tailopts} $(logpath ${app_name}) | bunyan |
34 | 33 | } |
35 | 34 |
|
36 | 35 | # Follow a log, grep for "${regexp}" |
37 | 36 | # Usage: greplog <app_name> <regexp> |
38 | | -function greplog() { |
| 37 | +greplog() { |
39 | 38 | local app_name="$1" |
40 | | - local datetime=`date +%Y/%m/%d/%H` |
41 | | - local app_log_dir="{{ app_log_dir }}" |
42 | | - local logfile="${app_log_dir}/${datetime}/${app_name}.log" |
43 | 39 | local regexp="" |
44 | 40 | # trusting YOU, the user, not to fsck this up |
45 | 41 | if [ 2 -eq ${#} ] ; then |
46 | 42 | regexp="${2}" |
47 | 43 | fi |
48 | | - tail -f ${logfile} | grep ${regexp} | bunyan |
| 44 | + tail -f $(logpath ${app_name}) | grep ${regexp} | bunyan |
49 | 45 | } |
50 | 46 |
|
51 | 47 | # Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading. |
52 | 48 | # Usage: npmlog <app_name> |
53 | | -function npmlog() { |
54 | | - local app_name="$1" |
55 | | - local app_log_dir="/var/log" |
56 | | - local logfile="${app_log_dir}/${app_name}.log" |
57 | | - less ${logfile} |
| 49 | +npmlog() { |
| 50 | + less $(logpath ${app_name}) |
58 | 51 | } |
0 commit comments