Skip to content

Commit

Permalink
OS-1615 switch VM.js logging to bunyan
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwilsdon committed Oct 26, 2012
1 parent 15fad47 commit 6172ef4
Show file tree
Hide file tree
Showing 18 changed files with 1,072 additions and 626 deletions.
4 changes: 0 additions & 4 deletions overlay/generic/etc/rsyslog.conf
Expand Up @@ -15,10 +15,6 @@ $ModLoad imudp

*.emerg *

# logs for VM actions
local0.debug /var/log/vmactions.debug
local0.info /var/log/vmactions.log

mail.debug /var/log/syslog

auth.info /var/log/auth.log
Expand Down
3 changes: 1 addition & 2 deletions overlay/generic/manifest
Expand Up @@ -158,5 +158,4 @@ f lib/svc/manifest/network/forwarding.xml 0444 root sys
d var/db 0755 root bin
d var/db/imgadm 0755 root bin
d var/log 0755 root sys
f var/log/vmactions.debug 0644 root root
f var/log/vmactions.log 0644 root root
d var/log/vm 0755 root sys
22 changes: 6 additions & 16 deletions src/Makefile
Expand Up @@ -113,17 +113,6 @@ $(KSTAT.NODE) : CXXFLAGS += $(NODE_CFLAGS)
$(KSTAT.NODE) : LDFLAGS += $(NODE_LDFLAGS)
$(KSTAT.NODE) : LIBS += -lkstat

#
# Likewise the syslog add-on.
#
SYSLOG_OBJDIR = node-syslog/build/Release
SYSLOG.NODE = $(SYSLOG_OBJDIR)/syslog.node

$(SYSLOG.NODE) : WARN_FLAGS += -Wno-unused
$(SYSLOG.NODE) : CPPFLAGS += $(NODE_CPPFLAGS)
$(SYSLOG.NODE) : CXXFLAGS += $(NODE_CFLAGS)
$(SYSLOG.NODE) : LDFLAGS += $(NODE_LDFLAGS)

