我需要能够编写自己的分割字符串方法,以便输入像
String[] test1 = mySplit("ab#cd#efg#", "#");
System.out.println(Arrays.toString(test1));
Run Code Online (Sandbox Code Playgroud)
将打印[ab, #, cd, #, efg, #]到控制台.到目前为止,我已经让它像那样拆分但是我的方式留下了两个分隔符连续的尴尬空间,或者分隔符位于输入的开头.
public static String[] mySplit(String str, String regex)
{
String[] storeSplit = new String[str.length()];
char compare1, compare2;
int counter = 0;
//Initializes all the string[] values to "" so when the string
//and char concatonates, 'null' doesn't appear.
for(int i=0; i<str.length(); i++) {
storeSplit[i] = "";
}
//Puts the str values into the split array and concatonates until
//a delimiter is found, then it moves to …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置我的log4j记录器,以便Marker在过滤要记录的内容时使用多个.我不完全确定我是否在正确的轨道上,但基本上我想要的是能够根据许多不同的标记记录许多不同的事件.
假设我有三个标记MARKERONE,MARKERTWO和MARKERTHREE.这三个都是"顶级"标记,这意味着它们无法从其他标记中获取.
目前我有以下log4j.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app-%d{MM-dd-yyyy}.log.gz">
<MarkerFilter marker="MARKERONE" onMatch="ACCEPT" onMismatch="DENY"/>
<MarkerFilter marker="MARKERTWO" onMatch="ACCEPT" onMismatch="DENY"/>
<MarkerFilter marker="MARKERTHREE" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</PatternLayout>
<TimeBasedTriggeringPolicy />
</RollingFile>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
Run Code Online (Sandbox Code Playgroud)
这是基于log4j网站上的示例xml文件:http://logging.apache.org/log4j/2.x/manual/filters.html#MarkerFilter
但是,由于错误,这不起作用.然后我尝试用MarkerFilter以下内容替换这三个条目:
<Filters>
<MarkerFilter marker="MARKERONE" onMatch="ACCEPT" onMismatch="DENY"/>
<MarkerFilter marker="MARKERTWO" onMatch="ACCEPT" onMismatch="DENY"/>
<MarkerFilter marker="MARKERTHREE" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
Run Code Online (Sandbox Code Playgroud)
这允许我运行日志工具并实际记录内容,但是(!)我只能记录记录的事件MARKERONE.如果我更改了 …