ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/juli/JdkLoggerFormatter.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/juli/JdkLoggerFormatter.java
Status
scanned
Type
file
Name
JdkLoggerFormatter.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3933 (3.8 KB)
MD5
49d0d9813b0bc6047c432533215a2e9b
SHA1
7e1f304ac87028a0985b9f1fdbe1d583e6aa1edb
SHA256
8c3ed8b6f7f33fc66d4e1b6ee1c9d904bbd3939234a94a7b369d93c676fe152b
SHA512

      
    
SHA1_git
3c353280f84191e9027adcd74ab14a2ffd077765
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
JdkLoggerFormatter.java | 3.8 KB |

/* * 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.juli; import java.util.logging.Formatter; import java.util.logging.LogRecord; /** * A more compact formatter. Equivalent log4j config: * * <pre> * log4j.rootCategory=WARN, A1 * log4j.appender.A1=org.apache.log4j.ConsoleAppender * log4j.appender.A1.layout=org.apache.log4j.PatternLayout * log4j.appender.A1.Target=System.err * log4j.appender.A1.layout.ConversionPattern=%r %-15.15c{2} %-1.1p %m %n * </pre> * * Example: 1130122891846 Http11BaseProtocol I Initializing Coyote HTTP/1.1 on http-8800 */ public class JdkLoggerFormatter extends Formatter { // values from JDK Level public static final int LOG_LEVEL_TRACE = 400; public static final int LOG_LEVEL_DEBUG = 500; public static final int LOG_LEVEL_INFO = 800; public static final int LOG_LEVEL_WARN = 900; public static final int LOG_LEVEL_ERROR = 1000; public static final int LOG_LEVEL_FATAL = 1000; @Override public String format(LogRecord record) { Throwable t = record.getThrown(); int level = record.getLevel().intValue(); String name = record.getLoggerName(); long time = record.getMillis(); String message = formatMessage(record); if (name.indexOf('.') >= 0) { name = name.substring(name.lastIndexOf('.') + 1); } // Use a string buffer for better performance StringBuilder buf = new StringBuilder(); buf.append(time); // pad to 8 to make it more readable buf.append(" ".repeat(Math.max(0, 8 - buf.length()))); // Append a readable representation of the log level. switch (level) { case LOG_LEVEL_TRACE: buf.append(" T "); break; case LOG_LEVEL_DEBUG: buf.append(" D "); break; case LOG_LEVEL_INFO: buf.append(" I "); break; case LOG_LEVEL_WARN: buf.append(" W "); break; case LOG_LEVEL_ERROR: buf.append(" E "); break; // case : buf.append(" F "); break; default: buf.append(" "); } // Append the name of the log instance if so configured buf.append(name); buf.append(' '); // pad to 20 chars buf.append(" ".repeat(Math.max(0, 8 - buf.length()))); // Append the message buf.append(LogUtil.escape(message)); // Append stack trace if not null if (t != null) { buf.append(System.lineSeparator()); java.io.StringWriter sw = new java.io.StringWriter(1024); java.io.PrintWriter pw = new java.io.PrintWriter(sw); t.printStackTrace(pw); pw.close(); buf.append(LogUtil.escape(sw.toString())); } buf.append(System.lineSeparator()); // Print to the appropriate destination return buf.toString(); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
25.93
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9