|
| 1 | +# `log` helper |
| 2 | + |
| 3 | +REserve offers a method to **output server events** in the standard console. |
| 4 | + |
| 5 | +```typescript |
| 6 | +function log (server: Server, verbose?: boolean): Server |
| 7 | +``` |
| 8 | + |
| 9 | +> Types definition for `log` |
| 10 | + |
| 11 | +```javascript |
| 12 | +import { log, read, serve } from 'reserve' |
| 13 | +
|
| 14 | +read('reserve.json') |
| 15 | + .then(configuration => log(serve(configuration))) |
| 16 | +``` |
| 17 | + |
| 18 | +> Example of `log` |
| 19 | + |
| 20 | +The helper supports two modes based on the `verbose` parameter : |
| 21 | + |
| 22 | +* When `verbose` is `false` : only a summary is generated when a request is **completed**. It includes `method`, `url` *(initial)*, `statusCode` and `timeSpent`. |
| 23 | + |
| 24 | +```text |
| 25 | +Server running at http://192.168.4.41:8080/ |
| 26 | +SERVE GET / 200 12 ms |
| 27 | +SERVE GET /load-ui5.js 200 4 ms |
| 28 | +SERVE GET /init.js 200 3 ms |
| 29 | +SERVE GET /test/MockServer.js 200 3 ms |
| 30 | +SERVE GET /const.js 200 3 ms |
| 31 | +SERVE GET /test/newItem.js 200 3 ms |
| 32 | +SERVE GET /manifest.json 200 2 ms |
| 33 | +SERVE GET /model/metadata.xml 200 2 ms |
| 34 | +SERVE GET /model/metadata.xml 200 3 ms |
| 35 | +SERVE GET /model/AppConfigurationSet.json 200 3 ms |
| 36 | +SERVE GET /model/TodoItemSet.json 200 2 ms |
| 37 | +SERVE GET /Component-preload.js 404 2 ms |
| 38 | +SERVE GET /Component-preload.js 404 1 ms |
| 39 | +SERVE GET /Component.js 200 2 ms |
| 40 | +SERVE GET /manifest.json 200 2 ms |
| 41 | +SERVE GET /favicon.ico 404 1 ms |
| 42 | +SERVE GET /css/styles.css 200 6 ms |
| 43 | +SERVE GET /i18n/i18n_fr.properties 404 2 ms |
| 44 | +SERVE GET /i18n/i18n_en.properties 404 1 ms |
| 45 | +SERVE GET /i18n/i18n.properties 200 2 ms |
| 46 | +SERVE GET /view/App.view.xml 200 2 ms |
| 47 | +SERVE GET /controller/App.controller.js 200 2 ms |
| 48 | +``` |
| 49 | + |
| 50 | +> Example of `log(...,false)` output |
| 51 | + |
| 52 | +In case of error, a trace with error information is generated |
| 53 | + |
| 54 | +```text |
| 55 | +ERROR GET /i18n/i18n_fr.properties |
| 56 | +\____ Error: FAILED |
| 57 | +``` |
| 58 | + |
| 59 | +> Example of error |
| 60 | + |
| 61 | +* When `verbose` is `true` : all request events are dumped, the request `id` is used to **correlate** the traces. |
| 62 | + * `INCMG` : `incoming` event, documents `method` and `url` |
| 63 | + * `RDRCT` : `redirecting` event, documents `type` and `redirect` |
| 64 | + * `SERVE` : `redirected` event, documents `statusCode` and `timeSpent` |
| 65 | + * `ABORT` : `aborted` event |
| 66 | + * `CLOSE` : `closed` event |
| 67 | + |
| 68 | +```text |
| 69 | +Server running at http://192.168.4.41:8080/ |
| 70 | +INCMG 0001 GET / |
| 71 | +RDRCT 0001 file ./webapp/index.html |
| 72 | +CLOSE 0001 |
| 73 | +SERVE 0001 200 16 ms |
| 74 | +INCMG 0002 GET /load-ui5.js |
| 75 | +RDRCT 0002 file ./webapp/load-ui5.js |
| 76 | +CLOSE 0002 |
| 77 | +SERVE 0002 200 5 ms |
| 78 | +INCMG 0003 GET /init.js |
| 79 | +RDRCT 0003 file ./webapp/init.js |
| 80 | +CLOSE 0003 |
| 81 | +SERVE 0003 200 4 ms |
| 82 | +INCMG 0004 GET /test/MockServer.js |
| 83 | +RDRCT 0004 file ./webapp/test/MockServer.js |
| 84 | +CLOSE 0004 |
| 85 | +SERVE 0004 200 4 ms |
| 86 | +INCMG 0005 GET /const.js |
| 87 | +RDRCT 0005 file ./webapp/const.js |
| 88 | +INCMG 0006 GET /test/newItem.js |
| 89 | +RDRCT 0006 file ./webapp/test/newItem.js |
| 90 | +CLOSE 0005 |
| 91 | +SERVE 0005 200 5 ms |
| 92 | +CLOSE 0006 |
| 93 | +SERVE 0006 200 5 ms |
| 94 | +INCMG 0007 GET /manifest.json |
| 95 | +RDRCT 0007 file ./webapp/manifest.json |
| 96 | +CLOSE 0007 |
| 97 | +SERVE 0007 200 3 ms |
| 98 | +INCMG 0008 GET /model/metadata.xml |
| 99 | +RDRCT 0008 file ./webapp/model/metadata.xml |
| 100 | +CLOSE 0008 |
| 101 | +SERVE 0008 200 3 ms |
| 102 | +INCMG 0009 GET /model/metadata.xml |
| 103 | +RDRCT 0009 file ./webapp/model/metadata.xml |
| 104 | +CLOSE 0009 |
| 105 | +SERVE 0009 200 3 ms |
| 106 | +INCMG 000A GET /model/AppConfigurationSet.json |
| 107 | +RDRCT 000A file ./webapp/model/AppConfigurationSet.json |
| 108 | +CLOSE 000A |
| 109 | +SERVE 000A 200 4 ms |
| 110 | +INCMG 000B GET /model/TodoItemSet.json |
| 111 | +RDRCT 000B file ./webapp/model/TodoItemSet.json |
| 112 | +CLOSE 000B |
| 113 | +SERVE 000B 200 3 ms |
| 114 | +INCMG 000C GET /Component-preload.js |
| 115 | +RDRCT 000C file ./webapp/Component-preload.js |
| 116 | +RDRCT 000C status 404 |
| 117 | +SERVE 000C 404 3 ms |
| 118 | +CLOSE 000C |
| 119 | +INCMG 000D GET /Component-preload.js |
| 120 | +RDRCT 000D file ./webapp/Component-preload.js |
| 121 | +RDRCT 000D status 404 |
| 122 | +SERVE 000D 404 2 ms |
| 123 | +CLOSE 000D |
| 124 | +INCMG 000E GET /Component.js |
| 125 | +RDRCT 000E file ./webapp/Component.js |
| 126 | +CLOSE 000E |
| 127 | +SERVE 000E 200 3 ms |
| 128 | +INCMG 000F GET /manifest.json |
| 129 | +RDRCT 000F file ./webapp/manifest.json |
| 130 | +CLOSE 000F |
| 131 | +SERVE 000F 200 5 ms |
| 132 | +INCMG 0010 GET /css/styles.css |
| 133 | +RDRCT 0010 file ./webapp/css/styles.css |
| 134 | +CLOSE 0010 |
| 135 | +SERVE 0010 200 4 ms |
| 136 | +INCMG 0011 GET /i18n/i18n_fr.properties |
| 137 | +RDRCT 0011 file ./webapp/i18n/i18n_fr.properties |
| 138 | +RDRCT 0011 status 404 |
| 139 | +SERVE 0011 404 2 ms |
| 140 | +CLOSE 0011 |
| 141 | +INCMG 0012 GET /i18n/i18n_en.properties |
| 142 | +RDRCT 0012 file ./webapp/i18n/i18n_en.properties |
| 143 | +RDRCT 0012 status 404 |
| 144 | +SERVE 0012 404 2 ms |
| 145 | +CLOSE 0012 |
| 146 | +INCMG 0013 GET /i18n/i18n.properties |
| 147 | +RDRCT 0013 file ./webapp/i18n/i18n.properties |
| 148 | +CLOSE 0013 |
| 149 | +SERVE 0013 200 3 ms |
| 150 | +INCMG 0014 GET /view/App.view.xml |
| 151 | +RDRCT 0014 file ./webapp/view/App.view.xml |
| 152 | +CLOSE 0014 |
| 153 | +SERVE 0014 200 3 ms |
| 154 | +INCMG 0015 GET /controller/App.controller.js |
| 155 | +RDRCT 0015 file ./webapp/controller/App.controller.js |
| 156 | +CLOSE 0015 |
| 157 | +SERVE 0015 200 3 ms |
| 158 | +``` |
| 159 | + |
| 160 | +> Example of `log(...,true)` output |
| 161 | + |
| 162 | +In case of error, a trace with error information is generated |
| 163 | + |
| 164 | +```text |
| 165 | +INCMG 0011 GET /i18n/i18n_fr.properties |
| 166 | +RDRCT 0011 file ./webapp/i18n/i18n_fr.properties |
| 167 | +RDRCT 0011 custom ./error.js |
| 168 | +ERROR 0011 Error: FAILED |
| 169 | +RDRCT 0011 status 500 |
| 170 | +SERVE 0011 500 3 ms |
| 171 | +CLOSE 0011 |
| 172 | +``` |
| 173 | + |
| 174 | +> Example of error |
0 commit comments