### Flexible Output Formatting Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Control the information included in log output using properties. ```properties showName=SHORT # Show simple class names showThread=true # Include thread names showName.expensive=CALLER # Show exact caller method ``` -------------------------------- ### Per-Logger Configuration Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Configure logging levels differently for specific packages using properties. ```properties level=INFO level.com.example.database=DEBUG level.com.example.analytics=WARN ``` -------------------------------- ### Logger Name Matching Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Illustrates how logger names are matched against configuration rules, prioritizing exact matches and then longest-prefix matches. ```text Logger: com.example.MyService Matches in order: 1. com.example.MyService (exact) 2. com.example (package) 3. (root) ``` -------------------------------- ### Logger Configuration Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/types.md Illustrates how to configure logging levels using a properties file. Specific loggers can override the default level. ```properties level=INFO level.com.example.debug=DEBUG level.com.example.production=WARN ``` -------------------------------- ### LoggingConfig Initialization Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md An example of how LoggingConfig is instantiated internally by LoggerFactory. It specifies the properties file name and a logger instance. ```java // This is called internally by LoggerFactory: LoggingConfig config = new LoggingConfig("config.properties", LOG); // Loads from uk/uuid/slf4j/android/config.properties // If not found, tries /eu/lp0/slf4j/android/config.properties // If not found, continues with defaults ``` -------------------------------- ### Basic SLF4J Logging Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Demonstrates the basic usage of SLF4J logging by obtaining a logger instance and logging an informational message. ```java import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MyApp { private static final Logger logger = LoggerFactory.getLogger(MyApp.class); public void run() { logger.info("Starting application"); } } ``` -------------------------------- ### Example of Marker-Based Trace Logging Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Demonstrates how to use a Marker with trace-level logging. The Marker is accepted but does not affect the Android log output. ```java Marker expensive = MarkerFactory.getMarker("EXPENSIVE"); logger.trace(expensive, "Entering expensive operation: {}", operationId); // The marker is accepted but not used in the Android log output ``` -------------------------------- ### Example SLF4J Android Configuration Properties Source: https://github.com/nomis/slf4j-android/blob/main/README.md This snippet shows an example of a properties file for configuring the SLF4J Android logger. Properties like tag, showThread, and showName can be set here. ```properties tag=ExampleApplication showThread=true showName=short ``` -------------------------------- ### Example Log Message Formatting Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Demonstrates how log messages are formatted with thread name and logger name prefixes enabled. The output shows the expected prefixed message. ```java // Config: showThread=true, showName=SHORT logger.info("User logged in"); // Output: [main] MyClass: User logged in ``` -------------------------------- ### Multi-Level Configuration Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/category-map.md Defines default properties and then overrides them for specific package prefixes. The resolution process shows how properties are merged from the most specific logger name up to the root. ```properties tag=DefaultApp level=INFO tag.com.example=Example level.com.example.service=DEBUG showName.com.example=SHORT ``` ```text Resulting CategoryMap: "" -> LoggerConfig(tag="DefaultApp", level=INFO) "com.example" -> LoggerConfig(tag="Example", showName=SHORT) "com.example.service" -> LoggerConfig(level=DEBUG) ``` ```text Resolution for `com.example.service.auth.Login`: Lookup: "com.example.service.auth.Login" → not found Lookup: "com.example.service.auth" → not found Lookup: "com.example.service" → found! level=DEBUG Is complete? No, has nulls for other fields Lookup: "com.example" → found! tag=Example, showName=SHORT Merge into existing: level=DEBUG, tag=Example, showName=SHORT Is complete? No, missing showThread Lookup: "" → found! tag=DefaultApp, level=INFO (but level already set) Merge: showThread=false (from defaults) Result: level=DEBUG, tag=Example, showName=SHORT, showThread=false ``` -------------------------------- ### Example Log Output with CallerStackTrace Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/caller-stack-trace.md Demonstrates the expected output format when `showName=CALLER` is configured and a direct logging call is made. The output includes the fully qualified method name of the caller. ```text Configuration: showName=CALLER Code: logger.info("User logged in"); Output: com.example.auth.LoginService.authenticate(): User logged in ``` -------------------------------- ### Logger Configuration Precedence Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md This properties file demonstrates how root, package-level, and logger-specific settings are defined to influence logger behavior. Settings not explicitly defined for a logger are inherited from its parent packages or the root configuration. ```properties # Root defaults tag=DefaultApp level=INFO showName=FALSE showThread=false # Package-level overrides tag.com.example=ExampleTag level.com.example=DEBUG # showName and showThread inherit from root # Logger-specific overrides tag.com.example.service.auth=AuthService # level inherits from com.example (DEBUG) # showName inherits from root (FALSE) # showThread inherits from root (false) ``` -------------------------------- ### Create Empty CategoryMap Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/category-map.md Initializes a new, empty CategoryMap. This is the starting point for managing logger configurations. ```java CategoryMap() ``` -------------------------------- ### ServiceProvider Class Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/INDEX.md Documentation for the ServiceProvider class, the primary entry point for SLF4J initialization. It includes methods for initializing the service, getting the LoggerFactory, and other essential adapters. ```APIDOC ## ServiceProvider Class ### Description The main entry point for the SLF4J implementation, responsible for service initialization and providing access to core factories. ### Methods - `initialize()`: Initializes the SLF4J service provider. - `getLoggerFactory()`: Returns the `ILoggerFactory` instance. - `getMarkerFactory()`: Returns the `IMarkerFactory` instance. - `getMDCAdapter()`: Returns the `MDCAdapter` instance. - `getRequestedApiVersion()`: Returns the requested SLF4J API version. ### Details - Service provider configuration and discovery process. - Lifecycle documentation for the service provider. ``` -------------------------------- ### Logger Usage with Specific Tag Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Demonstrates how a logger instance retrieves its tag configuration. This example shows a logger configured with a specific tag ('DB') from the properties file. ```java Logger logger = LoggerFactory.getLogger("com.example.database.ConnectionPool"); // Uses tag "DB" Logger logger2 = LoggerFactory.getLogger("com.example.utils.Helper"); // Uses default tag "MyApplication" ``` -------------------------------- ### Native Log Level Integration Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Set the log level to NATIVE to respect Android's system log level settings, utilizing `android.util.Log.isLoggable()`. ```properties level=NATIVE # Uses android.util.Log.isLoggable() ``` -------------------------------- ### Exact Logger Override Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/category-map.md Demonstrates how to set a property for a single, exact logger name, overriding any inherited properties. The resolution stops if the logger is found and complete. ```properties tag=DefaultApp tag.com.example.service.auth.LoginHandler=AuthLogin level.com.example.service.auth=DEBUG ``` ```text Resolution for `com.example.service.auth.LoginHandler`: Lookup: "com.example.service.auth.LoginHandler" → found! tag=AuthLogin If complete, return immediately Otherwise continue merging with parent configs ``` -------------------------------- ### get(String name) Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/category-map.md Retrieves the merged logger configuration for a given logger name by applying hierarchical matching rules. ```APIDOC ## get(String name) ### Description Returns the merged configuration for the given logger name by matching against configured category prefixes. The matching process starts with the exact logger name and proceeds up the hierarchy to the root logger, merging configurations as it goes. Built-in defaults are applied if the configuration is still incomplete. ### Method Signature ```java final LoggerConfig get(String name) ``` ### Parameters #### Path Parameters - **name** (String) - Required - The fully-qualified logger name to look up. ### Return Type `LoggerConfig` - A new LoggerConfig instance with merged settings from all matching categories and defaults. ### Matching Algorithm 1. Starts with the exact logger name. 2. Checks if an exact configuration exists; if so, merges it and continues if incomplete. 3. Removes the rightmost segment (after the last `.`) and repeats. 4. When no more segments remain, checks for root configuration (empty string key). 5. If still incomplete, merges with built-in defaults. 6. Returns the final merged configuration. ### Null Handling If the name parameter is null, it is treated as an empty string (root logger). ### Merging Process Configurations are merged using `LoggerConfig.merge()`, which fills in null fields from later configurations without overwriting existing values. ### Example ```java CategoryMap map = new CategoryMap(); map.put("com.example", new LoggerConfig(LogLevel.DEBUG)); map.put("com.example.service", new LoggerConfig("MyService")); LoggerConfig config1 = map.get("com.example.service.auth.Login"); // Result: Uses LoggerConfig from "com.example.service" (tag="MyService") // Then merges with "com.example" (level=DEBUG) // Final: tag="MyService", level=DEBUG LoggerConfig config2 = map.get("com.example.util"); // Result: Uses LoggerConfig from "com.example" (level=DEBUG) // Final: level=DEBUG, other settings from defaults ``` ``` -------------------------------- ### Logger Usage with Specific Level Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Illustrates logger behavior based on configured logging levels. This example shows messages being logged or suppressed according to the 'DEBUG' level set for the 'com.example.feature.new' package. ```java Logger logger = LoggerFactory.getLogger("com.example.feature.new.Processor"); logger.trace("Entering processor"); // Logged (VERBOSE >= DEBUG) logger.debug("Processing item"); // Logged logger.info("Started operation"); // Logged ``` -------------------------------- ### Production Configuration for SLF4J Android Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/README.md A conservative production logging setup. It sets a general INFO level while increasing the log level to WARN for a specific third-party package. ```properties tag=MyApp level=INFO level.com.myapp.thirdparty=WARN ``` -------------------------------- ### LoggerFactory Class Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/INDEX.md Documentation for the LoggerFactory class, which is the entry point for obtaining loggers and related factories. It covers methods for getting a logger by name and creating tags, along with details on configuration loading and thread safety. ```APIDOC ## LoggerFactory Class ### Description Provides access to loggers and utility methods for tag creation. Handles configuration loading and ensures thread safety. ### Methods - `getLogger(String name)`: Retrieves a logger instance for the given name. - `createTag(String name)`: Static utility method to create a tag, often based on the provided name. ### Details - Automatic tag generation algorithm is described. - Configuration loading and caching mechanisms are explained. - Thread safety guarantees are provided. ``` -------------------------------- ### Get Logger Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/category-map.md Retrieves the merged configuration for a given logger name. It applies a hierarchical matching algorithm, starting from the exact logger name and moving up through parent packages to the root. ```java final LoggerConfig get(String name) ``` ```java Logger name: com.example.service.auth.LoginHandler Lookups in order: 1. "com.example.service.auth.LoginHandler" → Not found 2. "com.example.service.auth" → Found! Use this config - If this config is complete, return it - Otherwise, continue to parent 3. "com.example.service" → Check if has more config 4. "com.example" → Check if has more config 5. "" (root) → Check for root config 6. LoggerConfig.DEFAULT → Use built-in defaults ``` ```java CategoryMap map = new CategoryMap(); map.put("com.example", new LoggerConfig(LogLevel.DEBUG)); map.put("com.example.service", new LoggerConfig("MyService")); LoggerConfig config1 = map.get("com.example.service.auth.Login"); // Result: Uses LoggerConfig from "com.example.service" (tag="MyService") // Then merges with "com.example" (level=DEBUG) // Final: tag="MyService", level=DEBUG LoggerConfig config2 = map.get("com.example.util"); // Result: Uses LoggerConfig from "com.example" (level=DEBUG) // Final: level=DEBUG, other settings from defaults ``` -------------------------------- ### Get Logger Name Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Retrieves the fully-qualified name of the logger instance. ```java public final String getName() ``` -------------------------------- ### get() Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/caller-stack-trace.md Retrieves the extracted stack frame element at a configured depth. Returns UNKNOWN if the depth is out of bounds. ```APIDOC ## get() ### Description Returns the extracted stack frame element. ### Method Signature ```java public final StackTraceElement get() ``` ### Return Type `StackTraceElement` - The stack frame at the configured depth, or UNKNOWN if the depth was out of bounds. ### Properties of Returned StackTraceElement - `getClassName()`: The fully-qualified class name - `getMethodName()`: The method name - `getFileName()`: The source file name (may be null) - `getLineNumber()`: The line number in source (may be -1) ### Example ```java CallerStackTrace cst = new CallerStackTrace(4); StackTraceElement frame = cst.get(); System.out.println(frame.getClassName() + "." + frame.getMethodName()); // Output: com.example.MyClass.doSomething ``` ``` -------------------------------- ### Get Stack Trace Element Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/caller-stack-trace.md Retrieves the StackTraceElement at a configured depth. Returns UNKNOWN if the depth is out of bounds. ```java public final StackTraceElement get() ``` ```java CallerStackTrace cst = new CallerStackTrace(4); StackTraceElement frame = cst.get(); System.out.println(frame.getClassName() + "." + frame.getMethodName()); // Output: com.example.MyClass.doSomething ``` -------------------------------- ### Simple Development Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Use this configuration for verbose logging during development to see full context. It sets a custom tag and enables detailed logging. ```properties # Development configuration - verbose logging with full context tag=MyDevApp level=DEBUG showName=SHORT showThread=true ``` -------------------------------- ### Get LoggerFactory Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/service-provider.md Returns the logger factory for obtaining logger instances. initialize() must be called before this method. ```java ServiceProvider provider = new ServiceProvider(); provider.initialize(); ILoggerFactory factory = provider.getLoggerFactory(); Logger logger = factory.getLogger("com.example.MyApp"); ``` -------------------------------- ### Get Requested API Version Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Returns the SLF4J API version that this binding targets. This is useful for compatibility checks. ```java @Override public String getRequestedApiVersion() ``` -------------------------------- ### File Loading Logic Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md This code block demonstrates the logic for locating and loading the properties file. It first checks the standard resource path and then a legacy path. If the file is found, it's loaded; otherwise, a debug message is logged. ```java URL url = getClass().getResource(configFileName); if (url == null) { /* Try old package name */ url = getClass().getResource("/eu/lp0/slf4j/android/" + configFileName); } if (url != null) { log.debug("Loading properties file from {}", url); try { props.load(url.openStream()); } catch (IOException e) { log.error("Error loading properties file from {}", url, e); props.clear(); } } else { log.debug("No config file"); } ``` -------------------------------- ### Production-Ready Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md This configuration is suitable for production, balancing logging with important context. It allows for specific module overrides and quieting third-party libraries. ```properties # Production configuration - balanced logging with important context tag=MyApp level=INFO # Debug specific modules in production level.com.myapp.feature.newfeature=DEBUG # Quiet third-party libraries level.com.thirdparty=WARN tag.com.thirdparty=3PLib # Production code stays quiet level.com.myapp.analytics=WARN ``` -------------------------------- ### Configure Log Levels Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/INDEX.md Set the global log level and specific levels for packages. Use properties format. ```properties level=INFO level.com.example=DEBUG ``` -------------------------------- ### initialize() Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/service-provider.md Initializes the service provider and creates the logger factory. This method is called automatically by the SLF4J framework. ```APIDOC ## initialize() ### Description Initializes the service provider and creates the logger factory. ### Return Type `void` ### Behavior This method is called by the SLF4J framework to initialize the binding. It creates a new `LoggerFactory` instance and assigns it to the internal field for later retrieval via `getLoggerFactory()`. ### Example ```java // This is called automatically by SLF4J: SLF4JServiceProvider provider = new ServiceProvider(); provider.initialize(); Logger logger = provider.getLoggerFactory().getLogger("com.example.MyClass"); logger.info("Ready to log"); ``` ### Source `ServiceProvider.java:74-76` ``` -------------------------------- ### Basic Usage of slf4j-android Logger Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Demonstrates how to obtain a logger instance and log messages at different levels. Ensure the logger is properly initialized. ```java import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MyApplication { private static final Logger logger = LoggerFactory.getLogger(MyApplication.class); public void startApplication() { logger.info("Application starting"); logger.debug("Debug mode enabled"); logger.error("An error occurred", exception); } } ``` -------------------------------- ### Get LoggerFactory Instance Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Provides access to the LoggerFactory instance, which is used for obtaining Logger instances. This method is part of the SLF4JServiceProvider contract. ```java @Override public ILoggerFactory getLoggerFactory() ``` -------------------------------- ### Compact Logger Tag Example Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Logger names longer than 23 characters are automatically compacted to fit Android's tag limit. ```text com.example.myapplication.service.authentication.LoginHandler ↓ (compacted) c.e.m.s.a.LoginHandler ``` -------------------------------- ### initialize() Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Initializes the SLF4J binding. This method is called by the SLF4J framework during startup to set up the LoggerFactory and load configuration. ```APIDOC ## initialize() ### Description Initializes the SLF4J binding. Called by the SLF4J framework during startup. ### Responsibility Creates the LoggerFactory and loads configuration. ### Signature ```java @Override public void initialize() ``` ``` -------------------------------- ### Get Logger Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md Retrieves the merged configuration for a specific logger name. Delegates to an internal map for hierarchical prefix matching and merging. ```java final LoggerConfig get(String name) ``` ```java LoggingConfig loggingConfig = new LoggingConfig("config.properties", LOG); LoggerConfig config = loggingConfig.get("com.example.MyClass"); // Returns merged configuration for com.example.MyClass ``` -------------------------------- ### Get MarkerFactory Instance Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Returns the marker factory, which is a BasicMarkerFactory in this binding. Note that markers are accepted by LogAdapter but do not affect logging output on Android. ```java @Override public IMarkerFactory getMarkerFactory() ``` -------------------------------- ### Basic SLF4J Usage in Java Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/README.md Demonstrates basic logging with slf4j-android, including info, debug, and error messages with exceptions. Ensure slf4j-api is available. ```java import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MyClass { private static final Logger logger = LoggerFactory.getLogger(MyClass.class); public void doSomething() { logger.info("Information message"); logger.debug("Debug message: {}", value); try { risky(); } catch (Exception e) { logger.error("Operation failed", e); } } } ``` -------------------------------- ### SLF4J Configuration Loading Flow Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/MODULE-MAP.md Explains how the SLF4J Android module initializes and loads its configuration, including finding and parsing the properties file. ```text ServiceProvider.initialize() ↓ LoggerFactory constructor ├─ LoggingConfig(DEFAULT_FILENAME, LOG) │ ├─ Find config.properties file │ │ ├─ Try: uk/uuid/slf4j/android/config.properties │ │ └─ Try: /eu/lp0/slf4j/android/config.properties │ ├─ Parse properties │ │ ├─ Extract tag properties │ │ ├─ Extract level properties │ │ ├─ Extract showName properties │ │ └─ Extract showThread properties │ ├─ Validate values │ └─ Store in CategoryMap via put() └─ Initialization complete ``` -------------------------------- ### Get Stack Trace Element as String Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/caller-stack-trace.md Returns a formatted string representation of the stack frame. For out-of-bounds depths, it returns a standard unknown format. ```java public final String toString() ``` ```java CallerStackTrace cst = new CallerStackTrace(4); String frameStr = cst.toString(); // Output: "com.example.MyClass.doSomething(MyClass.java:42)" CallerStackTrace cst2 = new CallerStackTrace(100); // Out of bounds String frameStr2 = cst2.toString(); // Output: "." ``` -------------------------------- ### LogAdapter Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Creates a new LogAdapter instance for a given logger name and configuration. ```APIDOC ## LogAdapter(String name, LoggerConfig config) ### Description Creates a new LogAdapter for the specified logger name with the provided configuration. ### Parameters #### Path Parameters - **name** (String) - Required - The fully-qualified logger name - **config** (LoggerConfig) - Required - Configuration object containing tag, level, display options ### Behavior Initializes the adapter by storing the name, extracting the Android tag from config, computing the compact logger name if needed, and determining which log levels are enabled based on the configured level. If the config level is set to NATIVE, queries the Android system to determine the actual log level and caches it. ``` -------------------------------- ### SLF4J Framework Service Provider Initialization Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/MODULE-MAP.md This shows how the SLF4J framework discovers and initializes the ServiceProvider. Application code should not directly instantiate these classes. ```java // SPI discovery ServiceProvider provider = new ServiceProvider(); // Instantiated by SLF4J provider.initialize(); ILoggerFactory factory = provider.getLoggerFactory(); // Returns LoggerFactory ``` -------------------------------- ### Standard SLF4J Usage Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Demonstrates the typical way to obtain a logger and log messages using the SLF4J API. This pattern is implementation-agnostic and relies on SLF4J's service discovery. ```java // Standard SLF4J usage (implementation-agnostic) Logger logger = LoggerFactory.getLogger("com.example.MyClass"); logger.info("Message"); ``` -------------------------------- ### Logging Output Messages Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md Provides visibility into the configuration process. Different log levels indicate various conditions during loading. ```text DEBUG | "Loading properties file from {url}" | Config file found and loading starts DEBUG | "No config file" | Config file not found at either location ERROR | "Error loading properties file from {url}" | IO error while reading file WARN | "Ignoring invalid default tag {value}" | Tag exceeds 23 characters (no prefix) WARN | "Ignoring invalid tag {value} for {prefix}" | Tag exceeds 23 characters (with prefix) WARN | "Ignoring invalid default log level {value}" | Unknown LogLevel value (no prefix) WARN | "Ignoring invalid log level {value} for {prefix}" | Unknown LogLevel value (with prefix) WARN | "Ignoring invalid default show name setting {value}" | Unknown ShowName value (no prefix) WARN | "Ignoring invalid show name setting {value} for {prefix}" | Unknown ShowName value (with prefix) TRACE | "Config processing completed in {microseconds}µs" | Configuration loading finished ``` -------------------------------- ### CallerStackTrace Utility Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/INDEX.md Information about the CallerStackTrace utility class, used for extracting stack frames. It covers its constructor, the `get()` method for accessing frames, and its usage within the LogAdapter. ```APIDOC ## CallerStackTrace Utility ### Description A utility class designed to extract and provide access to caller stack frames. ### Methods - `CallerStackTrace(int frameDepth)`: Constructor that initializes the utility with a specified frame depth. - `get()`: Retrieves the extracted stack frame information. - `toString()`: Provides a formatted string representation of the stack trace. ### Details - Usage within the `LogAdapter` for determining the calling class. - Performance considerations and limitations of stack frame extraction. ``` -------------------------------- ### ServiceProvider() Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/service-provider.md Constructs a new ServiceProvider with default marker and MDC implementations. The logger factory is created lazily during initialize(). ```APIDOC ## ServiceProvider() ### Description Constructs a new ServiceProvider with default marker and MDC implementations. ### Behavior Creates a new BasicMarkerFactory for marker support and a NOPMDCAdapter for MDC operations (which is a no-operation implementation since Android logging does not support MDC). The logger factory is not created during construction; it is created lazily during `initialize()`. ### Source `ServiceProvider.java:48-51` ``` -------------------------------- ### Get Logger Instance in Application Code Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/MODULE-MAP.md Use the standard SLF4J API to obtain a logger instance for your class. This is the primary way application code should interact with SLF4J. ```java Logger logger = LoggerFactory.getLogger("com.example.MyClass"); logger.info("Message"); ``` -------------------------------- ### Production Configuration Properties Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/TECHNICAL-REFERENCE.md Configure for production to set a baseline INFO level and override specific package loggers. ```properties tag=MyApp level=INFO level.com.myapp.debug=DEBUG level.com.myapp.analytics=WARN ``` -------------------------------- ### Configure Logger Name Display (Java) Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Demonstrates how logger name display settings affect log output in Java. Assumes specific properties are set. ```java // Assume: showName.com.example=SHORT Logger logger = LoggerFactory.getLogger("com.example.MyService"); logger.info("Service started"); // Output: MyService: Service started // Assume: showName.com.example.expensive=CALLER Logger logger2 = LoggerFactory.getLogger("com.example.expensive.Operation"); logger2.info("Operation complete"); // Output: com.example.expensive.Operation.execute(): Operation complete ``` -------------------------------- ### Get Logger Instance Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logger-factory.md Retrieves or creates a logger instance with the specified name. The factory caches logger instances and handles concurrent access safely. Use this to obtain a logger for your class. ```java Logger logger = loggerFactory.getLogger("com.example.MyClass"); logger.info("Application started"); logger.debug("Processing request: {}", requestId); ``` -------------------------------- ### Configure Thread and Logger Name Display (Java) Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Illustrates the combined effect of thread and logger name display settings on log output in Java. Assumes specific properties are set. ```java // Assume: showThread=true, showName=SHORT Logger logger = LoggerFactory.getLogger("com.example.Worker"); logger.info("Processing task"); // Output: [AsyncTask-1] Worker: Processing task // In different thread: logger.info("Completed"); // Output: [main] Worker: Completed ``` -------------------------------- ### ServiceProvider Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/MODULE-MAP.md The SLF4J service provider entry point, responsible for initializing the binding and providing factories for Loggers, Markers, and MDC. ```APIDOC ## ServiceProvider ### Fully Qualified Name `uk.uuid.slf4j.android.ServiceProvider` ### Interface `org.slf4j.spi.SLF4JServiceProvider` ### Access Public ### Instantiation Via SPI mechanism (automatic) ### Responsibilities - Acts as SLF4J service provider entry point - Initializes the binding - Provides LoggerFactory, MarkerFactory, MDCAdapter ``` -------------------------------- ### CategoryMap Class Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/INDEX.md Documentation for the CategoryMap class, a hierarchical registry used for managing logger configurations based on category names. It includes methods for getting and putting configurations and describes the matching algorithm. ```APIDOC ## CategoryMap Class ### Description A hierarchical registry for mapping logger category names to their configurations. ### Methods - `get(String name)`: Retrieves the `LoggerConfig` for a given category name using prefix matching. - `put(String name, LoggerConfig value)`: Adds or updates a `LoggerConfig` for a specific category name. ### Details - Hierarchical matching algorithm explained. - Examples of configuration merging. - Performance characteristics. ``` -------------------------------- ### Per-Feature Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Configure base settings and then override specific features or packages for detailed logging. This allows teams to manage their own logging levels and tags. ```properties # Base configuration tag=MyApp level=INFO showName=false showThread=false # Feature teams can override for their packages level.com.myapp.payments=DEBUG showName.com.myapp.payments=LONG tag.com.myapp.payments=Payments level.com.myapp.inventory=DEBUG showName.com.myapp.inventory=COMPACT tag.com.myapp.inventory=Inventory # Expensive operations get extra visibility showName.com.myapp.reports=CALLER showThread.com.myapp.reports=true ``` -------------------------------- ### CategoryMap Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/category-map.md Creates a new empty CategoryMap instance. Initializes an internal HashMap to store category configurations. ```APIDOC ## CategoryMap() ### Description Creates a new empty CategoryMap. ### Constructor Signature ```java CategoryMap() ``` ### Behavior Initializes an empty HashMap to store category configurations. ``` -------------------------------- ### ServiceProvider Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Creates a new instance of the ServiceProvider. ```APIDOC ## ServiceProvider() ### Description Creates a new service provider instance. ### Signature ```java public ServiceProvider() ``` ``` -------------------------------- ### Feature Team Configuration for SLF4J Android Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/README.md Configures different logging settings for specific feature teams. This example shows distinct settings for 'Team A' and 'Team B', including custom tags and display name formats. ```properties tag=MyApp level=INFO # Team A tag.com.myapp.feature.paymentprocessing=Payments level.com.myapp.feature.paymentprocessing=DEBUG showName.com.myapp.feature.paymentprocessing=LONG # Team B tag.com.myapp.feature.analytics=Analytics showName.com.myapp.feature.analytics=COMPACT ``` -------------------------------- ### Set Native Log Level at Runtime (Android 5.0+) Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/configuration.md Use this snippet to change the native log level for a specific tag in Android applications starting from API level 21 (Lollipop). This affects the Android system's logging, not SLF4J's internal configuration. ```java import android.util.Log; // This affects the NATIVE log level setting only if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Process.setLogLevel(Log.DEBUG, "MyTag"); } ``` -------------------------------- ### LoggingConfig Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md Creates a new LoggingConfig instance and loads logging properties from a specified file. It attempts to find the file in standard and legacy locations, parses the properties, validates them, and stores them. Errors during loading are logged. ```APIDOC ## LoggingConfig(String configFileName, Logger log) ### Description Creates a new LoggingConfig and loads configuration from the specified file. ### Parameters #### Path Parameters - **configFileName** (String) - Required - The properties file name (e.g., "config.properties") - **log** (Logger) - Required - A logger instance to use for logging configuration loading progress and errors ### Request Example ```java // This is called internally by LoggerFactory: LoggingConfig config = new LoggingConfig("config.properties", LOG); // Loads from uk/uuid/slf4j/android/config.properties // If not found, tries /eu/lp0/slf4j/android/config.properties // If not found, continues with defaults ``` ``` -------------------------------- ### Info Logging Methods Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Provides methods for logging messages at the INFO level. Supports simple messages, formatted strings with arguments, and includes options for logging with a marker or a throwable. ```java public final void info(final String msg) public final void info(final String format, final Object arg) public final void info(final String format, final Object arg1, final Object arg2) public final void info(final String format, final Object... arguments) public final void info(final String msg, final Throwable t) public final void info(final Marker marker, final String msg) public final void info(final Marker marker, final String format, final Object arg) public final void info(final Marker marker, final String format, final Object arg1, final Object arg2) public final void info(final Marker marker, final String format, final Object... argArray) public final void info(final Marker marker, final String msg, final Throwable t) ``` -------------------------------- ### LogAdapter Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Creates a new LogAdapter instance. Requires a logger name and a LoggerConfig object for tag, level, and display options. The adapter initializes by storing the name, extracting the Android tag, and determining enabled log levels based on the configuration. ```java LogAdapter(final String name, final LoggerConfig config) ``` -------------------------------- ### SLF4J Exception Logging Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Illustrates how to log an exception with its stack trace using the error level in SLF4J. ```java Logger logger = LoggerFactory.getLogger("com.example.Handler"); try { processRequest(); } catch (Exception e) { logger.error("Failed to process request", e); } ``` -------------------------------- ### LoggingConfig Constructor Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md Creates a new LoggingConfig instance and loads configuration from the specified properties file. It attempts to find the file in standard and legacy locations, logs progress, and handles potential IO errors. ```java LoggingConfig(final String configFileName, final Logger log) ``` -------------------------------- ### Simple Default SLF4J-Android Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/types.md Use this simple configuration for a default tag, log level, and display settings across all loggers. Ensure the properties are placed in a classpath resource. ```properties tag=MyApp level=DEBUG showName=SHORT showThread=true ``` -------------------------------- ### Marker-Based Logging Methods Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Provides overloads for trace, debug, info, warn, and error methods that accept an SLF4J Marker. Note that markers are ignored in this implementation and do not affect logging behavior. ```APIDOC ## Marker-Based Methods All trace/debug/info/warn/error methods have corresponding overloads that accept an SLF4J `Marker` parameter. **Markers are ignored** in this implementation—the logging behavior is identical to the non-marker variants. ### `trace(Marker marker, String msg)` Logs a message with TRACE level, accepting a Marker. ### `trace(Marker marker, String format, Object arg)` Logs a formatted message with TRACE level, accepting a Marker. ### `trace(Marker marker, String format, Object arg1, Object arg2)` Logs a formatted message with TRACE level, accepting two arguments and a Marker. ### `trace(Marker marker, String format, Object... argArray)` Logs a formatted message with TRACE level, accepting an array of arguments and a Marker. ### `trace(Marker marker, String msg, Throwable t)` Logs a message with TRACE level and an associated Throwable, accepting a Marker. **Example**: ```java Marker expensive = MarkerFactory.getMarker("EXPENSIVE"); logger.trace(expensive, "Entering expensive operation: {}", operationId); // The marker is accepted but not used in the Android log output ``` ``` -------------------------------- ### Info Methods Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Provides a complete set of methods for logging at the INFO level, mirroring the trace methods. ```APIDOC ## Info Methods Provides a complete set of methods for logging at the INFO level, mirroring the trace methods. ### Methods - `info(final String msg)` - `info(final String format, final Object arg)` - `info(final String format, final Object arg1, final Object arg2)` - `info(final String format, final Object... arguments)` - `info(final String msg, final Throwable t)` - `info(final Marker marker, final String msg)` - `info(final Marker marker, final String format, final Object arg)` - `info(final Marker marker, final String format, final Object arg1, final Object arg2)` - `info(final Marker marker, final String format, final Object... argArray)` - `info(final Marker marker, final String msg, final Throwable t)` ``` -------------------------------- ### Basic Logging Methods Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md These are the fundamental SLF4J logging methods for different levels. Use them for simple log messages. ```java void trace(String msg) void debug(String msg) void info(String msg) void warn(String msg) void error(String msg) ``` -------------------------------- ### Initialize SLF4J Binding Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Initializes the SLF4J binding by creating the LoggerFactory and loading configuration. This method is automatically called by the SLF4J framework during startup. ```java @Override public void initialize() ``` -------------------------------- ### Warn Logging Methods Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/log-adapter.md Provides overloads for logging messages at the WARN level. Supports formatted strings with arguments and includes options for attaching a Throwable. ```java public final void warn(final String msg) public final void warn(final String format, final Object arg) public final void warn(final String format, final Object arg1, final Object arg2) public final void warn(final String format, final Object... arguments) public final void warn(final String msg, final Throwable t) public final void warn(final Marker marker, final String msg) public final void warn(final Marker marker, final String format, final Object arg) public final void warn(final Marker marker, final String format, final Object arg1, final Object arg2) public final void warn(final Marker marker, final String format, final Object... argArray) public final void warn(final Marker marker, final String msg, final Throwable t) ``` -------------------------------- ### Initialize Service Provider Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/service-provider.md Initializes the service provider and creates the logger factory. This method is called automatically by the SLF4J framework. ```java SLF4JServiceProvider provider = new ServiceProvider(); provider.initialize(); Logger logger = provider.getLoggerFactory().getLogger("com.example.MyClass"); logger.info("Ready to log"); ``` -------------------------------- ### Logging Configuration File Locations Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md LoggingConfig searches for configuration files in both a primary and a legacy location for backward compatibility. The primary location is checked first. ```text For Maven: src/main/resources/uk/uuid/slf4j/android/config.properties In JAR: uk/uuid/slf4j/android/config.properties ``` ```text For Maven: src/main/resources/eu/lp0/slf4j/android/config.properties In JAR: eu/lp0/slf4j/android/config.properties ``` -------------------------------- ### Formatted SLF4J Logging Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Demonstrates using parameterized messages for efficient and readable logging of variables in SLF4J. ```java Logger logger = LoggerFactory.getLogger("com.example.Service"); logger.info("User {} logged in from {}", username, ipAddress); logger.warn("Operation took {} ms (threshold: {} ms)", elapsed, threshold); ``` -------------------------------- ### Logger Name Display Configuration Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/types.md Configure logger name display using properties. Specific configurations override general ones. ```properties showName=SHORT showName.com.example=COMPACT showName.com.example.expensive=CALLER ``` -------------------------------- ### getLoggerFactory() Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/service-provider.md Returns the logger factory for obtaining logger instances. `initialize()` must be called before this method. ```APIDOC ## getLoggerFactory() ### Description Returns the logger factory for obtaining logger instances. ### Return Type `ILoggerFactory` — The factory that provides named Logger instances. Specifically, an instance of `LoggerFactory`. ### Precondition `initialize()` must be called before this method returns a non-null factory. ### Example ```java ServiceProvider provider = new ServiceProvider(); provider.initialize(); ILoggerFactory factory = provider.getLoggerFactory(); Logger logger = factory.getLogger("com.example.MyApp"); ``` ### Source `ServiceProvider.java:54-56` ``` -------------------------------- ### Configure Message Format Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/INDEX.md Control the display of the logger name and thread information in log messages. Use properties format. ```properties showName=SHORT showThread=true ``` -------------------------------- ### Logging Methods with Two Format Arguments Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/PUBLIC-API.md Use these methods for logging formatted strings with two arguments. They provide more flexibility for constructing messages. ```java void trace(String format, Object arg1, Object arg2) void debug(String format, Object arg1, Object arg2) void info(String format, Object arg1, Object arg2) void warn(String format, Object arg1, Object arg2) void error(String format, Object arg1, Object arg2) ``` -------------------------------- ### Default Configuration Filename Constant Source: https://github.com/nomis/slf4j-android/blob/main/_autodocs/api-reference/logging-config.md Used to instantiate LoggingConfig when a custom filename is not provided. ```java LoggingConfig config = new LoggingConfig(LoggingConfig.DEFAULT_FILENAME, LOG); ```