{"id":31105958,"url":"https://github.com/bright/slf4android","last_synced_at":"2025-09-17T04:48:51.857Z","repository":{"id":22430612,"uuid":"25768606","full_name":"bright/slf4android","owner":"bright","description":"A simple implementation of slf4j api using android java.util.logging.Logger","archived":false,"fork":false,"pushed_at":"2024-07-18T18:51:31.000Z","size":289,"stargazers_count":59,"open_issues_count":6,"forks_count":8,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-07T02:38:16.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bright.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-26T11:12:59.000Z","updated_at":"2025-04-02T13:47:23.000Z","dependencies_parsed_at":"2024-05-14T09:27:36.612Z","dependency_job_id":"32cb1af2-5f07-4d68-b591-98f4122f234a","html_url":"https://github.com/bright/slf4android","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/bright/slf4android","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fslf4android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fslf4android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fslf4android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fslf4android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bright","download_url":"https://codeload.github.com/bright/slf4android/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fslf4android/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275537148,"owners_count":25482345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-17T04:48:46.851Z","updated_at":"2025-09-17T04:48:51.842Z","avatar_url":"https://github.com/bright.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"slf4android\n===========\n\nA simple implementation of [SLF4J API](http://www.slf4j.org/) using Android `java.util.logging.*`. This means you can **easily hook in any existing** `java.util.logging.Handler` implementations. \n\nTo use this little gem, make sure you have Maven Central in your repositories:\n```groovy\nrepositories {\n    mavenCentral()\n}\n```\nand then declare a dependency inside a module:\n```groovy\ndependencies {\n    // just SLF4J binding\n    implementation(\"dev.bright.slf4android:slf4android:$slf4androidVersion\")\n\n    // (optional) a handler for file logging \n    implementation(\"dev.bright.slf4android:handler-file-log:$slf4androidVersion\")\n\n    // (optional) a handler for notifying the developer in case of an error \n    implementation(\"dev.bright.slf4android:handler-notify-developer:$slf4androidVersion\")\n}\n```\nAs with any slf4j compatible implementation using slf4android looks like this:\n```java\nclass HomeActivity extends Activity {\n    private static final Logger LOG = LoggerFactory.getLogger(HomeActivity.class.getSimpleName());\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        LOG.debug(\"Hello from {} saved instance state {}\", this, savedInstanceState);\n    }\n}\n```\n### Logging to Crashlytics\n[Crashlytics](https://get.fabric.io/crashlytics) has a nice feature of attaching log entries that were issued just before a crash. With slf4android it's easy to add a handler so that whenever a crash happens you get more insight as to what happened just before it.\n\nTo achieve that you need a custom handler:\n```java\nimport com.crashlytics.android.Crashlytics;\nimport java.util.logging.Handler;\nimport pl.brightinventions.slf4android.LogRecord;\nimport pl.brightinventions.slf4android.MessageValueSupplier;\n\npublic class CrashlyticsLoggerHandler extends Handler {\n    MessageValueSupplier messageValueSupplier = new MessageValueSupplier();\n\n    @Override\n    public void publish(java.util.logging.LogRecord record) {\n        LogRecord logRecord = LogRecord.fromRecord(record);\n        StringBuilder messageBuilder = new StringBuilder();\n        messageValueSupplier.append(logRecord, messageBuilder);\n        String tag = record.getLoggerName();\n        int androidLogLevel = logRecord.getLogLevel().getAndroidLevel();\n        Crashlytics.log(androidLogLevel, tag, messageBuilder.toString());\n    }\n\n    @Override\n    public void close() {\n    }\n\n    @Override\n    public void flush() {\n    }\n}\n```\n\nThat is added to root logger:\n```java\nLoggerConfiguration.configuration()\n        .removeRootLogcatHandler()\n        .addHandlerToRootLogger(new CrashlyticsLoggerHandler());\n```\nNote that we remove a default logcat handler since Crashlytics will push messages to logcat too.\n\n\n### Logging to a file\nTo print messages to a separate file just add:\n```java\nFileLogHandlerConfiguration fileHandler = FileLogHandlerConfiguration.create(this);\nLoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler);\nString logFileName = fileHandler.getCurrentFileName();\n// logFileName contains full path to logged file\n```\ninside your custom `android.app.Application` `onCreate` method. This will create rotated log files inside `context.getApplicationInfo().dataDir` with a name derived from `context.getPackageName()` and a default message pattern `%date %level [%thread] %name - %message%newline`\n\nTo change the location of log file you can use:\n```java\nFileLogHandlerConfiguration fileHandler = FileLogHandlerConfiguration.create(this);\n\nfileHandler.setFullFilePathPattern(\"/sdcard/your.package/my_log.%g.%u.log\");\n\nLoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fslf4android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbright%2Fslf4android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fslf4android/lists"}