Sending logback logs to graylog log server - how to add a dependency

522 views
Skip to first unread message

Ernout

unread,
May 17, 2014, 4:27:42 PM5/17/14
to ope...@googlegroups.com
Hi there!
I would like to have all logback logs from openhab to be transported to a Graylog2 logserver (http://graylog2.org/)
Then I can be alerted on errors and can analyze the logs better. Since there is a lot going on, going through the files with a log viewer is not practical.
I've found just the module to do that:
https://github.com/Moocar/logback-gelf
With this module you should be able to add a new appender in the logback configuration:

    <appender name="GELF" class="me.moocar.logbackgelf.GelfAppender">

And with this all logs can be sent to the logserver for analysis.
So far I have been unsuccessful in adding this dependency to openhab, and I keep getting class not found exceptions.

I've tried the following:
- added the new jar to the addons directory and the lib directory of openhab
- converted the jar into a plugin with eclipse. then i've downloaded openhab source and added the plugin as a dependency within the org.openhab.dependencies feature. But with the new plugin as a dependency, it cannot find the new plugin when I do a maven clean install on openhab. I think I might need to add it to a repository for it to be found?
Can anybody point me in the direction of how I can best add this dependency to the core so that logback can access it?
I'm both interested in a quick&dirty solution, or a solution where I can create a pull request and see if others might benefit from having a logserver with openhab as well.
Thanks in advance!

Ernout

unread,
May 21, 2014, 7:43:48 AM5/21/14
to ope...@googlegroups.com
Ok, got it to work by using 

Fragment-Host: ch.qos.logback.classic

In the manifest file.

Best!
Ernout

Op zaterdag 17 mei 2014 22:27:42 UTC+2 schreef Ernout:

Ben Jones

unread,
May 21, 2014, 4:05:15 PM5/21/14
to ope...@googlegroups.com
Hi Ernout,

Good news!

Could you explain the steps you took? Did you have to rebuild openHAB with the core manifest file updated? Which bundle exactly?

Cheers,
Ben

Jan-Piet Mens

unread,
May 21, 2014, 4:18:06 PM5/21/14
to ope...@googlegroups.com
> Could you explain the steps you took? Did you have to rebuild openHAB with
> the core manifest file updated? Which bundle exactly?

Yes please! (I'm familiar enough with Graylog2 but not with the
intricacies of getting openHAB configured as you did.)

-JP

Ernout

unread,
May 22, 2014, 4:10:58 PM5/22/14
to ope...@googlegroups.com
Steps I took:
- checkout of OpenHab source
- added a new plugin with the moocar logback to gelf classes in there. I've put the plugin in bundles/library. 
- added dependencies for google gson to the pom file - I had to add another repository that contained this plugin as well - it was not in the maven repo's used by openhab by default afaik.
- made the new plugin part of the build of openhab by adding it to the pom.xml in the library folder
- added the plugin as a dependency in the openhab dependencies feature's feature.xml
- added the plugin in openhab target (not sure if this is necessary)
- added the plugin to openhab runtime launch file
- adjusted the logback config file in the configuration folder as suggested in https://github.com/Moocar/logback-gelf

I've basically looked up where the logback plugins were listed and have added the gelf plugin there as well - thought it would be in the same classloader/context that way. But only when I added the Fragment-Host: ch.qos.logback.classic to the manifest of the plugin it was in the right context so logback could see it. 

I've added the diff of the files I've adjusted based on openhab 1.5. If you find out which steps can be omitted that would be interesting to know!
Maybe not all of these steps are necessary - haven't tried it with a clean install, and it was a bit of a journey.

Pretty nice when its all working - bit better insight into when things are going wrong! Do have to find a way to apply this into new versions easier. Or clean it up so it can be contributed back to master.

Best!

Ernout

Op zaterdag 17 mei 2014 22:27:42 UTC+2 schreef Ernout:
Hi there!
patchgelf.txt
Reply all
Reply to author
Forward
0 new messages