Skip to content

Commit 46401da

Browse files
committed
Merge pull request #466 from CodeNow/SAN-4222-etudes-des-logs
Add some new jazz to logtail
2 parents 8313a33 + 6a52103 commit 46401da

4 files changed

Lines changed: 41 additions & 39 deletions

File tree

ansible/dock.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111

1212
- include: charon.yml git_branch="{{ charon_version }}"
1313
- include: dock-init.yml git_branch="{{ dock_init_version }}"
14-
- include: filibuster.yml git_branch="{{ filibuster_version }}"
1514
- include: image-builder.yml git_branch="{{ image_builder_version }}"
1615
- include: krain.yml git_branch="{{ krain_version }}"

ansible/roles/bash_aliases/tasks/main.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,3 @@
77
owner=ubuntu
88
group=ubuntu
99
mode=0700
10-
11-
- name: copy bash aliases to root
12-
tags: [ loggly, bash_aliases ]
13-
become: true
14-
template:
15-
src=dot_bash_aliases_root.sh.j2
16-
dest=/root/.bash_aliases
17-
owner=root
18-
group=root
19-
mode=0700
Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
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)
22
# Usage: logtail <app_name>
3-
function logtail() {
3+
4+
logpath() {
45
local app_name="$1"
56
local datetime=`date +%Y/%m/%d/%H`
67
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"
99
}
1010

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() {
1438
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
1845
}
1946

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+
}

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)