[Snippet] [devHelper] Logger

2 843 Views No Comments 4 years ago
  • Here it is; the humble hunchback of the debugger: LOGGER.

    Logger is a simple class object, which brings depth to debugging.
    You can follow execution paths and trace bugs with precision.

    Installation: Simply copy and paste the snippet to your project! Just make sure Logger and its functions are defined before they are used.

    Functions:
    * Logger:log() – Normal log, as long as logger level is set to [All].
    * Logger:warn() – Warning log, as long as logger level is set to [All] or [Errors & Warnings].
    * Logger:error() – Error log.
    * Logger:enter() – Enter new scope. Will be added to the scope-path when logging messages.
    * Logger:exit() – Exit the current scope. Will remove the latest entry from the scope-path.

    Rest of the functions are for Logger’s internal use only.

    Usage:

    
    -- normal log msg
    Logger:log('we are in Main, and this only shows when we log All')
    
    -- normal log msg with color
    Logger:log('logger supports colors as well', Green)
    
    function doSomething()
         -- enter new scope
        Logger:enter('doSomething')
    
        -- log a warning
        Logger:warn('this time we warn something at Main::doSomething')
    
        -- exit current scope
        Logger:exit()
    end
    
    doSomething()
    
    -- log an error
    Logger:error('execution stops here')
    
    HaasScript Code
    Sign in or Register to download for free
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free