{"id":26452967,"url":"https://github.com/goapt/logger","last_synced_at":"2026-05-08T15:02:07.050Z","repository":{"id":52441711,"uuid":"138748288","full_name":"goapt/logger","owner":"goapt","description":"golang logger","archived":false,"fork":false,"pushed_at":"2026-01-14T02:57:47.000Z","size":98,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-14T05:39:15.607Z","etag":null,"topics":["go-lang","logrus","sentry"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/goapt.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}},"created_at":"2018-06-26T14:15:42.000Z","updated_at":"2026-01-14T02:54:31.000Z","dependencies_parsed_at":"2022-08-18T07:00:49.935Z","dependency_job_id":null,"html_url":"https://github.com/goapt/logger","commit_stats":null,"previous_names":["verystar/logger","ilibs/logger"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/goapt/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goapt","download_url":"https://codeload.github.com/goapt/logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Flogger/sbom","scorecard":{"id":432782,"data":{"date":"2025-08-11","repo":{"name":"github.com/goapt/logger","commit":"4d0330c5e22c7d300dd511f8d6b1b0bdb0585887"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/goapt/logger/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/goapt/logger/main.yml/master?enable=pin","Warn: downloadThenRun not pinned by hash: .github/workflows/main.yml:24","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 downloadThenRun dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 12 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T03:45:55.626Z","repository_id":52441711,"created_at":"2025-08-19T03:45:55.626Z","updated_at":"2025-08-19T03:45:55.626Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28492593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T02:39:23.645Z","status":"ssl_error","status_checked_at":"2026-01-17T02:34:19.649Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["go-lang","logrus","sentry"],"created_at":"2025-03-18T18:40:55.722Z","updated_at":"2026-05-08T15:02:07.037Z","avatar_url":"https://github.com/goapt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logger\n\n\u003cp\u003e\n\u003ca href=\"https://github.com/goapt/logger/actions\"\u003e\u003cimg src=\"https://github.com/goapt/logger/workflows/build/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/goapt/logger\"\u003e\u003cimg src=\"https://codecov.io/gh/goapt/logger/branch/master/graph/badge.svg\" alt=\"codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/goapt/logger\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/goapt/logger\" alt=\"Go Report Card\n\"\u003e\u003c/a\u003e\n\u003ca href=\"https://godoc.org/github.com/goapt/logger\"\u003e\u003cimg src=\"https://godoc.org/github.com/goapt/logger?status.svg\" alt=\"GoDoc\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/mit-license.php\" rel=\"nofollow\"\u003e\u003cimg src=\"https://badges.frapsoft.com/os/mit/mit.svg?v=103\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nGolang logger,use log/slog, support logroate\n\n## Default logger\n\ndefault log out to os.Stderr\n\n```go\nimport \"github.com/goapt/logger\"\n\nfunc main(){\n    logger.New(\u0026logger.Config{\n        Mode: logger.ModeStd,\n        Level: slog.LevelInfo,\n    })\n}\n```\n\n## Setting default logger\n\n```\nlogger.SetDefault(logger.New(\u0026logger.Config{\n    Mode: logger.ModeFile,\n    Level: slog.LevelInfo,\n    FileName: \"app.log\",\n    Detail: true,\n}))\n```\n\n## Usage logger\n\n```\n// global logger\nlogger.Default().Info(\"this is new log\",slog.String(\"key\",\"value\"))\n\n// or\nfunc Foo(log *slog.Logger) {\n    log.Info(\"this is new log\",slog.String(\"key\",\"value\"))\n}\nFoo(logger.Default())\n```\n\n## Print filename and line no\n\nif `Detail` is true,the log data add filename and line no\n\n```\n{\"file\":\"/Users/fifsky/wwwroot/go/library/src/github.com/fifsky/goblog/handler/index.go\",\"func\":\"handler.IndexGet\",\"level\":\"debug\",\"line\":16,\"msg\":\"[test]\",\"time\":\"2018-08-02 22:37:02\"}\n```\n\n# Record the logs of the HTTP Handler and HTTP Client\n\nUse sloghttp to record HTTP server and client request/response data as structured logs for observability and search. Supports request ID correlation, request/response body capture with truncation, sensitive header redaction, flexible filters, and OpenTelemetry Trace/Span extraction. Code forked from https://github.com/samber/slog-http, with additional support for HTTP client logging.\n\n## Server Handler Logging\n\n```go\npackage main\n\nimport (\n    \"log/slog\"\n    \"net/http\"\n\n    \"github.com/goapt/logger\"\n    \"github.com/goapt/logger/sloghttp\"\n)\n\nfunc main() {\n    // Initialize default logger (JSON to stdout)\n    logger.SetDefault(logger.New(\u0026logger.Config{\n        Mode:   logger.ModeStd,\n        Level:  slog.LevelInfo,\n        Detail: false,\n    }))\n\n    // Configure HTTP logging middleware (enable fields as needed)\n    cfg := sloghttp.DefaultConfig\n    cfg.Level = slog.LevelInfo     // log level for HTTP logs\n    cfg.WithRequestBody = false    // capture request body (on by default; truncated)\n    cfg.WithResponseBody = false   // capture response body (on by default; truncated)\n    cfg.WithRequestHeader = false  // include request headers (sensitive headers redacted)\n    cfg.WithResponseHeader = false // include response headers (sensitive headers redacted)\n\n    // Optional: filter routes/methods/status codes you don’t want to log\n    // cfg.Filters = []sloghttp.Filter{\n    //     sloghttp.IgnorePathPrefix(\"/health\", \"/metrics\"),\n    //     sloghttp.IgnoreMethod(http.MethodOptions),\n    // }\n\n    mw := sloghttp.NewMiddleware(logger.Default(), cfg)\n\n    mux := http.NewServeMux()\n    mux.HandleFunc(\"/hello\", func(w http.ResponseWriter, r *http.Request) {\n        // Enrich with business attributes via Context; included in logs\n        ctx := sloghttp.NewContextAttributes(r.Context(), slog.String(\"user_id\", \"123\"))\n        r = r.WithContext(ctx)\n\n        // Retrieve request ID for business log correlation\n        reqID := sloghttp.GetRequestID(r)\n        logger.Default().Info(\"handle hello\", slog.String(\"request_id\", reqID))\n\n        w.Write([]byte(\"ok\"))\n    })\n\n    // Start server with middleware\n    _ = http.ListenAndServe(\":8080\", mw(mux))\n}\n```\n\n## HTTP Client Logging\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log/slog\"\n    \"net/http\"\n    \"strings\"\n\n    \"github.com/goapt/logger\"\n    \"github.com/goapt/logger/sloghttp\"\n)\n\nfunc main() {\n    logger.SetDefault(logger.New(\u0026logger.Config{\n        Mode:  logger.ModeStd,\n        Level: slog.LevelInfo,\n    }))\n\n    cfg := sloghttp.DefaultConfig\n    cfg.Level = slog.LevelInfo   // log level for HTTP logs\n    cfg.WithRequestBody = true   // capture client request body\n    cfg.WithResponseBody = true  // capture client response body\n\n    // Wrap Transport with sloghttp RoundTripper\n    rt := sloghttp.NewRoundTripper(logger.Default(), http.DefaultTransport, cfg)\n    client := \u0026http.Client{Transport: rt}\n\n    ctx := sloghttp.NewContextAttributes(context.Background(), slog.String(\"order_id\", \"A1001\"))\n    req, _ := http.NewRequestWithContext(ctx, http.MethodPost, \"http://example.com/api\", strings.NewReader(\"payload\"))\n    res, err := client.Do(req)\n    if err != nil {\n        logger.Default().Error(\"http request failed\", slog.String(\"error\", err.Error()))\n        return\n    }\n    defer res.Body.Close()\n}\n```\n\n## Advanced\n\n- Sensitive headers are redacted by default: authorization/cookie/x-auth-token, etc.\n- Customize capture size: adjust global max bytes for request/response body.\n\n```go\n// Max bytes captured for request/response bodies (default 64KB)\nsloghttp.RequestBodyMaxSize = 128 * 1024\nsloghttp.ResponseBodyMaxSize = 128 * 1024\n```\n\n- OpenTelemetry integration: when `span.IsRecording()` is true, `trace_id` and `span_id` are recorded automatically.\n\n## Config Fields\n\n- Level: control log level\n- WithUserAgent / WithRequestBody / WithRequestHeader: request switches\n- WithResponseBody / WithResponseHeader: response switches\n- request_id: always generated/propagated via `X-Request-Id` header\n- trace_id/span_id: auto extracted when `span.IsRecording()` is true\n- Filters: plug Accept*/Ignore* filters (method, path, status, host, etc.)\n\nFilter example:\n\n```go\ncfg.Filters = []sloghttp.Filter{\n    sloghttp.IgnorePathPrefix(\"/health\", \"/metrics\"),\n    sloghttp.IgnoreMethod(http.MethodOptions),\n    sloghttp.AcceptStatusGreaterThanOrEqual(http.StatusBadRequest),\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoapt%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoapt%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoapt%2Flogger/lists"}