def init_notifier(self):
		# TODO: only do this, when it is really importet
		# import umcp; del sys.modules['notifier']; import module; sys.modules.get('notifier')
		# (but what if the importet module relies on notifier on import time?) → doesn't occur
		# TODO: break API: remove notifier

		# MUST be called after initializing the deamon
		implementation = self.options.notifier.lower()
		types = dict(
			qt=notifier.QT,
			generic=notifier.TWISTED
		)

		if implementation == 'qt':
			import PyQt4.Qt as qt
			qt.QCoreApplication(sys.argv)

		notifier.init(types[implementation])

		# disable notifier logging
		nflog.instance.handlers = []
		# to activate notifier logging
		nflog.set_level(nflog.DEBUG)
		nflog.open()
Ejemplo n.º 2
0
if __name__ == '__main__':
	# use default handlers
	print '>>> default handlers'
	# nflog.open() -> the default handlers are opened during import
	for level in ( nflog.CRITICAL, nflog.ERROR, nflog.WARN, nflog.INFO, nflog.DEBUG ):
		nflog.set_level( level )
		print 'LEVEL: %d' % level
		nflog.critical( 'critical' )
		nflog.error( 'error' )
		nflog.warn( 'warn' )
		nflog.info( 'info' )
		nflog.debug( 'debug' )

	# use custom handlers
	print '>>> custom handlers'
	handler = logging.FileHandler( 'test.log' )
	handler.setFormatter( nflog.formatter )
	nflog.open( handler )
	for level in ( nflog.CRITICAL, nflog.ERROR, nflog.WARN, nflog.INFO, nflog.DEBUG ):
		nflog.set_level( level )
		nflog.critical( 'LEVEL: %d' % level )
		nflog.critical( 'critical' )
		nflog.error( 'error' )
		nflog.warn( 'warn' )
		nflog.info( 'info' )
		nflog.debug( 'debug' )
	for line in open( 'test.log' ).readlines():
		print line,
	os.unlink( 'test.log' )
Ejemplo n.º 3
0
    # use default handlers
    print '>>> default handlers'
    # nflog.open() -> the default handlers are opened during import
    for level in (nflog.CRITICAL, nflog.ERROR, nflog.WARN, nflog.INFO,
                  nflog.DEBUG):
        nflog.set_level(level)
        print 'LEVEL: %d' % level
        nflog.critical('critical')
        nflog.error('error')
        nflog.warn('warn')
        nflog.info('info')
        nflog.debug('debug')

    # use custom handlers
    print '>>> custom handlers'
    handler = logging.FileHandler('test.log')
    handler.setFormatter(nflog.formatter)
    nflog.open(handler)
    for level in (nflog.CRITICAL, nflog.ERROR, nflog.WARN, nflog.INFO,
                  nflog.DEBUG):
        nflog.set_level(level)
        nflog.critical('LEVEL: %d' % level)
        nflog.critical('critical')
        nflog.error('error')
        nflog.warn('warn')
        nflog.info('info')
        nflog.debug('debug')
    for line in open('test.log').readlines():
        print line,
    os.unlink('test.log')