{"id":28619653,"url":"https://github.com/eleme/trojan","last_synced_at":"2025-06-12T04:41:04.753Z","repository":{"id":51338041,"uuid":"115109261","full_name":"eleme/Trojan","owner":"eleme","description":"Trojan is an efficient mobile terminal lightweight log SDK","archived":false,"fork":false,"pushed_at":"2021-05-14T14:18:09.000Z","size":304,"stargazers_count":390,"open_issues_count":7,"forks_count":66,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-04-18T15:53:55.161Z","etag":null,"topics":["logging-library","mobile-app","trojan"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eleme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-22T11:26:20.000Z","updated_at":"2024-04-03T10:43:05.000Z","dependencies_parsed_at":"2022-08-27T16:31:41.933Z","dependency_job_id":null,"html_url":"https://github.com/eleme/Trojan","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eleme/Trojan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FTrojan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FTrojan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FTrojan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FTrojan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eleme","download_url":"https://codeload.github.com/eleme/Trojan/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FTrojan/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259400479,"owners_count":22851818,"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","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":["logging-library","mobile-app","trojan"],"created_at":"2025-06-12T04:40:53.738Z","updated_at":"2025-06-12T04:41:04.738Z","avatar_url":"https://github.com/eleme.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](/assets/trojan_banner.png)\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://gradleupdate.appspot.com/ELELogistics/Trojan/status\"\u003e\n        \u003cimg src=\"https://gradleupdate.appspot.com/ELELogistics/Trojan/status.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.java.com\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/language-Java-blue.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/EyreFree/EFQRCode/assets/icon/MadeWith%3C3.png\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/made%20with-%3C3-orange.svg\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n[Trojan](https://github.com/ELELogistics/Trojan) is a stable and efficient mobile lightweight log SDK that not only records general logs, such as Http, power changes, component life cycles, but also records the definition of the log, which it is useful to  analysis problems through the user logs. Here is the following characteristics:\n\n* Concise API, it is easy to achieve diary record function through a few lines of code;\n* Use the AOP technologies [Lancet](https://github.com/eleme/lancet) SDK, it is comfortable to collect common logs, also support incremental compile;\n* Use mmap technology to ensure the efficiency of log records;\n* Scalability, developers can customize the log file to achieve the purpose of the upload;\n* Small traffic overhead, remote control user log file upload or not by online configuration;\n* High stability, it is very stable at many apps.\n\n\u003e [中文介绍](/README_CN.md)\n\n## Overview\n\nIn the open source [Trojan](https://github.com/ELELogistics/Trojan) SDK, we have collected basic logs such as Activity and Fragment lifecycles, View Click events, network status changes, phone battery status changes, also include collecting [KLog](https://github.com/ZhaoKaiQiang/KLog) logs, if KLog is not used in the project, it can be customized according to the project specific conditions. Considering that the implementation framework for network modules is different at fact, there are [OkHttp](https://github.com/square/okhttp), [Volley](https://github.com/google/volley), [Android-Async-Http](https://github.com/loopj/android-async-http), etc. Therefore, this part of collecting network logs is not suitable for customization. Users can use [Lancet](https://github.com/eleme/lancet) to collect logs  at the specific network framework. In [Demo](https://github.com/ELELogistics/Trojan/blob/master/app/src/main/java/me/ele/trojan/demo/DemoHook.java), we can achieve acquisition Http request and response functions in OkHttp, it can be used as a reference. As for business-related logs, users should collect by self.\n\n## Installation\n\nAdd in the root directory's build.gradle:\n\n```java\nbuildscript {\n    dependencies {\n        ......\n        classpath 'me.ele:lancet-plugin:1.0.2'\n    }\n}\n```\n\nAdd in the app directory's build.gradle:\n\n```java\napply plugin: 'me.ele.lancet'\n\ndependencies {\n    ......\n    provided 'me.ele:lancet-base:1.0.2'\n    compile 'me.ele:trojan-library:0.0.5'\n}\n```\n\n## Use\n\n### 1. Initialization\n\nAdd in the custom Application:\n\n```java\nTrojanConfig config = new TrojanConfig.Builder(this)\n    // Set user information\n    .userInfo(\"xxxx\")\n    // Set device id\n    .deviceId(\"xxxx\")\n    // Set cipher key if need encry log\n    .cipherKey(\"xxxx\")\n    // Optional, save log file in sdcard by default\n    .logDir(\"xxxx\")\n    // Console log switch, the default is open\n    .enableLog(true)\n    .build();\nTrojan.init(config);\n```\n\nSpecial Note:\n\n1. The log files are stored in sdcard by default and will not be lost even if the application is uninstalled;\n2. To be compatible with multiple processes, log files stored in their respective directories;\n3. The log is not encrypted by default, we currently only provide TEA encryption in view for high efficiency。\n\n### 2. Record the log\n\nTrojan provides two ways to recode log:\n\nFirstly:\n\n```java\nTrojan.log(\"Trojan\", \"We have a nice day!\");\n```\n\nSecondly:\n\n```java\nList\u003cString\u003e msgList = new LinkedList \u003c\u003e();\nmsgList.add(\"Hello Trojan!\");\nmsgList.add(\"We have a nice day!\");\nmsgList.add(\"Hello world!\");\nTrojan.log(\"Trojan\", msgList);\n```\n\nBy default, a single line log is not encrypted, and if you need to encrypt it, the following is used:\n\n```java\nTrojan.log(\"Trojan\", \"We have a nice day!\", true);\n```\n\n### 3. User Information\n\nWhen the user information changes or switch users, you can call:\n\n```java\nTrojan.refreshUser(\"new user info\");\n```\n\nOf course, if the user logs out, you can pass a null value:\n\n```java\nTrojan.refreshUser(null);\n```\n\n### 4. Upload Solution\n\nIn [Demo](https://github.com/ELELogistics/Trojan/blob/master/app/src/main/java/me/ele/trojan/demo/upload/DemoLeanCloudUploader.java) we provided free and simple way such as [LeanCloud](https://leancloud.cn/) to upload log file, you can browse, download and download log file.\n\n### 5. Data Decryption\n\nWhen we set the encryption key, we can encrypt a single log to ensure the security of sensitive data. We must decrypt the encrypted data When we analyze the log. Use the [decryption script](/decrypt/trojan_decrypt.py) as follows:\n\n1. Compile and generate decryption SO library on MAC, The so library has been generated in the repository. This step can be omitted:\n    \n    ```java\n    gcc -shared -Wl,-install_name,trojan_decrypt.so -o trojan_decrypt.so -fPIC trojan_decrypt.c\n    \n    ```\n2. Call python script to decrypt the data on MAC, you need to pass in the decryption key and file path to be decrypted, it should be noted that the path of the python script:\n\n    ```java\n    python ./trojan_decrypt.py cipher-key cipher-file-path\n    \n    ```\n    \n## PS\n\nThrough the above steps, you can integrate [Trojan](https://github.com/ELELogistics/Trojan) SDK to record user's log, That is very simple! If you have any questions about the use of Lancet, you can get more details by [Readme](https://github.com/eleme/lancet/blob/dev/README_zh.md).\n\n## License\n\n![](/assets/trojan_license.png)\n\nTrojan is available under the Apache-2.0 license. See the [LICENSE](/LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleme%2Ftrojan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feleme%2Ftrojan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleme%2Ftrojan/lists"}