Skip to content

Commit

Permalink
Upgrade MG
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalexling committed Jan 17, 2021
1 parent 7507ab6 commit b471ed2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ shards:

mg:
git: https://github.com/hkalexling/mg.git
version: 0.1.0+git.commit.8d378bf58da442be2e5a27670233d43687d14121
version: 0.2.0+git.commit.171c46489d991a8353818e00fc6a3c4e0809ded9

myhtml:
git: https://github.com/kostya/myhtml.git
Expand Down
9 changes: 3 additions & 6 deletions src/logger.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ class Logger
SEVERITY_IDS = [0, 4, 5, 2, 3]
COLORS = [:light_cyan, :light_red, :red, :light_yellow, :light_magenta]

getter raw_log = Log.for ""

@@severity : Log::Severity = :info

use_default

def initialize
@@severity = Logger.get_severity
@log = Log.for("")
@backend = Log::IOBackend.new

format_proc = ->(entry : Log::Entry, io : IO) do
Expand Down Expand Up @@ -54,10 +55,6 @@ class Logger
{% end %}
end

def self.reset
@@default = Logger.new
end

# Ignores @@severity and always log msg
def log(msg)
@backend.write Log::Entry.new "", Log::Severity::None, msg,
Expand All @@ -70,7 +67,7 @@ class Logger

{% for lvl in LEVELS %}
def {{lvl.id}}(msg)
@log.{{lvl.id}} { msg }
raw_log.{{lvl.id}} { msg }
end
def self.{{lvl.id}}(msg)
default.not_nil!.{{lvl.id}} msg
Expand Down
6 changes: 1 addition & 5 deletions src/storage.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ class Storage
DB.open "sqlite3://#{@path}" do |db|
begin
severity = Logger.get_severity
Log.setup "mg", severity
MG::Migration.new(db).migrate
MG::Migration.new(db, log: Logger.default.raw_log).migrate
rescue e
Logger.reset
Logger.fatal "DB migration failed. #{e}"
raise e
else
Logger.reset
end

user_count = db.query_one "select count(*) from users", as: Int32
Expand Down

0 comments on commit b471ed2

Please sign in to comment.