Tomcat源码分析(六)--日志记录器和国际化
日志记录器挺简单的,没有很多东西,最主要的就是一个Logger接口:
public String getString(String key) { if (key == null) { String msg = "key is null"; throw new NullPointerException(msg); } String str = null; try { str = bundle.getString(key); } catch (MissingResourceException mre) { str = "Cannot find message associated with key '" + key + "'"; } return str; }重点是budle.getString(key),这句代码能拿到LocalStrings.properties文件的key属性(这里是fileLogger.alreadyStarted)的值,即File Logger has already been started。这样我们便能定义多个属性文件,一个表示英文,一个表示汉语,一个属性文件表示一个语言,就能实现应用的国际化了。