- Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathlog2html.sh
executable file
·57 lines (45 loc) · 1.28 KB
/
log2html.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
# Copyright 2016 The Cockroach Authors.
#
# Use of this software is governed by the CockroachDB Software License
# included in the /LICENSE file.
# Script that converts a log file to html, using cockroach-specific log syntax
# highlighting. Requires vim to be installed.
#
# Usage: log2html.sh [input-file [output-file]]
# input-file can be - for stdin.
# If not specified, stdin/stdout are used.
set -e
input="$1"
[ -z"$input" ] && input="-"
output="$2"
outfile="$output"
if [ -z"$output" ];then
outfile=$(mktemp)
trap"rm -f $outfile" EXIT
fi
dir=$(dirname $0)
if!$(which vim >/dev/null 2>/dev/null);then
>&2echo"Error: vim needs to be installed."
>&2echo" on Ubuntu: sudo apt-get install vim-gtk"
>&2echo" on Mac: brew install vim"
exit 1
fi
# Check if vim supports the "--not-a-term" switch which suppresses a warning
# about the output not being a terminal.
EXTRA_OPTS=""
if vim --not-a-term --version >/dev/null 2>/dev/null;then
EXTRA_OPTS="--not-a-term"
fi
vim -X $EXTRA_OPTS -n -i NONE -u NORC \
+"syn on" \
+"colorscheme torte" \
+"source $dir/crlog.vim" \
+"let g:html_no_progress=1" \
+"run! syntax/2html.vim" \
+"saveas! $outfile" \
+"qa!" \
"$input">/dev/null
if [ -z"$output" ];then
cat $outfile
fi