/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j;
import org.apache.log4j.spi.LoggingEvent;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.Locale;
/**
* This class provides parameterized logging services
* using the pattern syntax of java.text.MessageFormat.
* Message formatting is only performed when the
* request exceeds the threshold level of the logger.
* When the pattern only contains literal text and
* default conversion patterns (that is "{0}" and similar)
* a simple fast compatible formatter is used.
* If the pattern contains more complex conversion patterns,
* formatting will be delegated to java.text.MessageFormatter
* which can be substantially slower.
*
* @see org.apache.log4j.LogSF
* @since 1.2.16
*
*/
public final class LogMF extends LogXF {
/**
* private constructor.
*
*/
private LogMF() {
}
/**
* Number format.
*/
private static NumberFormat numberFormat = null;
/**
* Locale at time of last number format request.
*/
private static Locale numberLocale = null;
/**
* Date format.
*/
private static DateFormat dateFormat = null;
/**
* Locale at time of last date format request.
*/
private static Locale dateLocale = null;
/**
* Format number.
* @param n number to format, may not be null.
* @return formatted value.
*/
private static synchronized String formatNumber(final Object n) {
Locale currentLocale = Locale.getDefault();
if (currentLocale != numberLocale || numberFormat == null) {
numberLocale = currentLocale;
numberFormat = NumberFormat.getInstance(currentLocale);
}
return numberFormat.format(n);
}
/**
* Format date.
* @param d date, may not be null.
* @return formatted value.
*/
private static synchronized String formatDate(final Object d) {
Locale currentLocale = Locale.getDefault();
if (currentLocale != dateLocale || dateFormat == null) {
dateLocale = currentLocale;
dateFormat = DateFormat.getDateTimeInstance(
DateFormat.SHORT,
DateFormat.SHORT,
currentLocale);
}
return dateFormat.format(d);
}
/**
* Format a single parameter like a "{0}" formatting specifier.
*
* @param arg0 parameter, may be null.
* @return string representation of arg0.
*/
private static String formatObject(final Object arg0) {
if (arg0 instanceof String) {
return arg0.toString();
} else if (arg0 instanceof Double ||
arg0 instanceof Float) {
return formatNumber(arg0);
} else if (arg0 instanceof Date) {
return formatDate(arg0);
}
return String.valueOf(arg0);
}
/**
* Determines if pattern contains only {n} format elements
* and not apostrophes.
*
* @param pattern pattern, may not be null.
* @return true if pattern only contains {n} format elements.
*/
private static boolean isSimple(final String pattern) {
if (pattern.indexOf('\'') != -1) {
return false;
}
for(int pos = pattern.indexOf('{');
pos != -1;
pos = pattern.indexOf('{', pos + 1)) {
if (pos + 2 >= pattern.length() ||
pattern.charAt(pos+2) != '}' ||
pattern.charAt(pos+1) < '0' ||
pattern.charAt(pos+1) > '9') {
return false;
}
}
return true;
}
/**
* Formats arguments using MessageFormat.
* @param pattern pattern, may be malformed or null.
* @param arguments arguments, may be null or mismatched.
* @return Message string or null
*/
private static String format(final String pattern,
final Object[] arguments) {
if (pattern == null) {
return null;
} else if(isSimple(pattern)) {
String formatted[] = new String[10];
int prev = 0;
String retval = "";
int pos = pattern.indexOf('{');
while(pos >= 0) {
if(pos + 2 < pattern.length() &&
pattern.charAt(pos+2) == '}' &&
pattern.charAt(pos+1) >= '0' &&
pattern.charAt(pos+1) <= '9') {
int index = pattern.charAt(pos+1) - '0';
retval += pattern.substring(prev, pos);
if (formatted[index] == null) {
if (arguments == null || index >= arguments.length) {
formatted[index] = pattern.substring(pos, pos+3);
} else {
formatted[index] = formatObject(arguments[index]);
}
}
retval += formatted[index];
prev = pos + 3;
pos = pattern.indexOf('{', prev);
} else {
pos = pattern.indexOf('{', pos + 1);
}
}
retval += pattern.substring(prev);
return retval;
}
try {
return MessageFormat.format(pattern, arguments);
} catch (IllegalArgumentException ex) {
return pattern;
}
}
/**
* Formats a single argument using MessageFormat.
* @param pattern pattern, may be malformed or null.
* @param arguments arguments, may be null or mismatched.
* @return Message string or null
*/
private static String format(final String pattern,
final Object arg0) {
if (pattern == null) {
return null;
} else if(isSimple(pattern)) {
String formatted = null;
int prev = 0;
String retval = "";
int pos = pattern.indexOf('{');
while(pos >= 0) {
if(pos + 2 < pattern.length() &&
pattern.charAt(pos+2) == '}' &&
pattern.charAt(pos+1) >= '0' &&
pattern.charAt(pos+1) <= '9') {
int index = pattern.charAt(pos+1) - '0';
retval += pattern.substring(prev, pos);
if (index != 0) {
retval += pattern.substring(pos, pos+3);
} else {
if (formatted == null) {
formatted = formatObject(arg0);
}
retval += formatted;
}
prev = pos + 3;
pos = pattern.indexOf('{', prev);
} else {
pos = pattern.indexOf('{', pos + 1);
}
}
retval += pattern.substring(prev);
return retval;
}
try {
return MessageFor
没有合适的资源?快使用搜索试试~ 我知道了~
apache-log4j-1.2.17
共1610个文件
html:913个
java:363个
xml:92个
需积分: 32 21 下载量 51 浏览量
2018-09-28
17:12:33
上传
评论
收藏 4.57MB ZIP 举报
温馨提示
apache-log4j-1.2.17解决导入问题,日志输出的问题,import
资源推荐
资源详情
资源评论
收起资源包目录
apache-log4j-1.2.17 (1610个子文件)
xmlLayout.1 5KB
dom.A1.1 4KB
patternLayout.1 4KB
dom.A2.1 3KB
enhancedPatternLayout.1 3KB
socketServer.1 2KB
customLogger.1 941B
xmlLayout.mdc.1 296B
customLevel.1 210B
patternLayout.mdc.1 44B
enhancedPatternLayout.mdc.1 44B
hierarchyThreshold.1 0B
patternLayout.10 6KB
enhancedPatternLayout.10 4KB
patternLayout.11 5KB
enhancedPatternLayout.11 3KB
patternLayout.12 6KB
enhancedPatternLayout.12 4KB
patternLayout.13 6KB
enhancedPatternLayout.13 4KB
patternLayout.14 4KB
enhancedPatternLayout.14 3KB
enhancedPatternLayout.15 3KB
xmlLayout.2 7KB
patternLayout.2 5KB
enhancedPatternLayout.2 3KB
socketServer.2 2KB
enhancedPatternLayout.mdc.2 483B
xmlLayout.mdc.2 356B
customLevel.2 210B
hierarchyThreshold.2 51B
customLogger.2 47B
patternLayout.3 5KB
enhancedPatternLayout.3 3KB
socketServer.3 2KB
xmlLayout.3 720B
hierarchyThreshold.3 102B
customLevel.3 42B
patternLayout.4 5KB
dom.A1.4 4KB
enhancedPatternLayout.4 3KB
dom.A2.4 3KB
socketServer.4 2KB
customLevel.4 210B
hierarchyThreshold.4 152B
patternLayout.5 5KB
enhancedPatternLayout.5 3KB
socketServer.5 2KB
hierarchyThreshold.5 202B
patternLayout.6 5KB
enhancedPatternLayout.6 3KB
socketServer.6 2KB
hierarchyThreshold.6 253B
patternLayout.7 5KB
enhancedPatternLayout.7 3KB
socketServer.7 2KB
hierarchyThreshold.7 304B
patternLayout.8 5KB
enhancedPatternLayout.8 3KB
socketServer.8 2KB
hierarchyThreshold.8 304B
patternLayout.9 5KB
enhancedPatternLayout.9 3KB
publications.apt 4KB
index.apt 4KB
download.apt 3KB
roadmap.apt 1KB
mycat.bad 1KB
run-tests.bat 7KB
exception.bin 2KB
mdc.bin 508B
location.bin 465B
ndc.bin 409B
simple.bin 399B
MSG00001.bin 164B
info.bin 60B
patternLayout.mdc.clear 67B
CONTENTS 3KB
nteventlog.cpp 10KB
maven-base.css 3KB
maven-base.css 3KB
maven-theme.css 3KB
stylesheet.css 2KB
stylesheet.css 2KB
stylesheet.css 1KB
site.css 775B
site.css 775B
NTEventLogAppender.def 912B
NTEventLogAppender.amd64.dll 45KB
NTEventLogAppender.dll 10KB
log4j.dtd 7KB
log4j.dtd 7KB
log4j.dtd 7KB
fallback1 3KB
faq.fml 35KB
od.gif 6KB
od.gif 6KB
lf5_small_icon.gif 1KB
icon_help_sml.gif 1019B
icon_error_sml.gif 1010B
共 1610 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
qq_33728318
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 高分课程设计作业-基于QT的模仿宝石迷阵游戏C++源码+文档说明+界面截图
- 基于Apache Spark的Spark DistCP重实现设计源码
- 粤港澳大湾区(黄埔)算法算例大赛-工业表面缺陷检测源码+超详细注释
- 在 KolektorSDD 数据上使用分割决策网络进行表面缺陷检测python源码+文档说明
- 操作系统作业:时间片轮转算法的模拟实现C++源码+文档说明
- 基于改进yolov5的金属曲面缺陷检测,使用pyqt5实习了实时视频检测的功能python源码+文档说明
- 基于Qt及OpenCv设计了一个视觉检测系统,实现了米粒的计数、缺陷分析功能+源码+文档说明+效果图
- 基于STM32F1和TB6612芯片的电机驱动板,可以驱动两个电机正反转,具有比L298N更小的体积源码+文档说明
- 基于Javascript的CNN卷积交互式播放器设计源码
- 基于Layui的树表格(treeGrid)前端设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功