{"id":16474345,"url":"https://github.com/ibreakthecloud/redactrus","last_synced_at":"2025-03-23T11:32:51.826Z","repository":{"id":247910288,"uuid":"827205506","full_name":"ibreakthecloud/redactrus","owner":"ibreakthecloud","description":"Go package for redacting sensitive info in Logrus logs.","archived":false,"fork":false,"pushed_at":"2025-03-05T07:53:33.000Z","size":17,"stargazers_count":5,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T20:08:04.872Z","etag":null,"topics":["golang","hacktoberfest","logging","logrus","redact","security"],"latest_commit_sha":null,"homepage":"","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/ibreakthecloud.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":"2024-07-11T07:45:36.000Z","updated_at":"2024-09-30T15:44:30.000Z","dependencies_parsed_at":"2024-10-28T16:09:53.644Z","dependency_job_id":"4bc03d9a-24d5-4f5c-852b-d7d398ff5368","html_url":"https://github.com/ibreakthecloud/redactrus","commit_stats":null,"previous_names":["ibreakthecloud/redactrus"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibreakthecloud%2Fredactrus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibreakthecloud%2Fredactrus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibreakthecloud%2Fredactrus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibreakthecloud%2Fredactrus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibreakthecloud","download_url":"https://codeload.github.com/ibreakthecloud/redactrus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"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":["golang","hacktoberfest","logging","logrus","redact","security"],"created_at":"2024-10-11T12:31:06.871Z","updated_at":"2025-03-23T11:32:51.549Z","avatar_url":"https://github.com/ibreakthecloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redactrus\n\nRedactrus is a custom formatter for the [logrus](https://github.com/sirupsen/logrus) logging library, designed to redact sensitive information from your logs. It allows you to define custom redaction functions that can be applied to your log messages, ensuring that sensitive data does not get exposed in your log output.\n\n## Features\n\n- **Custom Redaction Functions**: Define your own redaction logic tailored to your application's needs.\n- **Flexible Redaction**: Add single or multiple redactors to your formatter.\n- **Easy Integration**: Seamlessly integrates with the logrus logging library.\n\n## Getting Started\n\nTo use Redactrus in your project, follow these steps:\n\n### Installation\n\nFirst, ensure you have logrus installed:\n\n```sh\ngo get github.com/sirupsen/logrus\n```\n\nThen, add Redactrus to your project:\n\n```sh\ngo get github.com/ibreakthecloud/redactrus\n```\n\n### Usage\n\n1. Create a Redacting Formatter:\u003cbr\u003e\n   You can create a new RedactingFormatter by passing an existing logrus formatter that you wish to wrap. For example, to use logrus's JSONFormatter:\n\n```go\nimport (\n    \"github.com/sirupsen/logrus\"\n    \"github.com/ibreakthecloud/redactrus\"\n)\n\nfunc main() {\n    log := logrus.New()\n    formatter := redactrus.NewRedactingFormatter(\u0026logrus.JSONFormatter{})\n    log.SetFormatter(formatter)\n}\n```\n\n2. Add Redaction Functions:\u003cbr\u003e\n   Define your redaction functions and add them to the formatter:\n\n```go\nfunc myRedactor(originalMsg, redactWith string) string {\n    // Implement your redaction logic here\n    return originalMsg // Return the redacted message\n}\n\nfunc main() {\n    // Assuming log and formatter are already set up\n    formatter.AddRedactor(myRedactor)\n}\n```\n\n3. Log Messages:\u003cbr\u003e\n   Use logrus as usual, and your logs will be redacted according to your defined rules.\n\n```go\nlog.Info(\"This is a log message with password=password123, api_key=abcdef123456, and email=test@example.com.\")\n```\n\n## RedactingFormatter\n\nRedactingFormatter is a struct that embeds logrus.Formatter and includes redaction functions.\n\n### Methods\n\n- `NewRedactingFormatter(innerFormatter logrus.Formatter) *RedactingFormatter`\n\n  - Creates a new `RedactingFormatter`.\n\n- `NewDefaultRedactingFormatter(innerFormatter logrus.Formatter) *RedactingFormatter`\n\n  - Creates a new `RedactingFormatter` with default redactors.\n\n- `AddRedactor(redactor RedactionFunc) *RedactingFormatter`\n\n  - Adds a new redaction function to the `RedactingFormatter`.\n\n- `AddRedactors(redactors ...RedactionFunc) *RedactingFormatter`\n\n  - Adds multiple redaction functions to the `RedactingFormatter`.\n\n- `SetRedactWith(r string) *RedactingFormatter`\n  - Sets the string to redact sensitive information with.\n\n## Default Redactors\n\nThe defaultRedactors function returns a slice of default redaction functions: Password, APIKey, and Email.\n\n### Functions\n\n- `Password(msg string, r string) string`\n  - Redacts the password from a log message.\n- `APIKey(msg string, r string) string`\n  - Redacts the API key from a log message.\n- `Email(msg string, r string) string`\n  - Redacts the email from a log message\n\n## Custom Redaction Functions\n\nYou can define your own redaction functions to redact sensitive information from your log messages. A redaction function takes the original log message and the string to redact sensitive information with, and returns the redacted log message.\n\n### Example\n\n```go\nfunc GitHubToken(msg string, r string) string {\n    tokenRegex := regexp.MustCompile(`^(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$`)\n    return tokenRegex.ReplaceAllString(msg, r)\n}\n```\n\n## Contributing\n\nContributions are welcome! If you have ideas for more custom redactors, it would be awesome to have you contribute them. Feel free to open an issue or submit a pull request. Your contributions can help make Redactrus even more useful for everyone and logging more secure.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibreakthecloud%2Fredactrus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibreakthecloud%2Fredactrus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibreakthecloud%2Fredactrus/lists"}