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

com.sshtools.slf4jtty.TtyLoggerFactory Maven / Gradle / Ivy

Go to download

An SLF4J log provider that directly implements the SLF4J API and provides logging output suitable for console output (i.e. not to a file). The width of the output is restricted to the terminal width, with the possibility to split the width into multiple sections, each which may be a fixed width, or 'auto' which divides all remaining space amongst other automative sections. Any log attribute fields may then be placed in any of the sections with a particular alignment. Text will not overflow out of its section. Sections may be colour or styled with other text attributes, including hyperlinks for supported termins. Emoticons and other graphical sequences may be used in place of log levels. Configuration is achieved via 'ini' type files, which are reload automatically when changed.

The newest version!
package com.sshtools.slf4jtty;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

import com.sshtools.slf4jtty.TtyLoggerConfiguration.Format;

/**
 * An implementation of {@link ILoggerFactory} which always returns
 * {@link TtyLogger} instances.
 * 

* TtyLogger and associated classes are based on SimpleLogger implementation to varying degrees. * * @author Ceki Gülcü */ public class TtyLoggerFactory implements ILoggerFactory { ConcurrentMap loggerMap; public TtyLoggerFactory() { loggerMap = new ConcurrentHashMap<>(); } /** * Return an appropriate {@link SimpleLogger} instance by name. */ public Logger getLogger(String name) { Logger simpleLogger = loggerMap.get(name); if (simpleLogger != null) { return simpleLogger; } else { TtyLoggerConfiguration cfg = TtyLoggerConfiguration.get(); Logger newInstance = cfg.format == Format.JSON ? new JsonLogger(name, cfg) : new TtyLogger(name, cfg); Logger oldInstance = loggerMap.putIfAbsent(name, newInstance); return oldInstance == null ? newInstance : oldInstance; } } /** * Clear the internal logger cache. * * This method is intended to be called by classes (in the same package) for * testing purposes. This method is internal. It can be modified, renamed or * removed at any time without notice. * * You are strongly discouraged from calling this method in production code. */ void reset() { loggerMap.clear(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy