各种feature的实现
  1. 执行shell
  2. 处理时间
  3. 处理参数
  4. 处理文件
  5. logging
  6. test
  7. 多线程、进程,并发 
语言
  1. python
  2. groovy
  3. scala
  4. java
  5. C++
  6. C
  7. shell
  8. go

执行shell, check output

  1. groovy
    1. a= "ls".execute(); println a.text
  2. scala
    1. import sys.process._; “ls”.!!
  3. Java
  4. python
    1. import subprocess; a = subprocess.check_output("ls /tmp", shell=True); print(a)
  5. C++

处理时间

  1. java/scaca 
  2. python

 

处理参数

  1. python
    1. argparse
  2. scala
    1. scallop
    2. scopt 
    3. Argparse4j
  3. java
    1. Argparse4J
    2. JewlCli    

文件

  1. scala:
    1. import java.io._ ; val writer = new PrintWriter(new File("test.txt)); writer.write("hello world"); writer.close)
    2. import scala.io.Surce; Source.fromFile("test.txt").foreach{println}

logging

  1. python (RotateFile and Console)
    1. handler_Console = logging.StreamHandler()
      handler_Console.setFormatter(formatter)
      handler_Console.setLevel(logging.DEBUG)

      base_dir = os.path.dirname(os.path.abspath(__file__))
      log_path = os.path.join(base_dir, log_file_name)
      handler_F = RotatingFileHandler(log_path, maxBytes=200*1024, backupCount=5)
      handler_F.setFormatter(formatter)
      handler_F.setLevel(logging.INFO)

      logger = logging.getLogger(logger_name)
      logger.addHandler(handler_Console)
      logger.addHandler(handler_F)
      logger.setLevel(logging.DEBUG)

  2. scala or java
    1. SLF4J, Log4j, Log4j2 (使用SLF4J and Logback,  log4j vs logback vs log4j2)
    2. import org.apache.log4j.Logger;
      import org.apache.log4j.PropertyConfigurator;

      static Logger logger = Logger.getLogger(this.getClass)
      PropertyConfigurator.configure("log4j.properties");
    3. log4j.properites

      # Root logger
      log4j.rootLogger=INFO, console, file

      log4j.appender.console=org.apache.log4j.ConsoleAppender
      log4j.appender.console.Target=System.out
      log4j.appender.console.layout=org.apache.log4j.PatternLayout
      log4j.appender.consoleAppender.layout.ConversionPattern=[%t] %-5p %c %x - %m%n


      # Direct log messages to a log file
      log4j.appender.file=org.apache.log4j.RollingFileAppender

      log4j.appender.file.File=C:\\temp\info.log
      log4j.appender.file.MaxFileSize=10MB
      log4j.appender.file.MaxBackupIndex=10
      log4j.appender.file.layout=org.apache.log4j.PatternLayout
      log4j.appender.file.layout.ConversionPattern=[%t] %-5p %c %x - %m%n

Posted on 2021-02-02 15:00  bob.dong  阅读(467)  评论(0编辑  收藏  举报