From e107825c599e402f6d345b9d670718b0c3a97676 Mon Sep 17 00:00:00 2001 From: xaseiresh Date: Wed, 12 Apr 2023 10:04:05 +0200 Subject: [PATCH] feat: :sparkles: add builtin log function --- lib/comfpile/artefact.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/comfpile/artefact.rb b/lib/comfpile/artefact.rb index e33ea6b..94afe99 100644 --- a/lib/comfpile/artefact.rb +++ b/lib/comfpile/artefact.rb @@ -61,6 +61,8 @@ module Comfpile @included_artefacts = [] @referenced_artefacts = [] + @log_current_level = :debug + @log_current_line = "Not started..." @steps = [] @step_additions = nil @@ -86,6 +88,30 @@ module Comfpile @parameters[key] = value end + # + # Log an event for this artefact. + # Saves the given argument as log line, + # optionally prints it to a logger. Use this to + # save state progress messages as well as + # error messages. + # + # @param [String] text Text message to log + # @param [Symbol] state Level to log at. Known levels + # are: + # - :debug + # - :info + # - :warning + # - :error + # + def log(text, level = :debug) + @log_current_line = text + @log_current_level = level + + puts "> #{@state} #{@target}: #{text}" + + nil + end + private def add_step_data(data) @step_additions ||= []