# Copyright 2015 Canonical Ltd.
#
# This file is part of the PostgreSQL Charm for Juju.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import glob
import os.path
from charmhelpers import context
from charmhelpers.core import hookenv, host, templating
from decorators import data_ready_action, relation_handler
from charms import reactive
@when('syslog.available')
def configure_syslog(rel):
programname = hookenv.local_unit().replace('/', '_')
rel.configure(programname=programname)
extend_syslog(rel.conversation())
@when('postgresql.cluster.configured')
def reconfigure_syslog():
rel = SyslogProvides.from_name('syslog')
if not rel:
return
for conv in rel.conversations():
extend_syslog(conv)
def extend_syslog(conv):
'''Add extra relation settings, extending the basic syslog interface.
Adds programname and log_line_prefix, required for consumers such
as pgBadger to be able to decode the logs.
'''
store = unitdata.kv()
log_line_prefix_key = 'postgresql.cluster.pgconf.current.log_line_prefix'
conv.set_remote('log_line_prefix', store.get(log_line_prefix_key))
conv.set_remote('programname', hookenv.local_unit().replace('/', '_'))