Posts Tagged ‘logging’

Python & Scribe : Setting up logging to Scribe from Python

September 3, 2011

Instructions to setup Scribe in Ubuntu 10.04 and log messages from python.

Scribe is an opensource logging server developed by facebook. It is very robust and can scale across many machines. You can setup master/slave scribe configuration and forward all the logs to one place.

I am working on a python application that has to log messages to scribe. So here we go:

1. apt-get install libboost-filesystem1.40.0 (requirement)

2. Download & Install Thrift (pre-req for Scribe)

3. Download & install scribe.

4. Configure scribe. The default conf file location is /etc/scribe/scribe.conf.

– The port value is important to remember.

– The store section has details of where and how the logs are stored or sent. The primary section is tried first and if it fails for some reason, the logs are sent to secondary. So if you are making the scribe to forward logs to another server, you need to put that info in primary. But also use the local file system as a secondary in case of failure.

– If you are using a file to store logs, the location of the logs is given in file_path. Usually this points to /var/log/scribe/central.

– Most of the default values here  are pretty satisfactory, you would not need to change it.

5. Start scribe.

Start using scribed command. If you have a different config file use -c “filename”.

You can now try and send log statements to scribe using the scribecat command.

$ echo “test message to scribe” | scribecat -h 127.0.0.1:1463 server

Now you can see the /var/log/scribe/central/server/server_current file. The test message should be seen there.

6. Install Python modules for scribe.

There are 3 modules required.

– The thrift python module (This usually gets installed along with the thrift installation)

– The fb303 module. This has to be installed separately. This can be found inside the thrift/contrib/fb303/py. Build the fb303 package fully so that the py modules are built. Then $ python setup.py install inside /py folder.

– Finally scribe python modules need to be installed separately. Don’t use $ pip install scribe. This installs a different scribe module (One of my mistakes). You need to install scribe/lib/py module.

7. Test

Now you have the environment setup and running. Use python and try to “from scribe import scribe”. If successful you have installed all the required packages. Now go ahead and try the sample given here.

HTH