Difference between revisions of "Logging in the Code Base"
(New page: {| align="right" | __TOC__ |} =Introduction= This section covers the 2 types of logging in the PCGen codebase. =Logging= There are currently two error reporting systems used in the ...) |
(→Existing System) |
||
(One intermediate revision by the same user not shown) | |||
Line 10: | Line 10: | ||
There are currently two error reporting systems used in the loader system. | There are currently two error reporting systems used in the loader system. | ||
− | The first is the error reporting used in the "new tokens", which also requires the new loader structure. This uses addParseMessage along with the ability to replay messages. A good example can be traced through plugin.lsttokens.equipment.RangeToken and pcgen.persistence.lst.GenericLoader. However, since the Game Mode files aren't using the new loader structure, you can't use this system (at least not without a lot of [unnecessary] work). An important thing I found out with this system is that it is not suited to warnings as the messages generally only get output (replayed) if the token fails by returning false when parsed. In that case Logging.log(Logging.LST_WARN, "blah should be avoided"); is a better option. | + | ==New Tokens== |
+ | The first is the error reporting used in the "new tokens", which also requires the new loader structure. This uses '''addParseMessage''' along with the ability to replay messages. A good example can be traced through '''plugin.lsttokens.equipment.RangeToken''' and '''pcgen.persistence.lst.GenericLoader'''. However, since the Game Mode files aren't using the new loader structure, you can't use this system (at least not without a lot of [unnecessary] work). An important thing I found out with this system is that it is not suited to warnings as the messages generally only get output (replayed) if the token fails by returning false when parsed. In that case '''Logging.log(Logging.LST_WARN, "blah should be avoided");''' is a better option. | ||
− | The second system is (also) in Logging, so if you need to output an error, all you need to do is call: | + | ==Existing System== |
− | Logging.errorPrint("blah failed due to stuff"); | + | The second system is (also) in Logging, so if you need to output an error, all you need to do is call:<br/> |
− | ...and then return false from the token. The AUTO subtokens (e.g. plugin.lsttokens.auto.ArmorProfToken.java) are places where this old messaging still exists in a token. This is the method you should use in the Game Mode files. The ideal is to use Logging.log(Logging.LST_ERROR, "blah failed due to stuff"); so that it correctly categorised on the output. | + | <br/>'''Logging.errorPrint("blah failed due to stuff");'''<br/> |
+ | <br/> | ||
+ | ...and then return false from the token. The AUTO subtokens (e.g. '''plugin.lsttokens.auto.ArmorProfToken.java''') are places where this old messaging still exists in a token. This is the method you should use in the Game Mode files. The ideal is to use '''Logging.log(Logging.LST_ERROR, "blah failed due to stuff");''' so that it correctly categorised on the output. |
Latest revision as of 08:47, 8 October 2008
Introduction
This section covers the 2 types of logging in the PCGen codebase.
Logging
There are currently two error reporting systems used in the loader system.
New Tokens
The first is the error reporting used in the "new tokens", which also requires the new loader structure. This uses addParseMessage along with the ability to replay messages. A good example can be traced through plugin.lsttokens.equipment.RangeToken and pcgen.persistence.lst.GenericLoader. However, since the Game Mode files aren't using the new loader structure, you can't use this system (at least not without a lot of [unnecessary] work). An important thing I found out with this system is that it is not suited to warnings as the messages generally only get output (replayed) if the token fails by returning false when parsed. In that case Logging.log(Logging.LST_WARN, "blah should be avoided"); is a better option.
Existing System
The second system is (also) in Logging, so if you need to output an error, all you need to do is call:
Logging.errorPrint("blah failed due to stuff");
...and then return false from the token. The AUTO subtokens (e.g. plugin.lsttokens.auto.ArmorProfToken.java) are places where this old messaging still exists in a token. This is the method you should use in the Game Mode files. The ideal is to use Logging.log(Logging.LST_ERROR, "blah failed due to stuff"); so that it correctly categorised on the output.