- 执行shell
- 处理时间
- 处理参数
- 处理文件
- logging
- test
- 多线程、进程,并发
- python
- groovy
- scala
- java
- C++
- C
- shell
- go
执行shell, check output
- groovy
- a= "ls".execute(); println a.text
- scala
- import sys.process._; “ls”.!!
- Java
- python
- import subprocess; a = subprocess.check_output("ls /tmp", shell=True); print(a)
- C++
处理时间
- java/scaca
- python
处理参数
- python
- argparse
- scala
- scallop
- scopt
- Argparse4j
- java
- Argparse4J
- JewlCli
文件
- scala:
- import java.io._ ; val writer = new PrintWriter(new File("test.txt)); writer.write("hello world"); writer.close)
- import scala.io.Surce; Source.fromFile("test.txt").foreach{println}
logging
- python (RotateFile and Console)
-
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)
-
- scala or java
- SLF4J, Log4j, Log4j2 (使用SLF4J and Logback, log4j vs logback vs log4j2)
import
org.apache.log4j.Logger;
import
org.apache.log4j.PropertyConfigurator;
static Logger logger = Logger.getLogger(this.getClass)PropertyConfigurator.configure("log4j.properties");-
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:\tempinfo.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