Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug1572749 filter macos logs: worker or >error #125

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/fluentd/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
}

service { 'td-agent':
require => File['/Library/LaunchDaemons/td-agent.plist'],
ensure => running,
enable => true,
require => File['/Library/LaunchDaemons/td-agent.plist'],
}

}
Expand Down
33 changes: 20 additions & 13 deletions modules/fluentd/templates/fluentd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
@type exec
command "\
log stream --color none --level <%= @mac_log_level %> --type log \
--predicate '(process MATCHES \"(logger|sudo|generic-worker)\") || (messageType > 2)' \
--timeout 1d \
| tail -n +3 \
"
# messageTypes 0:Default 1:Info 2:Debug ?:Error
# tail to omit first 2 lines that cause parsing to fail:
# Filtering the log data using "type == 1024"
# Timestamp Thread Type Activity PID TTL
Expand All @@ -29,31 +31,33 @@
@type record_transformer
enable_ruby true
<record>
<% if @syslog_host =~ /papertrail/ %>
<% if @syslog_host =~ /papertrail/ -%>
hostname "#{Socket.gethostname}"
<% end %>
<% end -%>
# Logging pid can be enabled:
# message pid:${record["pid"]} ${record["message"]}
# MacOS Unified logging levels: Fault, Error, Default, Info, Debug
<% if @syslog_host != '' %>
<% if @syslog_host != '' -%>
# syslog severities:
# https://github.com/eric/syslog_protocol/blob/master/lib/syslog_protocol/common.rb#L58
syslog_severity #{record["severity"].gsub(/^(Info|Default|Error|Fault)/i, 'Info' => 'info', 'Default' => 'warn', 'Error' => 'err', 'Fault' => 'crit')}
<% end %>
<% if @stackdriver_clientid != '' %>
<% end -%>
<% if @stackdriver_clientid != '' -%>
message ${record["program"]}: ${record['log_message']}
# stackdriver severities:
# https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
stackdriver_severity #{record["severity"].gsub(/^(Info|Default|Error|Fault)/i, 'Info' => 'info', 'Default' => 'warning', 'Error' => 'error', 'Fault' => 'critical')}
<% end %>
<% end -%>
</record>
</filter>

<% if @stackdriver_clientid != '' -%>
# Add a unique insertId to each log entry that doesn't already have it.
# This helps guarantee the order and prevent log duplication.
<filter system>
@type add_insert_ids
</filter>
<% end -%>

# string/numbers only
# msgpack cannot encode ruby Time fields
Expand All @@ -72,20 +76,23 @@
<record>
workerGroup "#{Socket.gethostname.split('.')[3]}"
</record>
<% if @stackdriver_clientid != '' -%>
<record>
severity #{record["stackdriver_severity"]}
</record>
<% end -%>
</filter>

<match system>
@type copy
<% if @syslog_host =~ /papertrail/ %>

<% if @syslog_host =~ /papertrail/ -%>
<store>
@type papertrail
papertrail_host <%= @syslog_host %>
papertrail_port <%= @syslog_port %>
</store>
<% elsif @syslog_host != '' %>
<% elsif @syslog_host != '' -%>
<store>
@type remote_syslog
hostname "#{Socket.gethostname}"
Expand All @@ -100,11 +107,11 @@
message_key log_message
</format>
</store>
<% else %>
<% else -%>
# Disabled syslog output. (syslog_host: <%= @syslog_host %>)
<% end %>
<% end -%>

<% if @stackdriver_clientid != '' %>
<% if @stackdriver_clientid != '' -%>
<store>
@type google_cloud
use_metadata_service false
Expand Down Expand Up @@ -136,7 +143,7 @@
# valid ones and drop the invalid ones instead of dropping everything.
partial_success true
</store>
<% else %>
<% else -%>
# Disabled stackdriver output. (clientid: <%= @stackdriver_clientid %>)
<% end %>
<% end -%>
</match>