コード例 #1
0
ファイル: main.py プロジェクト: YYwlo/shaveet
def cli_start():
  setprocname("shaveet")
  parser = OptionParser()
  parser.add_option("-d", "--daemon", dest="daemon",help="run as daemon",action="store_true",default=False)
  parser.add_option("-p", "--port",dest="port",help="which port to listen",type="int",default=0)
  (options, args) = parser.parse_args()
  
  formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
  #setup handlers
  fh = logging.handlers.RotatingFileHandler(config.LOG_PATH,maxBytes = 1024 * 1024,backupCount=3)
  ch = logging.StreamHandler()
  #set formmaters
  fh.setFormatter(formatter)
  ch.setFormatter(formatter)
  logger_wsgi.setLevel(logging.INFO)
  logger.setLevel(logging.INFO)

  if options.daemon:
    with DaemonContext(files_preserve=range(maxfd() + 2)):      
      logger.addHandler(fh)
      logger_wsgi.addHandler(fh)
      logger.info("starting daemon..")
      main(options)
  else:
    logger.setLevel(logging.DEBUG)
    logger_wsgi.setLevel(logging.DEBUG)
    logger.addHandler(ch)
    logger_wsgi.addHandler(ch)
    main(options)
コード例 #2
0
def cli_start():
    setprocname("shaveet")
    parser = OptionParser()
    parser.add_option("-d",
                      "--daemon",
                      dest="daemon",
                      help="run as daemon",
                      action="store_true",
                      default=False)
    parser.add_option("-p",
                      "--port",
                      dest="port",
                      help="which port to listen",
                      type="int",
                      default=0)
    (options, args) = parser.parse_args()

    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
    #setup handlers
    fh = logging.handlers.RotatingFileHandler(config.LOG_PATH,
                                              maxBytes=1024 * 1024,
                                              backupCount=3)
    ch = logging.StreamHandler()
    #set formmaters
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    logger_wsgi.setLevel(logging.INFO)
    logger.setLevel(logging.INFO)

    if options.daemon:
        with DaemonContext(files_preserve=range(maxfd() + 2)):
            logger.addHandler(fh)
            logger_wsgi.addHandler(fh)
            logger.info("starting daemon..")
            main(options)
    else:
        logger.setLevel(logging.DEBUG)
        logger_wsgi.setLevel(logging.DEBUG)
        logger.addHandler(ch)
        logger_wsgi.addHandler(ch)
        main(options)
コード例 #3
0
    server.stop()

if __name__ == "__main__":
  setprocname("shaveet")
  parser = OptionParser()
  parser.add_option("-d", "--daemon", dest="daemon",help="ruan as daemon",action="store_true",default=False)
  (options, args) = parser.parse_args()
  
  formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
  #setup handlers
  fh = logging.handlers.RotatingFileHandler(config.LOG_PATH,maxBytes = 1024 * 1024,backupCount=3)
  ch = logging.StreamHandler()
  #set formmaters
  fh.setFormatter(formatter)
  ch.setFormatter(formatter)
  logger_wsgi.setLevel(logging.INFO)
  logger.setLevel(logging.INFO)

  if options.daemon:
    with DaemonContext(files_preserve=range(maxfd() + 2)):      
      logger.addHandler(fh)
      logger_wsgi.addHandler(fh)
      logger.info("starting daemon..")
      main(options)
  else:
    logger.setLevel(logging.DEBUG)
    logger_wsgi.setLevel(logging.DEBUG)
    logger.addHandler(ch)
    logger_wsgi.addHandler(ch)
    main(options)