Setting up logging for a PostgreSQL server using syslog on a Linux machine is intuitive especially with logging systems like syslog-ng, you just need to put the correct parameters at the right place.

First, you need to setup the system side, by adding the following settings in /etc/syslog-nd/syslog-nd.conf (or similar, don’t hesitate to customize that with your own paths).
destination postgres { file("/var/log/pgsql"); };
filter f_postgres { facility(local0); };
log { source(src); filter(f_postgres); destination(postgres); };

This will send all the logs of postgresql server to /var/log/pgsql. Be sure to combine that with some solution rotating log files to avoid a single file becoming too large… And reload syslog-ng with a command similar to that (varies depending on distribution used, here Archlinux).
systemctl reload syslog-ng

Then, you need to add those settings in postgresql.conf.
log_destination = 'syslog' # Can specify multiple destinations
syslog_facility='LOCAL0'
syslog_ident='postgres'

Based on the documentation, syslog_facility can be set from LOCAL0 to LOCAL7.
Don’t forget that you can also specify multiple log destinations. For example when using stderr and syslog at the same time, simply do that:
log_destination = 'stderr,syslog'

Finally, reload the parameters of server and you are done.
pg_ctl reload -D $PGDATA
Note that restarting the server is not necessary.

In GIT you may finish with a bunch of escape characters (ESC) when invocating colors for “git log” and “git diff”.
ESC[31m-{ESC[m
ESC[31m- Oid res = InvalidOid;ESC[m
ESC[31m- Relation rel;ESC[m
ESC[31m- StringInfo buf;ESC[m
ESC[31m- char *storageName = NULL;ESC[m
ESC[31m- int prefix = 0;ESC[m
ESC[31m-ESC[m

This is due to the default pager which is “less”, because it cannot interpret correctly the escape characters.
There are a couple of ways to avoid that.

The first one is to change the pager to “more”.
git config --global core.pager more

The second one is to append an additional command with “less -r”.
git diff --color | less -r
git log -p --color | less -r

And you get a nice colored output.

Here is another solution which is more portable to my mind, and it is the one I use.
git config --global core.pager "less -r"
This directly appends the modified less command when git pager is invocated to print correctly escape characters.

In library git-core, git has a command that makes all the commits appearing in graphs.
For example:
git log --graph --all

It is an other matter to make readable graphs. For that purpose, the following command is helpful to setup a special alias:
git config alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
This makes tags and branch names appear in green.

For a command without colors:
git config alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"

Then this command based on the alias above prints nice-looking graphs.
git graph

©2010-2013 Michael Paquier All content is ©Copyright of Otacoo.com 2010-2013. Privacy Policy - Terms of Use