Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
wiki:documentation:devguide:core:logger [2016/10/04 10:01] carolina.santos [Arquivo de configuração] |
wiki:documentation:devguide:core:logger [2016/10/04 13:58] carolina.santos [References] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== TerraLib.Core: Logger ====== | ====== TerraLib.Core: Logger ====== | ||
- | The class **te::core::Logger** provides support to create application event logs through [[http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/index.html | Boost.Log]]. | + | The class **te::core::Logger** provides support to create event logs for the application through [[http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/index.html | Boost.Log]]. |
===== API ===== | ===== API ===== | ||
Line 7: | Line 7: | ||
==== C++ ==== | ==== C++ ==== | ||
- | The API for create event log in TerraLib is defined by the **Logger** class, shown below: | + | The API for create event logs in TerraLib is defined by the **Logger** class, shown below: |
<code cpp> | <code cpp> | ||
Line 14: | Line 14: | ||
namespace core | namespace core | ||
{ | { | ||
- | class TECOREEXPORT Logger | + | class Logger |
{ | { | ||
/*! | /*! | ||
Line 106: | Line 106: | ||
Where: | Where: | ||
- | * ''channel'': name of the logger. | + | * ''channel'': logger name. |
- | * ''message'': message to be registered. | + | * ''message'': message to be logged. |
It's possible to define your own logger macros, so that is not necessary to provide the logger name every time a log is made. | It's possible to define your own logger macros, so that is not necessary to provide the logger name every time a log is made. | ||
Line 115: | Line 115: | ||
</code> | </code> | ||
- | === Arquivo de configuração === | + | === Configuration File === |
It is possible to add a logger without providing a configuration file using the macro **TE_ADD_LOGGER**: | It is possible to add a logger without providing a configuration file using the macro **TE_ADD_LOGGER**: | ||
Line 140: | Line 140: | ||
* ''filename'': name of the configuration file. | * ''filename'': name of the configuration file. | ||
- | The following is an example of a configuration file: | + | Here is an example of a configuration file: |
<code cpp> | <code cpp> | ||
Line 151: | Line 151: | ||
</code> | </code> | ||
- | **Note:** the messages will be registered in the correct channel if the following filter was added: ''Filter="%Channel% matches \"logger_name\""'' | + | **Note:** the messages will be logged in the correct channel if the following filter was added: ''Filter="%Channel% matches \"logger_name\""'' |
- | The informations for create a configuration file are available in [[http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/index.html | Boost.Log]]. | + | The informations to create a configuration file are available in [[http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/index.html | Boost.Log]]. |
- | === Logger Padrão === | + | === Default Logger === |
- | It is possible to use the standard TerraLib logger by the macro **TE_INIT_DEFAULT_LOGGER**: | + | It is possible to use a default TerraLib logger with the macro **TE_INIT_DEFAULT_LOGGER**: |
<code cpp> | <code cpp> | ||
Line 165: | Line 165: | ||
Where: | Where: | ||
- | * ''filename'': file where the log messages will be registered. | + | * ''filename'': file where messages will be logged. |
- | The standard logger of TerraLib consists of 6 macros that can be used to categorize messages in relevant levels: | + | The default logger of TerraLib consists of 6 macros that can be used to categorize messages in relevant levels: |
<code cpp> | <code cpp> | ||
- | TE_LOG_TRACE("Trace log") | + | TE_LOG_TRACE ("Trace log") |
- | /* Utilizada dentro de funções que implementam algoritmos, com o propósito de ajudar a verificar o fluxo de execução dentro da função. | + | /* Used within functions which implement algorithms to check the flow of execution within the function. |
- | Portanto, esta macro deve ser aplicada nos níveis mais internos do algoritmo sendo implementado. */ | + | Therefore, this macro should be applied in the inner levels of the algorithm being implemented. */ |
- | + | ||
- | TE_LOG_DEBUG("Debug log") | + | TE_LOG_DEBUG ("Debug log") |
- | /* Utilizada para registrar mensagens que informem os valores de argumentos passados a uma função ou o valor de retorno dessa função. | + | /* Used to register messages to inform the values of arguments passed to a function or the return value of this function. |
- | O propósito das mensagens é a depuração do sistema. */ | + | The purpose of the message is the system debugging. */ |
TE_LOG_INFO("Information log") | TE_LOG_INFO("Information log") | ||
- | /* Utilizada com mensagens que indiquem o progresso da aplicação ou de uma função. */ | + | /* Used with messages that indicate the progress of the application or a function. */ |
TE_LOG_WARN("Warning log") | TE_LOG_WARN("Warning log") | ||
- | /* Utilizada para registrar mensagens de situações consideradas inseguras para a aplicação. */ | + | /* Used to register considered unsafe situations messages to the application. */ |
TE_LOG_ERROR("Error log") | TE_LOG_ERROR("Error log") | ||
- | /* Utilizada para registrar mensagens de erro que não inviabilizem a continuação da aplicação. */ | + | /* Used to register error messages that do not impede the continued application. */ |
TE_LOG_FATAL("Fatal log") | TE_LOG_FATAL("Fatal log") | ||
- | /* Utilizada para registrar mensagens de eventos que inviabilizem a continuação da aplicação. */ | + | /* Used to register event messages that impede the continued application. */ |
</code> | </code> | ||
- | **Note:** watch out to the fact that should be avoided the use of macros like **TE_LOG_TRACE** and **TE_LOG_DEBUG** together with the message translation mechanism to avoid overhead involved in messages translation. | + | **Note:** be careful with the fact that the use of macros like **TE_LOG_TRACE** and **TE_LOG_DEBUG** together with the message translation mechanism should be avoided to prevent overhead involved in messages translation. |
The application and TerraLib must be compiled with the level **TE_LOG_TRACE** disabled to prevent overcharging with the log record in the archives. | The application and TerraLib must be compiled with the level **TE_LOG_TRACE** disabled to prevent overcharging with the log record in the archives. | ||
- | === Formatação do Logger === | + | === Logger Formatting === |
- | Os atributos disponíveis para uso na formatação são: | + | The attributes available for use in formatting are: |
- | * ''TimeStamp'': data da mensagem. | + | * ''TimeStamp'': message date. |
- | * ''Severity'': nível de relevância da mensagem. | + | * ''Severity'': message level of relevance. |
- | * ''Channel'': nome do logger. | + | * ''Channel'': logger name. |
- | * ''Message'': conteúdo da mensagem. | + | * ''Message'': message content. |
- | * ''Process'': processo que registrou a mensagem. | + | * ''Process'': process that logged the message. |
- | * ''ProcessID'': ID do processo. | + | * ''ProcessID'': process id. |
- | * ''ThreadID'': ID da thread que registrou a mensagem. | + | * ''ThreadID'': id of the thread that logged the message. |
- | A utilização dos atributos é feita da seguinte forma: ''[%TimeStamp%] %Severity%: %Message%'' | + | The attributes are used as follow: ''[%TimeStamp%] %Severity%: %Message%'' |
- | ===== Exemplos ===== | + | ===== Examples ===== |
- | A seguir um exemplo de uso simples das funções fornecidas pela classe ''Logger'': | + | Here is a simple example using the functions provided by the **Logger** class: |
<code cpp> | <code cpp> | ||
Line 251: | Line 251: | ||
</code> | </code> | ||
- | ===== Referências ===== | + | ===== Additional References ===== |
* [[https://tools.ietf.org/html/rfc5424 | The Syslog Protocol]] | * [[https://tools.ietf.org/html/rfc5424 | The Syslog Protocol]] |