Skip to content

Commit

Permalink
Lower log clear threshhold
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Rigby committed Sep 11, 2018
1 parent 531e90c commit cfd724e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
10 changes: 3 additions & 7 deletions config/config.exs
Expand Up @@ -11,13 +11,9 @@ config :logger, [
backends: [:console]
]

# Randomly picked 300 megabytes.
# 3964928 bytes == ~4 megabytes in sqlite3
# 9266 logs = ~4 megabytes
# 4 logs * 75 = 300 megabytes
# 9266 logs * 75 = 694950 logs
# This will trim 175000 logs (25%) every time it gets to the max logs.
config :logger_backend_ecto, max_logs: 700000
# 700 bytes / log
# 100,000 logs * 700 bytes ~= 70 megabytes
config :logger_backend_ecto, max_logs: 100000

# Stop lager redirecting :error_logger messages
config :lager, :error_logger_redirect, false
Expand Down
25 changes: 25 additions & 0 deletions lib/farmbot/logger/logger.ex
Expand Up @@ -4,6 +4,31 @@ defmodule Farmbot.Logger do
"""
use GenStage

def how_many_logs do
alias IO.ANSI
alias LoggerBackendEcto.{Repo, Log}
import Ecto.Query

count = Repo.one(from f in Log, select: count(f.id))
total = Application.get_env(:logger_backend_ecto, :max_logs)
size_mb = File.stat!(Repo.config[:database]).size * 1.0e-6

IO.puts [
ANSI.clear(), ANSI.home(), ANSI.blue(),
"logs: ", ANSI.green(), to_string(count), " / ", to_string(total),

"\r\n", ANSI.blue(),
"size: ", ANSI.green(), to_string(size_mb),

"\r\n", ANSI.blue(), "\r\n",
"prediction: ", ANSI.green(), to_string(total / count),
"\r\n", ANSI.blue(),

"size: ", ANSI.green(), to_string((total / count) * size_mb),
"\r\n", ANSI.normal()
]
end

def format_logs do
RingLogger.get()
|> Enum.map(fn({level, {_logger, message, timestamp_tup, _meta}}) ->
Expand Down

0 comments on commit cfd724e

Please sign in to comment.