Skip to content

Commit 11b1c3e

Browse files
author
Christopher M. Neill
committed
Add some new jazz to logtail
1 parent f935466 commit 11b1c3e

2 files changed

Lines changed: 80 additions & 2 deletions

File tree

ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@ function logtail() {
88
tail -f ${logfile} | bunyan
99
}
1010

11+
# 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+
# Usage: lograw <app_name>
13+
function lograw() {
14+
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}
19+
}
20+
21+
# Just display the last few lines of a log (2nd arg specifies # of lines or tail default if left blank)
22+
# Usage: loglast <app_name> [ <#_of_lines> ]
23+
function loglast() {
24+
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+
local tailopts=""
29+
# trusting YOU, the user, not to fsck this up
30+
if [ 2 -eq ${#} ] ; then
31+
tailopts="-${2}"
32+
fi
33+
tail ${tailopts} ${logfile} | bunyan
34+
}
35+
36+
# Follow a log, grep for "${regexp}"
37+
# Usage: greplog <app_name> <regexp>
38+
function greplog() {
39+
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+
local regexp=""
44+
# trusting YOU, the user, not to fsck this up
45+
if [ 2 -eq ${#} ] ; then
46+
regexp="${2}"
47+
fi
48+
tail -f ${logfile} | grep ${regexp} | bunyan
49+
}
50+
1151
# Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading.
1252
# Usage: npmlog <app_name>
1353
function npmlog() {
@@ -16,4 +56,3 @@ function npmlog() {
1656
local logfile="${app_log_dir}/${app_name}.log"
1757
less ${logfile}
1858
}
19-

ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@ function logtail() {
88
tail -f ${logfile} | bunyan
99
}
1010

11+
# 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+
# Usage: lograw <app_name>
13+
function lograw() {
14+
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}
19+
}
20+
21+
# Just display the last few lines of a log (2nd arg specifies # of lines or tail default if left blank)
22+
# Usage: loglast <app_name> [ <#_of_lines> ]
23+
function loglast() {
24+
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+
local tailopts=""
29+
# trusting YOU, the user, not to fsck this up
30+
if [ 2 -eq ${#} ] ; then
31+
tailopts="-${2}"
32+
fi
33+
tail ${tailopts} ${logfile} | bunyan
34+
}
35+
36+
# Follow a log, grep for "${regexp}"
37+
# Usage: greplog <app_name> <regexp>
38+
function greplog() {
39+
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+
local regexp=""
44+
# trusting YOU, the user, not to fsck this up
45+
if [ 2 -eq ${#} ] ; then
46+
regexp="${2}"
47+
fi
48+
tail -f ${logfile} | grep ${regexp} | bunyan
49+
}
50+
1151
# Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading.
1252
# Usage: npmlog <app_name>
1353
function npmlog() {
@@ -16,4 +56,3 @@ function npmlog() {
1656
local logfile="${app_log_dir}/${app_name}.log"
1757
less ${logfile}
1858
}
19-

0 commit comments

Comments
 (0)