reorg as a library and use common.logging