Autore Topic: Nuovo componente: gb.logging  (Letto 588 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.334
  • Ne mors quidem nos iunget
    • Mostra profilo
Nuovo componente: gb.logging
« il: 20 Maggio 2013, 11:01:12 »
Riporto un'importante comunicazione apparsa nella M.L.I.:


« 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.

Sebastian Kulesz
»
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Nuovo componente: gb.logging
« Risposta #1 il: 21 Maggio 2013, 14:14:16 »
In realtà avevo già implementato una logica simile in pgdesigner3, prendendo come spunto la Log4J di Java.

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.334
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Nuovo componente: gb.logging
« Risposta #2 il: 21 Maggio 2013, 14:23:47 »
In realtà avevo già implementato una logica simile in.....

L'unico limite della nostra Comunità di Gambas è che, pur avendo un enorme potenziale, non riusciamo ad apportare un visibile contributo allo sviluppo di Gambas.  :-\
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.334
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Nuovo componente: gb.logging
« Risposta #3 il: 29 Novembre 2013, 01:14:15 »
Riguardo al componente gb.logging vi segnalo questa discussione apparsa nel forum della comunità ispanica dei programmatori Gambas:

http://www.gambas-es.org/viewtopic.php?f=4&t=3495
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »