Interface Loggable

All Known Subinterfaces:
SafeExecutor

public interface Loggable
Interface providing logging capabilities to implementing classes.

Loggable is framework-agnostic - implement logger() to return a Loggable.Logger that delegates to your preferred logging framework (SLF4J, Log4j, java.util.logging, etc.). This allows library code to emit logs without depending on any specific logging implementation.

Design Philosophy

Rather than depending on a logging facade like SLF4J, CoreFun uses a simple functional approach: you provide the logging functions. This means:

  • Zero dependencies on logging frameworks
  • Easy integration with any logging system
  • Testable - inject mock loggers for testing
  • Flexible - use lambdas, method references, or custom implementations

Example with SLF4J


 public class MyService implements Loggable {
     private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(MyService.class);

     @Override
     public Logger logger() {
         return Logger.of(LOG::info, LOG::warn, LOG::error);
     }

     public void doWork() {
         logger().info("Starting work");
         // ...
         logger().info("Work completed");
     }
 }
 

Example with java.util.logging


 public class JulService implements Loggable {
     private static final java.util.logging.Logger LOG =
         java.util.logging.Logger.getLogger(JulService.class.getName());

     @Override
     public Logger logger() {
         return Logger.of(
             msg -> LOG.info(msg),
             msg -> LOG.warning(msg),
             msg -> LOG.severe(msg)
         );
     }
 }
 

Example with Simple println


 public class SimpleService implements Loggable {
     @Override
     public Logger logger() {
         return Logger.println();
     }
 }
 

Tagged Logging


 Logger tagged = Logger.tagged("MyComponent", Logger.println());
 tagged.info("Starting");  // prints: [MyComponent] Starting
 
Since:
0.1.0
Author:
Guinetik <guinetik@gmail.com>
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A simple, framework-agnostic logger interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the logger for this instance.
    static Loggable
    Creates a no-op Loggable.
    static Loggable
    Creates a Loggable that uses the given Logger.
    static Loggable
    Creates a Loggable that prints to stdout/stderr.
  • Method Details

    • logger

      Loggable.Logger logger()
      Returns the logger for this instance. Override to provide a logger backed by your preferred framework.
      Returns:
      a Logger instance
    • of

      static Loggable of(Loggable.Logger logger)
      Creates a Loggable that uses the given Logger.
      Parameters:
      logger - the Logger to use
      Returns:
      a Loggable instance
    • println

      static Loggable println()
      Creates a Loggable that prints to stdout/stderr.
      Returns:
      a println-based Loggable
    • noop

      static Loggable noop()
      Creates a no-op Loggable.
      Returns:
      a silent Loggable