-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
179 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
defmodule LoggerJSON.Formatter do | ||
@callback format(event :: :logger.log_event(), opts :: term()) :: iodata() | ||
@type opts :: [ | ||
{:metadata, :all | {:all_except, [atom()]} | [atom()]} | ||
| {:redactors, [{module(), term()}]} | ||
| {atom(), term()} | ||
] | ||
|
||
@callback format(event :: :logger.log_event(), opts :: opts()) :: iodata() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule LoggerJSON.Redactor do | ||
@moduledoc """ | ||
This module provides a behaviour which allows to redact sensitive information from logs. | ||
Note: redactor will not be applied on `Jason.Fragment` structs. | ||
""" | ||
|
||
@doc """ | ||
Takes a key and a value and returns a redacted value. | ||
This callback will be applied on key-value pairs, like elements of structs, maps or keyword lists. | ||
""" | ||
@callback redact(key :: term(), value :: term(), opts :: term()) :: term() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule LoggerJSON.Redactors.RedactKeys do | ||
@moduledoc """ | ||
A simple redactor which replace the value of the keys with `"[REDACTED]"`. | ||
It takes list of keys to redact as an argument, eg.: | ||
```elixir | ||
config :logger, :default_handler, | ||
formatter: {LoggerJSON.Formatters.Basic, redactors: [ | ||
{LoggerJSON.Redactors.RedactKeys, ["password"]} | ||
]} | ||
``` | ||
Keep in mind that LoggerJSON will convert key type to string before comparing it | ||
with the list of keys to redact. | ||
""" | ||
|
||
@behaviour LoggerJSON.Redactor | ||
|
||
def redact(key, value, keys) do | ||
if key in keys do | ||
"[REDACTED]" | ||
else | ||
value | ||
end | ||
end | ||
end |
Oops, something went wrong.