lib/lazylead/log.rb in lazylead-0.3.1 vs lib/lazylead/log.rb in lazylead-0.4.0

- old
+ new

@@ -21,20 +21,42 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE # OR OTHER DEALINGS IN THE SOFTWARE. require "logging" +require "forwardable" module Lazylead - # Loggers. + # The main application logger + class Log + extend Forwardable + def_delegators :@log, :debug, :info, :warn, :error + + def initialize(log = Lazylead::Level::ERRORS) + @log = log + @log = Lazylead::Level::DEBUG if ARGV.include? "--trace" + end + + def nothing + @log = Lazylead::Level::NOTHING + self + end + + def verbose + @log = Lazylead::Level::DEBUG + self + end + end + + # Predefined logging levels. # # There are 3 colored loggers so far: # NOTHING - for cases when logging isn't required # VERBOSE - all logging levels including debug # ERRORS - for errors only which are critical for app. # - module Log + module Level # Coloring configuration for appender(s). Logging.color_scheme("bright", levels: { info: :green, warn: :yellow, @@ -44,26 +66,26 @@ date: :blue, logger: :cyan) Logging.appenders.stdout( "stdout", layout: Logging.layouts.pattern( - pattern: "[%d] %-5l %m\n", + pattern: "[%d] %-5l [%X{tid}] %m\n", color_scheme: "bright" ) ) # Nothing to log NOTHING = Logging.logger["nothing"] NOTHING.level = :off NOTHING.freeze # All levels including debug - VERBOSE = Logging.logger["verbose"] - VERBOSE.level = :debug - VERBOSE.add_appenders "stdout" - VERBOSE.freeze + DEBUG = Logging.logger["debug"] + DEBUG.level = :debug + DEBUG.add_appenders "stdout" + DEBUG.freeze - # Alerts + # Alerts/errors ERRORS = Logging.logger["errors"] ERRORS.level = :error ERRORS.add_appenders "stdout" ERRORS.freeze end