All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.uuid.ext.Log4jLogger Maven / Gradle / Ivy

Go to download

Java UUID Generator (JUG) is a Java library for generating Universally Unique IDentifiers, UUIDs (see http://en.wikipedia.org/wiki/UUID). It can be used either as a component in a bigger application, or as a standalone command line tool. JUG generates UUIDs according to the IETF UUID draft specification. JUG supports 3 original official UUID generation methods as well as later additions (v6, v7)

There is a newer version: 5.1.0
Show newest version
/* JUG Java Uuid Generator
 *
 * Copyright (c) 2002- Tatu Saloranta, [email protected]
 *
 * Licensed under the License specified in the file LICENSE which is
 * included with the source code.
 * You may not use this file except in compliance with the License.
 *
 * 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 com.fasterxml.uuid.ext;

import java.io.*;

//import com.fasterxml.uuid.Logger;

/**
 * Simple wrapper that allows easy connecting of JUG logging into log4j
 * logging subsystem.
 *

* Note: using this class implies all the dependencies that the log4j * subsystem in use requires (JDK 1.2 or above, in general) */ public class Log4jLogger extends com.fasterxml.uuid.Logger { private org.apache.log4j.Logger mPeer; private Log4jLogger(org.apache.log4j.Logger peer) { mPeer = peer; } /** * Static method to call to make JUG use to proxy all of its logging * through the specified log4j Logger instance. *

* Method will create a simple wrapper, and call * {@link com.fasterxml.uuid.Logger#setLogger} with the wrapper as * the argument. This will then re-direct logging from the previously * defined Logger (which initially is the simple JUG logger) to the * new wrapper, which routes logging messages to the log4j peer Logger * instance. */ public static void connectToLog4j(org.apache.log4j.Logger peer) { Log4jLogger logger = new Log4jLogger(peer); // This is static method of the base class... setLogger(logger); } /** * Static method to call to make JUG use a log4j proxy all of its logging * through a log4j Logger constructed to correspond with * com.fasterxml.uuid.Logger class (this generally determines * log4j category output etc settings). *

* Method will create a simple wrapper, and call * {@link com.fasterxml.uuid.Logger#setLogger} with the wrapper as * the argument. This will then re-direct logging from the previously * defined Logger (which initially is the simple JUG logger) to the * new wrapper, which routes logging messages to the log4j peer Logger * instance. */ public static void connectToLog4j() { connectToLog4j(org.apache.log4j.Logger.getLogger(com.fasterxml.uuid.Logger.class)); } /* ///////////////////////////////////////////////////////////// // Overridable implementation/instance methods from // Logger base class ///////////////////////////////////////////////////////////// */ // // // Config // This is ok; let's just use base class functionality: //protected void doSetLogLevel(int ll); /** * Note: this method is meaningless with log4j, since it has more * advanced output mapping and filtering mechanisms. As such, it's * a no-op */ protected void doSetOutput(PrintStream str) { // Could also throw an Error.. but for now, let's log instead... mPeer.warn("doSetOutput(PrintStream) called on "+getClass()+" instance, ignoring."); } /** * Note: this method is meaningless with log4j, since it has more * advanced output mapping and filtering mechanisms. As such, it's * a no-op */ protected void doSetOutput(Writer w) { mPeer.warn("doSetOutput(Writer) called on "+getClass()+" instance, ignoring."); } // // // Logging methods protected void doLogInfo(String msg) { if (_logLevel <= LOG_INFO_AND_ABOVE) { mPeer.info(msg); } } protected void doLogWarning(String msg) { if (_logLevel <= LOG_WARNING_AND_ABOVE) { mPeer.warn(msg); } } protected void doLogError(String msg) { if (_logLevel <= LOG_ERROR_AND_ABOVE) { mPeer.error(msg); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy