001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016 017package org.forgerock.openig.log; 018 019import org.forgerock.openig.heap.Name; 020import org.slf4j.ILoggerFactory; 021import org.slf4j.Logger; 022 023/** 024 * SLF4J {@link ILoggerFactory} implementation that wraps a {@link LogSink}. 025 */ 026public class LogSinkLoggerFactory implements ILoggerFactory { 027 028 private LogSink logSink; 029 030 /** 031 * Build a new LogSinkLoggerFactory using a default ConsoleLogSink. 032 */ 033 public LogSinkLoggerFactory() { 034 logSink = defaultLogSink(); 035 } 036 037 private static ConsoleLogSink defaultLogSink() { 038 ConsoleLogSink sink = new ConsoleLogSink(); 039 sink.setStream(ConsoleLogSink.Stream.AUTO); 040 return sink; 041 } 042 043 /** 044 * Sets the {@link LogSink} to use. This method is called through reflection avoid any cycling dependency between 045 * this module and the core one. 046 * 047 * @param logSink 048 * where the log statements will be send 049 */ 050 public void setLogSink(final LogSink logSink) { 051 this.logSink = logSink; 052 } 053 054 @Override 055 public Logger getLogger(final String name) { 056 return new LogSinkLogger(logSink, Name.of(name)); 057 } 058}