#
# The sqlite3 add-on uses a combination of C + C++ files in multiple
# directories, and has multiple header directories as well.
Expand Down Expand Up @@ -278,7 +267,6 @@ install: all
mkdir -m 0755 -p $(PREFIX_NODE)/node_modules
cp -Pr node_modules/* $(PREFIX_NODE)/node_modules
cp $(KSTAT.NODE) $(PREFIX_NODE)/node_modules/
cp $(SYSLOG.NODE) $(PREFIX_NODE)/node_modules/syslog.node
rm -rf $(DESTDIR)/usr/vm
cp -PR vm $(DESTDIR)/usr/
mkdir -m 0755 -p $(DESTDIR)/usr/vm/node_modules
Expand Down Expand Up @@ -322,7 +310,13 @@ install: all
mv $(DESTDIR)/usr/vm/sbin/add-userscript.js \
$(DESTDIR)/usr/vm/sbin/add-userscript
mv $(DESTDIR)/usr/vm/sbin/metadata.js $(DESTDIR)/usr/vm/sbin/metadata
mkdir -p $(DESTDIR)/usr/share/man/man1
cp node-bunyan/lib/bunyan.js $(PREFIX_NODE)/node_modules/bunyan.js
cp node-bunyan/docs/bunyan.1 $(DESTDIR)/usr/share/man/man1/bunyan.1
mkdir -p $(DESTDIR)/usr/bin
sed -e 's|^#!/usr/bin/env node.*$$|#!/usr/node/bin/node|' \
< node-bunyan/bin/bunyan \
> $(DESTDIR)/usr/bin/bunyan
cp -PR img $(DESTDIR)/usr/
mkdir -m 0755 -p $(DESTDIR)/var/db/imgadm

Expand Down Expand Up @@ -400,10 +394,6 @@ $(KSTAT.NODE): node-kstat/kstat.cc
@mkdir -p $(KSTAT_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)

$(SYSLOG.NODE): node-syslog/syslog.cc
@mkdir -p $(SYSLOG_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)

$(SQLITE3_OBJDIR)/%.o: $(SQLITE3_SRCDIR)/%.cc $(SQLITE3_HDRS)
@mkdir -p $(SQLITE3_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
Expand Down
3 changes: 2 additions & 1 deletion src/manifest
Expand Up @@ -20,6 +20,8 @@ f usr/img/node_modules/zfs.js 0444 root bin
# new vmadmd
s etc/bash/bash_completion.d/vmadm=/usr/vm/etc/vmadm.completion
f lib/svc/manifest/system/system-vmadmd.xml 0444 root bin
f usr/bin/bunyan 0555 root bin
f usr/share/man/man1/bunyan.1 0444 root bin
f usr/share/man/man1m/vmadmd.1m 0444 root bin
f usr/share/man/man1m/vmadm.1m 0444 root bin
d usr/vm 0555 root bin
Expand Down Expand Up @@ -143,7 +145,6 @@ f usr/node/0.8/node_modules/sprintf.js 0444 root bin
f usr/node/0.8/node_modules/sqlite3.js 0444 root bin
f usr/node/0.8/node_modules/sqlite3_trace.js 0444 root bin
f usr/node/0.8/node_modules/node_sqlite3.node 0444 root bin
f usr/node/0.8/node_modules/syslog.node 0444 root bin
f usr/node/0.8/node_modules/system.js 0444 root bin
f usr/node/0.8/node_modules/zfs.js 0444 root bin
d usr/node/0.8/node_modules/log4js 0555 root bin
Expand Down
187 changes: 187 additions & 0 deletions src/node-bunyan/docs/bunyan.1
@@ -0,0 +1,187 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "BUNYAN" "1" "October 2012" "" "bunyan manual"
.
.SH "NAME"
\fBbunyan\fR \- filter and pretty\-print Bunyan log file content
.
.SH "SYNOPSIS"
\fBbunyan\fR [OPTIONS] [LOOKUPS\.\.\.]
.
.SH "DESCRIPTION"
"Bunyan" is \fBa simple and fast a JSON logging library\fR for node\.js services, a one\-JSON\-object\-per\-line log format, and \fBa \fBbunyan\fR CLI tool\fR for nicely viewing those logs\. This man page describes the latter\.
.
.SS "Pretty\-printing"
A bunyan log file is a stream of JSON objects, optionally interspersed with non\-JSON log lines\. The primary usage of bunyan(1) is to pretty print, for example:
.
.IP "" 4
.
.nf

$ bunyan foo\.log # or `cat foo\.log | bunyan
[2012\-02\-08T22:56:52\.856Z] INFO: myservice/123 on example\.com: My message
extra: multi
line
[2012\-02\-08T22:56:54\.856Z] ERROR: myservice/123 on example\.com: My message
\.\.\.
.
.fi
.
.IP "" 0
.
.P
By default the "long" output format is used\. Use the \fB\-o FORMAT\fR option to emit other formats\. E\.g\.:
.
.IP "" 4
.
.nf

$ bunyan foo\.log \-o short
22:56:52\.856Z INFO myservice: My message
extra: multi
line
22:56:54\.856Z ERROR myservice: My message
\.\.\.
.
.fi
.
.IP "" 0
.
.P
These will color the output if supported in your terminal\. See "OUTPUT FORMATS" below\.
.
.SS "Filtering"
The \fBbunyan\fR CLI can also be used to filter a bunyan log\. Use \fB\-l LEVEL\fR to filter by level:
.
.IP "" 4
.
.nf

$ bunyan foo\.log \-l error # show only \'error\' level records
[2012\-02\-08T22:56:54\.856Z] ERROR: myservice/123 on example\.com: My message
.
.fi
.
.IP "" 0
.
.P
Use \fB\-c COND\fR to filter on a JavaScript expression returning true on the record data\. In the COND code, \fBthis\fR refers to the record object:
.
.IP "" 4
.
.nf

$ bunyan foo\.log \-c `this\.three` # show records with the \'extra\' field
[2012\-02\-08T22:56:52\.856Z] INFO: myservice/123 on example\.com: My message
extra: multi
line
.
.fi
.
.IP "" 0
.
.SH "OPTIONS"
.
.TP
\fB\-h\fR, \fB\-\-help\fR
Print this help info and exit\.
.
.TP
\fB\-\-version\fR
Print version of this command and exit\.
.
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Don\'t warn if input isn\'t valid JSON\.
.
.P
Filtering options:
.
.TP
\fB\-l\fR, \fB\-\-level LEVEL\fR
Only show messages at or above the specified level\. You can specify level \fInames\fR or numeric values\. (See \'Log Levels\' below\.)
.
.TP
\fB\-c COND\fR, \fB\-\-condition COND\fR
Run each log message through the condition and only show those that resolve to a truish value\. E\.g\. \fB\-c \'this\.pid == 123\'\fR\.
.
.TP
\fB\-\-strict\fR
Suppress all but legal Bunyan JSON log lines\. By default non\-JSON, and non\-Bunyan lines are passed through\.
.
.P
Output options:
.
.TP
\fB\-\-color\fR
Colorize output\. Defaults to try if output stream is a TTY\.
.
.TP
\fB\-\-no\-color\fR
Force no coloring (e\.g\. terminal doesn\'t support it)
.
.TP
\fB\-o FORMAT\fR, \fB\-\-output FORMAT\fR
Specify an output format\. One of \fBpaul\fR (the default), \fBshort\fR, \fBjson\fR, \fBjson\-N\fR, or \fBinspect\fR\.
.
.TP
\fB\-j\fR
Shortcut for \fB\-o json\fR\.
.
.SH "LOG LEVELS"
In Bunyan log records, then \fBlevel\fR field is a number\. For the \fB\-l|\-\-level\fR argument the level \fBnames\fR are supported as shortcuts\. In \fB\-c|\-\-condition\fR scripts, uppercase symbols like "DEBUG" are defined for convenience\.
.
.IP "" 4
.
.nf

Level Name Level Number Symbol in COND Scripts
trace 10 TRACE
debug 20 DEBUG
info 30 INFO
warn 40 WARN
error 50 ERROR
fatal 60 FATAL
.
.fi
.
.IP "" 0
.
.SH "OUTPUT FORMATS"
.
.nf

FORMAT NAME DESCRIPTION
paul (default) The default output\. Long form\. Colored and "pretty"\.
\'req\' and \'res\' and \'err\' fields are rendered specially
as an HTTP request, HTTP response and exception
stack trace, respectively\. Note: the "paul" name
is deprecated and will be changed to "long"\.
short Like the default output, but more concise\. Some
typically redundant fields are ellided\.
json JSON output, 2\-space indentation\.
json\-N JSON output, N\-space indentation, e\.g\. "json\-0"
inspect Node\.js `util\.inspect` output\.
.
.fi
.
.SH "PROJECT & BUGS"
\fBbunyan\fR is written in JavaScript and requires node\.js (\fBnode\fR)\. The project lives at \fIhttps://github\.com/trentm/node\-bunyan\fR and is published to npm as "bunyan"\.
.
.IP "\(bu" 4
README, Install notes: \fIhttps://github\.com/trentm/node\-bunyan#readme\fR
.
.IP "\(bu" 4
Report bugs to \fIhttps://github\.com/trentm/node\-bunyan/issues\fR\.
.
.IP "\(bu" 4
See the full changelog at: \fIhttps://github\.com/trentm/node\-bunyan/blob/master/CHANGES\.md\fR
.
.IP "" 0
.
.SH "LICENSE"
MIT License (see \fIhttps://github\.com/trentm/node\-bunyan/blob/master/LICENSE\.txt\fR)
.
.SH "COPYRIGHT"
node\-bunyan is Copyright (c) 2012 Joyent, Inc\. Copyright (c) 2012 Trent Mick\. All rights reserved\.

0 comments on commit 6172ef4

Please sign in to comment.