Package com.guinetik.corefun
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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceA simple, framework-agnostic logger interface. -
Method Summary
-
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
Creates a Loggable that uses the given Logger.- Parameters:
logger- the Logger to use- Returns:
- a Loggable instance
-
println
Creates a Loggable that prints to stdout/stderr.- Returns:
- a println-based Loggable
-
noop
Creates a no-op Loggable.- Returns:
- a silent Loggable
-