[Gambas-user] New gb.logging component

Jesus ea7dfh at ...2382...
Tue May 21 20:07:03 CEST 2013


El 20/05/13 04:44, Sebastian Kulesz escribió:
> Hey there!
>
> I just pushed the new component to the svn repository. It provides a
> flexible API for logging and tracking events while the software is running.
>
> It outputs to stdout by default, but you can simply point to a file when
> creating an instance of the Logger object.
>
> It provides 5 levels of severity, them being: Critical, Error, Warning,
> Info, Debug
> You can control the output by providing the minimum level required. For
> example, if the minimum level is Warning, only Warning, Error and Critical
> messages will be printed (or saved to the file)
>
> Another great feature is a flexible formatted output. When creating an
> instance, you can pass a string which will tell the logger how the string
> will be formatted. A single tag is represented as "$(TAG)". The default one
> is:
>
> [$(now)] [$(levelname)] [$(callLocation)] $(message)
>
> So, the message "Starting logger" would look like this:
>
> [05/20/2013 02:13:46.267] [WARNING] [MTest.Main.9] Starting logger
>
> The following tags are available as of now:
>
> $(message) : The message passed to the logger
> $(callLocation) : The full location of where the logger was called. In the
> form of FILE.FUNCTION.LINE (look above at the example line)
> $(callLine) : The line number where the logger was called.
> $(callFile) : The file name which called the logger
> $(callFunction) :The function which called the logger
> $(now) : A full date and time string, as returned by Now()
> $(date) : The date as returned by Date(Now)
> $(time) : The time as returned by Time(Now)
> $(ptimer) : The time elapsed since the application was started. ms of
> precision
> $(ptimerint) : Same as above, but only prints the elapsed time in seconds
> $(levelno) : The severity level of the message (integer)
> $(levelname) : The name of the severity level One of: CRITICAL,ERROR,
> WARNING,INFO,DEBUG
> $(version) : The version of the application
> $(gbversion) : The version of the Gambas interpreter
> $(host) : The system host name
> $(pid) : The process id of the running application
>
> Using it is pretty straightforward:
>
>    Dim oDumb As New Logger
>    oDumb("Starting logger")
>
> By default the component creates a hidden instance of the Logger class,
> just as the Settings component does, but i'm having trouble when performing
> the call. It's not a deal breaker, it only means you won't be able to call
> Logger(...) directly, but will need to create an instance and share it
> across your application.
>
> If you already have a logging module implemented and don't want to switch,
> you can still use the Formatter class and all the tags it comes with by
> simply calling Formatter(sMessage As String, sFormat As String, iLevel As
> Integer) Being sMessage the message you want to log, sFormat the formatting
> string and iLevel an integer value of the severity so 0=Critical and
> 4=Debug.
>
> Hope you find it useful. If you want any tags added, please let me know, or
> go ahead and implement them yourself!! It's not hard, i promise!

Great addition!!

Thanks for your work, definitely it is something I will use for sure.

Regards

-- 
Jesus Guardon




More information about the User mailing list