Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for Apache Log4j 1.2.17
Apache Log4j
provides the interface that applications should code to and provides the adapter
components required for implementers to create a logging implementation.
Bytecode (Java 1.4) for Apache Log4j is provided in a JAR file like log4j-1.2.17.jar.
Source Code files for Apache Log4j are provided in both binary packge like log4j-1.2.17.zip and source package like log4j-1.2.17-sources.zip. You can download them at Apache Log4j Website.
You can also browse Source Code files for Apache Log4j 1.2.17 below.
✍: FYIcenter.com
⏎ org/apache/log4j/net/SocketServer.java
/* * 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.net; import java.io.File; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.Hashtable; import org.apache.log4j.Hierarchy; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.RootLogger; /** A {@link SocketNode} based server that uses a different hierarchy for each client. <pre> <b>Usage:</b> java org.apache.log4j.net.SocketServer port configFile configDir where <b>port</b> is a part number where the server listens, <b>configFile</b> is a configuration file fed to the {@link PropertyConfigurator} and <b>configDir</b> is a path to a directory containing configuration files, possibly one for each client host. </pre> <p>The <code>configFile</code> is used to configure the log4j default hierarchy that the <code>SocketServer</code> will use to report on its actions. <p>When a new connection is opened from a previously unknown host, say <code>foo.bar.net</code>, then the <code>SocketServer</code> will search for a configuration file called <code>foo.bar.net.lcf</code> under the directory <code>configDir</code> that was passed as the third argument. If the file can be found, then a new hierarchy is instantiated and configured using the configuration file <code>foo.bar.net.lcf</code>. If and when the host <code>foo.bar.net</code> opens another connection to the server, then the previously configured hierarchy is used. <p>In case there is no file called <code>foo.bar.net.lcf</code> under the directory <code>configDir</code>, then the <em>generic</em> hierarchy is used. The generic hierarchy is configured using a configuration file called <code>generic.lcf</code> under the <code>configDir</code> directory. If no such file exists, then the generic hierarchy will be identical to the log4j default hierarchy. <p>Having different client hosts log using different hierarchies ensures the total independence of the clients with respect to their logging settings. <p>Currently, the hierarchy that will be used for a given request depends on the IP address of the client host. For example, two separate applicatons running on the same host and logging to the same server will share the same hierarchy. This is perfectly safe except that it might not provide the right amount of independence between applications. The <code>SocketServer</code> is intended as an example to be enhanced in order to implement more elaborate policies. @author Ceki Gülcü @since 1.0 */ public class SocketServer { static String GENERIC = "generic"; static String CONFIG_FILE_EXT = ".lcf"; static Logger cat = Logger.getLogger(SocketServer.class); static SocketServer server; static int port; // key=inetAddress, value=hierarchy Hashtable hierarchyMap; LoggerRepository genericHierarchy; File dir; public static void main(String argv[]) { if(argv.length == 3) init(argv[0], argv[1], argv[2]); else usage("Wrong number of arguments."); try { cat.info("Listening on port " + port); ServerSocket serverSocket = new ServerSocket(port); while(true) { cat.info("Waiting to accept a new client."); Socket socket = serverSocket.accept(); InetAddress inetAddress = socket.getInetAddress(); cat.info("Connected to client at " + inetAddress); LoggerRepository h = (LoggerRepository) server.hierarchyMap.get(inetAddress); if(h == null) { h = server.configureHierarchy(inetAddress); } cat.info("Starting new socket node."); new Thread(new SocketNode(socket, h)).start(); } } catch(Exception e) { e.printStackTrace(); } } static void usage(String msg) { System.err.println(msg); System.err.println( "Usage: java " +SocketServer.class.getName() + " port configFile directory"); System.exit(1); } static void init(String portStr, String configFile, String dirStr) { try { port = Integer.parseInt(portStr); } catch(java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number ["+ portStr +"]."); } PropertyConfigurator.configure(configFile); File dir = new File(dirStr); if(!dir.isDirectory()) { usage("["+dirStr+"] is not a directory."); } server = new SocketServer(dir); } public SocketServer(File directory) { this.dir = directory; hierarchyMap = new Hashtable(11); } // This method assumes that there is no hiearchy for inetAddress // yet. It will configure one and return it. LoggerRepository configureHierarchy(InetAddress inetAddress) { cat.info("Locating configuration file for "+inetAddress); // We assume that the toSting method of InetAddress returns is in // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1 String s = inetAddress.toString(); int i = s.indexOf("/"); if(i == -1) { cat.warn("Could not parse the inetAddress ["+inetAddress+ "]. Using default hierarchy."); return genericHierarchy(); } else { String key = s.substring(0, i); File configFile = new File(dir, key+CONFIG_FILE_EXT); if(configFile.exists()) { Hierarchy h = new Hierarchy(new RootLogger(Level.DEBUG)); hierarchyMap.put(inetAddress, h); new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h); return h; } else { cat.warn("Could not find config file ["+configFile+"]."); return genericHierarchy(); } } } LoggerRepository genericHierarchy() { if(genericHierarchy == null) { File f = new File(dir, GENERIC+CONFIG_FILE_EXT); if(f.exists()) { genericHierarchy = new Hierarchy(new RootLogger(Level.DEBUG)); new PropertyConfigurator().doConfigure(f.getAbsolutePath(), genericHierarchy); } else { cat.warn("Could not find config file ["+f+ "]. Will use the default hierarchy."); genericHierarchy = LogManager.getLoggerRepository(); } } return genericHierarchy; } }
⏎ org/apache/log4j/net/SocketServer.java
Or download all of them as a single archive file:
File name: log4j-1.2.17-sources.jar File size: 481200 bytes Release date: 2012-05-06 Download
⇒ Download and Install apache-log4j-1.2.15.zip
⇐ Download and Install log4j-1.2.17.zip
2015-12-14, 51463👍, 0💬
Popular Posts:
ASM is an all purpose Java bytecode manipulation and analysis framework. It can be used to modify ex...
JDK 11 java.compiler.jmod is the JMOD file for JDK 11 Compiler module. JDK 11 Compiler module compil...
How to download and install JDK (Java Development Kit) 5? If you want to write Java applications, yo...
SLF4J API is a simple API that allows to plug in any desired logging library at deployment time. Her...
JDK 11 jdk.jshell.jmod is the JMOD file for JDK 11 JShell tool, which can be invoked by the "jshell"...