tinylog-org / tinylog

@@ -0,0 +1,71 @@
Loading
1 +
/*
2 +
 * Copyright 2021 Victor Kropp
3 +
 *
4 +
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 +
 * the License. You may obtain a copy of the License at
6 +
 *
7 +
 * http://www.apache.org/licenses/LICENSE-2.0
8 +
 *
9 +
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 +
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 +
 * specific language governing permissions and limitations under the License.
12 +
 */
13 +
14 +
package org.tinylog.pattern;
15 +
16 +
import java.sql.PreparedStatement;
17 +
import java.sql.SQLException;
18 +
import java.util.Collection;
19 +
20 +
import org.tinylog.core.LogEntry;
21 +
import org.tinylog.core.LogEntryValue;
22 +
23 +
/**
24 +
 * Decorator token for ensuring both minimum and maximum size. If the output of the underlying token is shorter
25 +
 * or longer than the defined size, start of the token will be trimmed or padded with spaces at the end.
26 +
 */
27 +
class SizeToken implements Token {
28 +
29 +
	private final Token token;
30 +
	private final int size;
31 +
32 +
	/**
33 +
	 * @param token
34 +
	 *            Base token
35 +
	 * @param size
36 +
	 *            Maximum size for output
37 +
	 */
38 +
	SizeToken(final Token token, final int size) {
39 +
		this.token = token;
40 +
		this.size = size;
41 +
	}
42 +
43 +
	@Override
44 +
	public Collection<LogEntryValue> getRequiredLogEntryValues() {
45 +
		return token.getRequiredLogEntryValues();
46 +
	}
47 +
48 +
	@Override
49 +
	public void render(final LogEntry logEntry, final StringBuilder builder) {
50 +
		int offset = builder.length();
51 +
		token.render(logEntry, builder);
52 +
		int size = builder.length() - offset;
53 +
54 +
		if (size > this.size) {
55 +
			builder.delete(offset, offset + size - this.size);
56 +
		}
57 +
		if (size < this.size) {
58 +
			for (int i = 0; i < this.size - size; ++i) {
59 +
				builder.append(' ');
60 +
			}
61 +
		}
62 +
	}
63 +
	
64 +
	@Override
65 +
	public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException {
66 +
		StringBuilder builder = new StringBuilder();
67 +
		render(logEntry, builder);
68 +
		statement.setString(index, builder.toString());
69 +
	}
70 +
71 +
}

@@ -254,6 +254,10 @@
Loading
254 254
255 255
				if ("min-size".equals(key)) {
256 256
					styledToken = new MinimumSizeToken(styledToken, number);
257 +
				} else if ("max-size".equals(key)) {
258 +
					styledToken = new MaximumSizeToken(styledToken, number);
259 +
				} else if ("size".equals(key)) {
260 +
					styledToken = new SizeToken(styledToken, number);
257 261
				} else if ("indent".equals(key)) {
258 262
					styledToken = new IndentationToken(styledToken, number);
259 263
				} else {

@@ -0,0 +1,66 @@
Loading
1 +
/*
2 +
 * Copyright 2021 Victor Kropp
3 +
 *
4 +
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 +
 * the License. You may obtain a copy of the License at
6 +
 *
7 +
 * http://www.apache.org/licenses/LICENSE-2.0
8 +
 *
9 +
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 +
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 +
 * specific language governing permissions and limitations under the License.
12 +
 */
13 +
14 +
package org.tinylog.pattern;
15 +
16 +
import java.sql.PreparedStatement;
17 +
import java.sql.SQLException;
18 +
import java.util.Collection;
19 +
20 +
import org.tinylog.core.LogEntry;
21 +
import org.tinylog.core.LogEntryValue;
22 +
23 +
/**
24 +
 * Decorator token for ensuring a maximum size. If the output of the underlying token is longer than the defined
25 +
 * maximum size, start of the token will be trimmed.
26 +
 */
27 +
class MaximumSizeToken implements Token {
28 +
29 +
	private final Token token;
30 +
	private final int maximumSize;
31 +
32 +
	/**
33 +
	 * @param token
34 +
	 *            Base token
35 +
	 * @param size
36 +
	 *            Maximum size for output
37 +
	 */
38 +
	MaximumSizeToken(final Token token, final int size) {
39 +
		this.token = token;
40 +
		this.maximumSize = size;
41 +
	}
42 +
43 +
	@Override
44 +
	public Collection<LogEntryValue> getRequiredLogEntryValues() {
45 +
		return token.getRequiredLogEntryValues();
46 +
	}
47 +
48 +
	@Override
49 +
	public void render(final LogEntry logEntry, final StringBuilder builder) {
50 +
		int offset = builder.length();
51 +
		token.render(logEntry, builder);
52 +
		int size = builder.length() - offset;
53 +
54 +
		if (size > maximumSize) {
55 +
			builder.delete(offset, offset + size - maximumSize);
56 +
		}
57 +
	}
58 +
	
59 +
	@Override
60 +
	public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException {
61 +
		StringBuilder builder = new StringBuilder();
62 +
		render(logEntry, builder);
63 +
		statement.setString(index, builder.toString());
64 +
	}
65 +
66 +
}
Files Complexity Coverage
jboss-tinylog/src/main/java/org/tinylog/jboss 98.47% 98.84%
jcl-tinylog/src/main/java/org/tinylog/jcl 88.52% 89.55%
jul-tinylog/src/main/java/org/tinylog/jul 89.47% 91.18%
log4j1.2-api/src/main/java/org/apache/log4j 72.78% 70.50%
slf4j-tinylog/src/main/java/org 93.33% 94.96%
tinylog-api-kotlin/src/main/kotlin/org/tinylog/kotlin 96.08% 95.70%
tinylog-api-scala/src/main/scala/org/tinylog/scala 100.00% 90.00%
tinylog-api/src/main/java/org/tinylog 94.39% 94.07%
tinylog-impl/src/main/java/org/tinylog 94.06% 96.11%
tinylog-jboss/src/main/java/org/tinylog/adapter/jboss 89.66% 91.84%
tinylog1.3-api/src/main/java/org/pmw/tinylog 99.16% 98.91%
...ylog-jul/src/main/java/org/tinylog/adapter/jul/JavaUtilLoggingProvider.java 85.00% 88.24%
Project Totals (134 files) 93.52% 94.42%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading