Skip to content

Instantly share code, notes, and snippets.

@RikiyaOta
Created December 31, 2018 01:42
Show Gist options
  • Save RikiyaOta/948f97392b47eaedeb780630af3eb9aa to your computer and use it in GitHub Desktop.
Save RikiyaOta/948f97392b47eaedeb780630af3eb9aa to your computer and use it in GitHub Desktop.
implement Plugs for setting log file path dinamically
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :set_log1_file_daily
plug :set_log2_file_daily
end
defp set_log1_file_daily(conn, _opts) do
today = Timex.now("Japan") |> Timex.format!("{YYYY}{0M}{0D}")
Logger.configure_backend {LoggerFileBackend, :log1},
path: Path.join([File.cwd!, "var", "log", "log1-#{today}.log"])
conn #Plug should return conn.
end
defp set_log2_file_daily(conn, _opts) do
today = Timex.now("Japan") |> Timex.format!("{YYYY}{0M}{0D}")
Logger.configure_backend {LoggerFileBackend, :log2},
path: Path.join([File.cwd!, "var", "log", "log2-#{today}.log"])
conn #Plug should return conn.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment