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

org.hyperledger.fabric.Logger Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.fabric;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.LogManager;

/**
 * Logger class to use throughout the Contract Implementation
 *
 * Only available within the 1.4.3 release, this class was a helper class that wrapped
 * the standard java.util.logging.
 * 
 * This being deprecated as it doesn't enough extra function and also
 * log calls made via this can loose their 'caller method info'
 * 
 * For chaincode/contract implementations please use java.util.logging
 * or your own framework. All the Hyperledger Fabric code here is logged
 * in loggers with names starting org.hyperledger
 *  
 * @deprecated
 */
public class Logger extends java.util.logging.Logger {

    protected Logger(String name) {
        super(name, null);

        // ensure that the parent logger is set
        this.setParent(java.util.logging.Logger.getLogger("org.hyperledger.fabric"));
    }

    public static Logger getLogger(String name) {
        return new Logger(name);
    }

    /**
     * @deprecated
     */
    public void debug(Supplier msgSupplier) {
        log(Level.FINEST, msgSupplier);
    }

    /**
     * @deprecated
     */
    public void debug(String msg) {
        log(Level.FINEST, msg);
    }

    public static Logger getLogger(Class class1) {
        // important to add the logger to the log manager
        Logger l = Logger.getLogger(class1.getName());
        LogManager.getLogManager().addLogger(l);
        return l;
    }

    /**
     * @deprecated
     */
    public void error(String message) {
        log(Level.SEVERE, message);
    }

    /**
     * @deprecated
     */
    public void error(Supplier msgSupplier) {
        log(Level.SEVERE, msgSupplier);
    }

    /**
     * @deprecated
     */
    public String formatError(Throwable throwable) {
        if (throwable == null)
            return null;
        final StringWriter buffer = new StringWriter();
        buffer.append(throwable.getMessage());
        throwable.printStackTrace(new PrintWriter(buffer));

        Throwable cause = throwable.getCause();
        if (cause != null) {
            buffer.append(".. caused by ..");
            buffer.append(this.formatError(cause));
        }

        return buffer.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy