{"id":28365029,"url":"https://github.com/joylinks/logger","last_synced_at":"2025-09-14T07:00:17.653Z","repository":{"id":262953742,"uuid":"888880792","full_name":"JoyLinks/logger","owner":"JoyLinks","description":"日志输出","archived":false,"fork":false,"pushed_at":"2025-08-30T09:56:27.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-30T10:18:36.703Z","etag":null,"topics":["access","china","clf","log","logger"],"latest_commit_sha":null,"homepage":"http://www.joyzl.com","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/JoyLinks.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,"zenodo":null}},"created_at":"2024-11-15T07:25:13.000Z","updated_at":"2025-08-30T09:56:30.000Z","dependencies_parsed_at":"2025-05-09T07:29:17.872Z","dependency_job_id":"e3c6e269-0bc1-42fe-93e7-41b136f970d0","html_url":"https://github.com/JoyLinks/logger","commit_stats":null,"previous_names":["joylinks/logger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JoyLinks/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoyLinks%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoyLinks%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoyLinks%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoyLinks%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoyLinks","download_url":"https://codeload.github.com/JoyLinks/logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoyLinks%2Flogger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275071516,"owners_count":25400398,"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-14T02:00:10.474Z","response_time":75,"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":["access","china","clf","log","logger"],"created_at":"2025-05-28T21:09:43.497Z","updated_at":"2025-09-14T07:00:17.623Z","avatar_url":"https://github.com/JoyLinks.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JOYZL logger\n\n轻量化高性能（部分）日志组件，没有任何其它依赖。\n日志字符编码固定为UTF-8。\n\n### Logger\n\n常规日志，用于热点代码之外同步输出运行日志。\n* 支持 ERROR INFO DEBUG 三级日志；\n* 支持控制台同步输出；\n* 支持网络端口同步发送；\n* 自动按日期切分日志文件；\n* 支持清理过期的日志文件；\n* 全局静态无须实例化。\n\n```log\n12:41:53.883\tmain\tINFOM\tTEST\n```\n\n从左至右含义为：时间 线程名 消息类型 内容文本，前三个字段固定。\n\n### AccessLogger\n\n访问日志，采用异步模式尽可能减少对业务性能的影响；\n与 Apache Common Log Format 类似但不完全相同，采用固定的格式输出，每行首添加时间戳以便于检索，不支持格式配置。\n* 自动按日期切分日志文件；\n* 支持按时间段从生成的日志文件检索日志；\n* 支持清理过期的日志文件；\n* 支持按需多实例。\n\n日志输出格式样例：\n\n```log\n1749550882032 18:21:22.32 80 www.joyzl.com 192.168.0.1 GET /web HTTP/1.1 0 WEBDAV 0 200 0\n```\n\n从左至右含义为：请求时间戳(UTC) 时间 服务器端口 客户端地址 请求方法 请求路径 协议版本 请求体字节数 服务程序 处理用时（毫秒） 响应状态 响应体字节数\n\n```java\nfinal AccessLogger logger = new AccessLogger(\"access\\\\acs.log\");\nlogger.record(new AccessRecord(){\n\t// 字段值\n\tpublic int getServerPort(){\n\t\treturn 80;\n\t}\n\t...\n});\n\n```\n\n### CommonLogger\n\n符合 RFC6872, RFC6873 规范的CLF(Common Log Format)日志，采用同步输出以确保日志被如实记录；\n对业务性能有影响，适用于强日志场景。\n* 自动按日期切分日志文件；\n* 支持按时间段从生成的日志文件检索日志；\n* 支持清理过期的日志文件；\n* 支持按需多实例。\n\n日志输出格式样例：\n\n```log\nA000493,0053005C005E006D007D008F009E00A000BA00C700EB00F70100\n1328821153.010\tRORUU\t1 INVITE\t-\tsip:192.0.2.10\t192.0.2.10:5060\t192.0.2.200:56485\tsip:192.0.2.10\t-\tsip:1001@example.com:5060\tDL88360fa5fc\tDL70dff590c1-1079051554@example.com\tS1781761-88\tC67651-11\t00@00000000,001C,00,Contact: \u003csip:bob@192.0.2.4\u003e\t00@00000000,0016,00,Reason-Phrase: Ringing\t01@00000000,00A9,00,application/sdp v=0%0D%0Ao=alice 2890844526 2890844526 IN IP4 host.example.com%0D%0As=-%0D%0Ac=IN IP4 host.example.com%0D%0At=0 0%0D%0Am=audio 49170 RTP/AVP 0 8 97%0D%0A\t01@00000000,0216,01,multipart/mixed;boundary=7a9cbec02ceef655 MIIBUgYJKoZIhvcNAQcCoIIBQzCCAT8CAQExCTAHBgUrDgMCGjALBgkqhkiG9w0BBwExggEgMIIB%0D%0AHAIBATB8MHAxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMREwDwYDVQQHEwhTYW4g%0D%0ASm9zZTEOMAwGA1UEChMFc2lwaXQxKTAnBgNVBAsTIFNpcGl0IFRlc3QgQ2VydGlmaWNhdGUgQXV0%0D%0AaG9yaXR5AggBlQBxAjMBEzAHBgUrDgMCGjANBgkqhkiG9w0BAQEFAASBgI70ZvlI8FIt0uWXjp2V%0D%0Aquny/hWgZllxYpLo2iqo2DUKaM7/rjy9K/8Wdd3VZI5ZPdZHKPJiIPfpQXSeMw2aFe2r25PRDEIQ%0D%0ALntyidKcwMmuLvvHwM/5Fy87An5PwCfhVG3ktqo6uz5mzMtd1sZLg4MUnLjm/xgtlE/le2W8mdAF%0D%0A\t03@00032473,0014,00,a=rtpmap:0 PCMU/8000\t07@00032473,0010,00,1877 example.com\n```\n\n\n```java\nfinal CommonLogger logger = new CommonLogger(\"common\\\\clf.log\");\nlogger.record(new CommonRecord(){\n\t// 字段值\n\tpublic char getDirection(){\n\t\treturn CommonCodes.RECEIVED;\n\t}\n\t...\n});\n\n```\n\n\n### 日志文件过期删除\n\nLoggerService 类提供日志过期删除功能，默认保留30天的日志文件，以防止过多的日志文件导致存储空间紧张。\n日志组件没有自动建立守护进程以自动运行清理功能，需要此功能时应在守护进程定时调用清理方法 LoggerService.clean()，\n此方法将返回 LoggerCleaner 对象实例，可获取删除的文件数量和释放的存储空间。\n\n日志有效期为全局参数，将同时清理 Logger 、AccessLogger 和 CommonLogger 当前产生的日志；\n注意：仅能清理运行时日志实例关联输出的目录中的日志文件；\n不要将其它文件放入日志目录中，清理程序根据文件扩展名判断日志文件，以防你的文件被意外删除。\n\n```log\nLoggerCleaner c = LoggerService.clean();\nSystem.out.println(c);\n```\n\n### 日志配置\n\n没有默认配置文件，如果需要可以自定义配置文件，将其读取后通过日志对象设置；\n参数支持运行时设置，设置的参数将立即生效并影响之后的日志输出。\n\n```java\n// 设置日志级别 ERROR=1,INFO=2,DEBUG=3\n// 设置级别为0将不会输出任何日志，大于3的值等同于3\nLogger.setLevel(3);\n\n// 设置输出异常时的缩进\nLogger.setIndent(\"------------\");\n\n// 设置分隔符，仅用于固定字段\nLogger.setTab('\\t');\n\n// 设置换行符\nLogger.setLine('\\n');\n\n// 设置控制台输出\nLogger.setConsole(true);\n\n// 设置日志目录和文件名\n// 生成日志文件：当前程序目录\\log\\joyzl-20250611.log\nLogger.setFile(\"log\", \"joyzl\", \".log\");\n\n// 生成日志文件：当前程序目录\\20250611.log\nLogger.setFile(\"\", null, \".log\");\n\n// 生成日志文件：当前程序目录\\20250611\nLogger.setFile(\"\", null, null);\n\n// 如果目录为null将关闭文件输出\nLogger.setFile(null, null, null);\n\n// 设置日志输出的网络目标(UDP)\nLogger.setUDP(\"192.168.0.2\", 8210);\n\n// 如果主机为null或端口为0将关闭网络输出\nLogger.setUDP(null, 0);\n\n// 输出日志\nLogger.info(\"test\");\nLogger.debug(\"text1\",\"text2\");\nLogger.error(\"text1\");\nLogger.error(new Exception(\"TEST\"));\n\n\n// 设置日志过期天数\nLoggerService.setExpires(30);\n// 清理过期日志\n// 如果有 AccessLogger 和 CommonLogger 实例，其输出的日志也将被清理。\nLoggerService.clean();\n\n\n```\n\n---\n[www.joyzl.com](http://www.joyzl.com)\n\nCopyright © 2017-2025 重庆骄智科技有限公司.\n本软件根据 Apache License 2.0 开源，详见 LICENSE 文件。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoylinks%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoylinks%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoylinks%2Flogger/lists"}