(continued from previous page) (continues on next page) 16 lvl=random.choice(levels) logger=logging.getLogger(random .choice(loggers)) logger.log(lvl, 'Message no. %d ', i) if __name__ =='__main__ ': q =Queue() d ={ 'version':1, 'formatters': { 'detailed': { 'class':'logging.Formatter ', 'format':' %(asctime)s %(name)-15s %(levelname)-8s %(processName)- ↪ → 10s%(message)s ' } }, 'handlers': { 'console': { 'class':'logging.StreamHandler ', 'level ':'INFO ', }, 'file': { 'class':'logging.FileHandler ', 'filename':'mplog.log ', 'mode':'w', 'formatter':'detailed', }, 'foofile': { 'class':'logging.FileHandler ', 'filename':'mplog-foo.log ', 'mode':'w', 'formatter':'detailed', }, 'errors': { 'class':'logging.FileHandler ', 'filename':'mplog-errors.log ', 'mode':'w', 'level ':'ERROR', 'formatter':'detailed', }, }, 'loggers': { 'foo': { 'handlers': ['foofile'] } }, 'root': { 'level ':'DEBUG', 'handlers': ['console','file','errors'] }, } workers =[] for i in range(5): wp =Process(target =worker_process, name ='worker %d '%(i +1), args = (q,)) workers.append(wp) wp.start() logging.config.dictConfig(d) lp=threading.Thread(target=logger_thread, args =(q,)) lp.start() # At this point, the main process could do some useful work of its own # Once it's done that, it can wait for the workers to terminate... for wp in workers: