LOGMINLEVEL: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_LOGMINLEVEL}} The _LOGMINLEVEL function returns the current minimum logging level that is being output. {{PageSyntax}} : {{Parameter|level&}} = _LOGMINLEVEL {{PageDescription}} The purpose of _LOGMINLEVEL is to allow programs to skip generating expensive logging if that logging would not be output anywhere. For example, you may have a very large array of integers that you want to log fairly often - generating the strings of the log messages...")
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_LOGMINLEVEL}}
{{DISPLAYTITLE:_LOGMINLEVEL}}
The [[_LOGMINLEVEL]] function returns the current minimum logging level that is being output.
The '''_LOGMINLEVEL''' function returns the current minimum logging level that is being output.
 


{{PageSyntax}}
{{PageSyntax}}
: {{Parameter|level&}} = [[_LOGMINLEVEL]]
: {{Parameter|level&}} = [[_LOGMINLEVEL]]


{{PageDescription}}
The purpose of [[_LOGMINLEVEL]] is to allow programs to skip generating expensive logging if that logging would not be output anywhere.


For example, you may have a very large array of integers that you want to log fairly often - generating the strings of the log messages for that array can slow down your program even if those messages are ultimately never written anywhere. By checking [[_LOGMINLEVEL]] before generating those log messages you can avoid that expensive work if it would not be used but also still produce it when you request it.
{{PageParameters}}
* The return value {{Parameter|level&}} is a number from 1 to 5 indicating the current minimum level of logging enabled. The below table indicates the mapping:
                          ┌────────┬─────────────┐
                          │ '''Number''' │  '''Log level'''  │
                          ├────────┼─────────────┤
                          │  1    │    Trace    │
                          ├────────┼─────────────┤
                          │  2    │ Information │
                          ├────────┼─────────────┤
                          │  3    │  Warning  │
                          ├────────┼─────────────┤
                          │  4    │    Error    │
                          ├────────┼─────────────┤
                          │  5    │    None    │
                          └────────┴─────────────┘


The return value is a number 1 to 5 indicating the current minimum level of logging enabled. The below table indicates the mapping:


{| align="center" border=1
{{PageDescription}}
! Number
* The purpose of '''_LOGMINLEVEL''' is to allow programs to skip generating expensive logging if that logging would not be output anywhere.
! Log level
* For example, you may have a very large array of integers that you want to log fairly often - generating the strings of the log messages for that array can slow down your program even if those messages are ultimately never written anywhere. By checking [[_LOGMINLEVEL]] before generating those log messages you can avoid that expensive work if it would not be used but also still produce it when you request it.
|-
* If the function returns a 2, that indicates that only logging at the Information level and above is being captured somewhere. If the function returns a 5, that means no logging is being captured anywhere.
| align="center" |1 ||  Trace
|-
| align="center" |2 ||  Information
|-
| align="center" |3 ||  Warning
|-
| align="center" |4 ||  Error
|-
| align="center" |5 ||  None
|}


If the function returns a 2, that indicates that only logging at the Information level and above is being captured somewhere. If the function returns a 5, that means no logging is being captured anywhere.


{{PageAvailability}}
{{PageAvailability}}
Line 39: Line 40:
File:Osx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
</gallery>
<!-- Additional availability notes go below here -->


{{PageExamples}}
{{PageExamples}}
; Example 1 : Writes a log message at the information level
; Example 1 : Writes a log message at the information level
{{CodeStart}}
{{CodeStart}}
level& = {{Cl|_LOGMINLEVEL}}
level&amp; = {{Cl|_LOGMINLEVEL}}


{{Cl|IF}} level& < 2 {{Cl|THEN}}
{{Cl|IF}} level&amp; &lt; {{Text|2|#F580B1}} {{Cl|THEN}}
     ' Generate expensive log messages
     {{Text|<nowiki>' Generate expensive log messages</nowiki>|#919191}}
     _LOGTRACE expensiveLogMessage$
     {{Cl|_LOGTRACE}} expensiveLogMessage$
{{Cl|END IF}}
{{Cl|END IF}}
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1066 Featured in our "Keyword of the Day" series]
* [[_LOGTRACE]], [[_LOGINFO]]
* [[Keyword Reference - Alphabetical]]
* [[_LOGWARN]], [[_LOGERROR]]
* [[Keyword Reference - By usage]]
* [[Logging]]
 


{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 12:11, 8 December 2024

The _LOGMINLEVEL function returns the current minimum logging level that is being output.


Syntax

level& = _LOGMINLEVEL


Parameters

  • The return value level& is a number from 1 to 5 indicating the current minimum level of logging enabled. The below table indicates the mapping:
                          ┌────────┬─────────────┐
                          │ NumberLog level  │
                          ├────────┼─────────────┤
                          │   1    │    Trace    │
                          ├────────┼─────────────┤
                          │   2    │ Information │
                          ├────────┼─────────────┤
                          │   3    │   Warning   │
                          ├────────┼─────────────┤
                          │   4    │    Error    │
                          ├────────┼─────────────┤
                          │   5    │    None     │
                          └────────┴─────────────┘


Description

  • The purpose of _LOGMINLEVEL is to allow programs to skip generating expensive logging if that logging would not be output anywhere.
  • For example, you may have a very large array of integers that you want to log fairly often - generating the strings of the log messages for that array can slow down your program even if those messages are ultimately never written anywhere. By checking _LOGMINLEVEL before generating those log messages you can avoid that expensive work if it would not be used but also still produce it when you request it.
  • If the function returns a 2, that indicates that only logging at the Information level and above is being captured somewhere. If the function returns a 5, that means no logging is being captured anywhere.


Availability


Examples

Example 1
Writes a log message at the information level
level& = _LOGMINLEVEL

IF level& < 2 THEN
    ' Generate expensive log messages
    _LOGTRACE expensiveLogMessage$
END IF

END


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link