|
| 1 | +.. ================================================== |
| 2 | +.. FOR YOUR INFORMATION |
| 3 | +.. -------------------------------------------------- |
| 4 | +.. -*- coding: utf-8 -*- with BOM. |
| 5 | +
|
| 6 | +.. include:: ../Includes.txt |
| 7 | + |
| 8 | + |
| 9 | +.. _developer: |
| 10 | + |
| 11 | +Developer manual |
| 12 | +---------------- |
| 13 | + |
| 14 | + |
| 15 | +.. _developer-logging-method: |
| 16 | + |
| 17 | +Using the logging method |
| 18 | +^^^^^^^^^^^^^^^^^^^^^^^^ |
| 19 | + |
| 20 | +To log something simply call :code:`\TYPO3\CMS\Core\Utility\GeneralUtility::devLog()`. |
| 21 | +This method takes the following parameters: |
| 22 | + |
| 23 | ++-----------+-----------------------------------------------------------------------+ |
| 24 | +| $msg | The message that you want to write to the log | |
| 25 | ++-----------+-----------------------------------------------------------------------+ |
| 26 | +| $extKey | The key of the extension writing to the log | |
| 27 | ++-----------+-----------------------------------------------------------------------+ |
| 28 | +| $severity | Indication of the severity of the message. The following values are | |
| 29 | +| | expected: | |
| 30 | +| | | |
| 31 | +| | - -1 for ok status | |
| 32 | +| | - 0 for a purely informational message | |
| 33 | +| | - 1 for a notice | |
| 34 | +| | - 2 for a warning | |
| 35 | +| | - 3 for a (fatal) error | |
| 36 | +| | | |
| 37 | +| | This parameter is optional and defaults to 0. | |
| 38 | ++-----------+-----------------------------------------------------------------------+ |
| 39 | +| $dataVar | This variable can be any type of data that you wish and that you find | |
| 40 | +| | useful for information or debugging purposes. The Database Writer | |
| 41 | +| | serializes it before storage in the database. | |
| 42 | +| | | |
| 43 | +| | This parameter is optional and defaults to false. | |
| 44 | ++-----------+-----------------------------------------------------------------------+ |
| 45 | + |
| 46 | +.. warning:: |
| 47 | + |
| 48 | + If you store a lot of stuff in the :code:`$dataVar` or |
| 49 | + if you call the "devLog" very frequently, you may end up with a |
| 50 | + very large "tx\_devlog\_domain\_model|_entry" table in your database. |
| 51 | + Check it out regularly and don't hesitate to use the :ref:`clean up features <user-backend-module-clear-entries>` |
| 52 | + as the relevant :ref:`configuration options <installation-configuration-database-writer>`. |
| 53 | + |
| 54 | + |
| 55 | +.. _developer-logging-method-severity-levels: |
| 56 | + |
| 57 | +More about severity levels |
| 58 | +"""""""""""""""""""""""""" |
| 59 | + |
| 60 | +It may not always be easy to choose a severity level. The descriptions |
| 61 | +below go into a bit more detail and will – hopefully – make the choice |
| 62 | +easier. |
| 63 | + |
| 64 | +OK (-1) |
| 65 | + These events indicate that everything went fine, no |
| 66 | + error occurred (at least up to that point where the event was |
| 67 | + created). No action needs to be taken. |
| 68 | + |
| 69 | +Info (0) |
| 70 | + These events are purely informational. They are |
| 71 | + normally used for debugging purposes only and require no special |
| 72 | + action. |
| 73 | + |
| 74 | +Notice (1) |
| 75 | + Abnormal condition, but not blocking. Notices are |
| 76 | + meant to raise attention. Processes have been completed, but things |
| 77 | + are not running as smoothly as they could and the condition should be |
| 78 | + investigated. |
| 79 | + |
| 80 | +Warning (2) |
| 81 | + These events are used to notify significant |
| 82 | + problems. Processes have been completed, but parts of them may be |
| 83 | + missing, wrong or corrupted. Warnings should not be ignored and action |
| 84 | + should definitely be taken. |
| 85 | + |
| 86 | +Error (3) |
| 87 | + These events signal that something went fatally wrong. |
| 88 | + Processes were not completed and action is definitely needed. |
| 89 | + Alternately this level may be used to point to a failed event, but in |
| 90 | + a process where failure can be expected, e.g. a login attempt with the |
| 91 | + wrong password. |
| 92 | + |
| 93 | + |
| 94 | +.. _developer-extra-information: |
| 95 | + |
| 96 | +Extra information |
| 97 | +^^^^^^^^^^^^^^^^^ |
| 98 | + |
| 99 | +The devlog extension stores information beyond the parameters passed to the |
| 100 | +:code:`\TYPO3\CMS\Core\Utility\GeneralUtility::devLog()` method. Some of it |
| 101 | +is automatically retrieved, like the id of the currently logged in BE user, if any. |
| 102 | + |
| 103 | +If the devlog call is made in the FE context, the page id will also automatically |
| 104 | +be retrieved from :code:`$GLOBALS['TSFE']->id. This variable is not defined in other contexts, |
| 105 | +in particular the BE. There is still a way to pass a page id to the devlog, if it makes sense, |
| 106 | +but you need to set it yourself in the global variable |
| 107 | +:code:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['debugData']['pid']`. |
| 108 | +If defined, this variable will be taken into account by the devlog. |
| 109 | + |
| 110 | +All this work happens in the :class:`\\Devlog\\Devlog\\Utility\\Logger` class. |
| 111 | + |
| 112 | + |
| 113 | +.. _developer-custom-writers: |
| 114 | + |
| 115 | +Custom Writers |
| 116 | +^^^^^^^^^^^^^^ |
| 117 | + |
| 118 | +The data passed in the :code:`\TYPO3\CMS\Core\Utility\GeneralUtility::devLog()` |
| 119 | +call is stored by classed called "Writers". The extension provides two Writers |
| 120 | +out of the box: one write to the database, the other to a file. It is pretty |
| 121 | +easy to develop custom Writers. |
| 122 | + |
| 123 | +First you want to create a new class which extends |
| 124 | +:class:`\\Devlog\\Devlog\\Writer\\AbstractWriter`, which itself implements |
| 125 | +:class:`\\Devlog\\Devlog\\Writer\\WriterInterface`. The interface |
| 126 | +defines a single method called :code:`write()` which should take care of |
| 127 | +storing each log entry wherever and however it wants. |
| 128 | + |
| 129 | +Once you hace created your writer, register it in your extension's |
| 130 | +:file:`ext_localconf.php` file with the following syntax: |
| 131 | + |
| 132 | +.. code-block:: php |
| 133 | +
|
| 134 | + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['devlog']['writers']['foobar'] = \Foo\Bar\Writer\FooBarWriter::class; |
| 135 | +
|
| 136 | +
|
| 137 | +where :code:`foobar` should be a unique key for your Writer. |
| 138 | + |
| 139 | +.. note:: |
| 140 | + |
| 141 | + It is actually possible to overwrite the default Writers be registrer a different |
| 142 | + class for keys :code:`db` (Database Writer) and :code:`file` (File Writer). |
| 143 | + |
| 144 | + It would also be possible to disable a Writer, by unsetting its entry in the |
| 145 | + :code:`$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['devlog']['writers']` array. |
0 commit comments