Skip to content

Commit

Permalink
add option to specify logging timestamp format
Browse files Browse the repository at this point in the history
  • Loading branch information
jprjr committed Feb 20, 2019
1 parent 747ee65 commit 45fe7f6
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 12 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ with built-in log rotation.

`socklog-overlay` works by reading in a series of `s6-log` logging scripts from
`/etc/socklog.rules`. You can create your own rules by placing a file in
`/etc/socklog.rules`.
`/etc/socklog.rules`. Each directive (selection directive, control directive,
or action directive) for the logging script should be on its own line.

For example, if you wanted to save all errors for messages tagged with the
"local0" facility, you could create the file `/etc/socklog.rules/local0-error`
Expand Down Expand Up @@ -79,7 +80,15 @@ Create a script in `/etc/cont-init.d` to make your needed logging folder,
if it's a subfolder of `/var/log/socklog`, you should be covered. If not,
you'll likely need to chown it as well, to the `nobody` user.

Ideas I'd like to flesh out:
### Environment variables

* `SOCKLOG_TIMESTAMP_FORMAT` - controls how (or if) a timestamp should be placed
before every line, defaults to `T`
* (empty) - do not insert timestamps into logs
* `T` - prepend every line with an ISO 8601 timestamp
* `t` - prepend every line with a TAI64N timestamp

## Ideas I'd like to flesh out:

* Setting an environment variable to specify number of files, size, etc
* Right now this is just using the `s6-log` defaults - 10 files, ~100k per file
Expand Down
22 changes: 22 additions & 0 deletions overlay-rootfs/etc/cont-init.d/~-socklog
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#!/usr/bin/execlineb

backtick -D "T" -n SOCKLOG_TIMESTAMP_FORMAT { printcontenv SOCKLOG_TIMESTAMP_FORMAT }
importas -u SOCKLOG_TIMESTAMP_FORMAT SOCKLOG_TIMESTAMP_FORMAT

# make sure SOCKLOG_TIMESTAMP_FORMAT is acceptable
if
{
ifelse { s6-test -n "${SOCKLOG_TIMESTAMP_FORMAT}" }
{
ifelse { s6-test "${SOCKLOG_TIMESTAMP_FORMAT}" != "T" }
{
ifelse { s6-test "${SOCKLOG_TIMESTAMP_FORMAT}" != "t" }
{
redirfd -wb 1 /var/run/s6/container_environment/SOCKLOG_TIMESTAMP_FORMAT
s6-echo -n -- T
}
exit 0
}
exit 0
}
exit 0
}

if { s6-mkdir -p -m 0750 /var/log/socklog/cron }
if { s6-mkdir -p -m 0750 /var/log/socklog/daemon }
if { s6-mkdir -p -m 0750 /var/log/socklog/debug }
Expand Down
6 changes: 5 additions & 1 deletion overlay-rootfs/etc/services.d/socklog/log/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/execlineb -P

backtick -D "T" -n SOCKLOG_TIMESTAMP_FORMAT { printcontenv SOCKLOG_TIMESTAMP_FORMAT }

backtick -i -n LOGGING_SCRIPT
{
pipeline { pipeline { s6-ls -0 -- /etc/socklog.rules } s6-sort -0 }
Expand All @@ -11,7 +13,9 @@ backtick -i -n LOGGING_SCRIPT
} s6-echo
}

importas -C -u -s LOGGING_SCRIPT LOGGING_SCRIPT
importas -C -u -s -d"\r\n" LOGGING_SCRIPT LOGGING_SCRIPT
importas -C -u -s -d"\r\n" SOCKLOG_TIMESTAMP_FORMAT SOCKLOG_TIMESTAMP_FORMAT

s6-setuidgid nobody
s6-log -bp $LOGGING_SCRIPT

2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-cron
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-
+^cron\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/cron
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-daemon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-
+^daemon\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/daemon
1 change: 1 addition & 0 deletions overlay-rootfs/etc/socklog.rules/~-debug
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-
+^\.debug:
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/debug
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-errors
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
+\.emerg:
+\.alert:
+\.crit:
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/errors
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-everything
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+
-auth\.
-authpriv\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/everything
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-kernel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-
+^kern\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/kernel
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-mail
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-
+^mail\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/mail
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-messages
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
-^mail\.
-^news\.
-^cron\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/messages
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-secure
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-
+^auth\.
+^authpriv\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/secure
2 changes: 1 addition & 1 deletion overlay-rootfs/etc/socklog.rules/~-user
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-
+^user\.
T
${SOCKLOG_TIMESTAMP_FORMAT}
/var/log/socklog/user

0 comments on commit 45fe7f6

Please sign in to comment.