Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <a name="roarr"></a>
  2. # Roarr
  3. [![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/roarr?style=flat-square)](https://gitspo.com/mentions/gajus/roarr)
  4. [![Travis build status](http://img.shields.io/travis/gajus/roarr/master.svg?style=flat-square)](https://travis-ci.org/gajus/roarr)
  5. [![Coveralls](https://img.shields.io/coveralls/gajus/roarr.svg?style=flat-square)](https://coveralls.io/github/gajus/roarr)
  6. [![NPM version](http://img.shields.io/npm/v/roarr.svg?style=flat-square)](https://www.npmjs.org/package/roarr)
  7. [![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
  8. [![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)
  9. JSON logger for Node.js and browser.
  10. * [Roarr](#roarr)
  11. * [Motivation](#roarr-motivation)
  12. * [Usage](#roarr-usage)
  13. * [Producing logs](#roarr-usage-producing-logs)
  14. * [Consuming logs](#roarr-usage-consuming-logs)
  15. * [Filtering logs](#roarr-usage-filtering-logs)
  16. * [Log message format](#roarr-log-message-format)
  17. * [API](#roarr-api)
  18. * [`adopt`](#roarr-api-adopt)
  19. * [`child`](#roarr-api-child)
  20. * [`getContext`](#roarr-api-getcontext)
  21. * [`trace`](#roarr-api-trace)
  22. * [`debug`](#roarr-api-debug)
  23. * [`info`](#roarr-api-info)
  24. * [`warn`](#roarr-api-warn)
  25. * [`error`](#roarr-api-error)
  26. * [`fatal`](#roarr-api-fatal)
  27. * [Middlewares](#roarr-middlewares)
  28. * [CLI program](#roarr-cli-program)
  29. * [Transports](#roarr-transports)
  30. * [Node.js environment variables](#roarr-node-js-environment-variables)
  31. * [Conventions](#roarr-conventions)
  32. * [Context property names](#roarr-conventions-context-property-names)
  33. * [Using Roarr in an application](#roarr-conventions-using-roarr-in-an-application)
  34. * [Recipes](#roarr-recipes)
  35. * [Logging errors](#roarr-recipes-logging-errors)
  36. * [Using with Elasticsearch](#roarr-recipes-using-with-elasticsearch)
  37. * [Using with Scalyr](#roarr-recipes-using-with-scalyr)
  38. * [Documenting use of Roarr](#roarr-recipes-documenting-use-of-roarr)
  39. <a name="roarr-motivation"></a>
  40. ## Motivation
  41. For a long time I have been a big fan of using [`debug`](https://github.com/visionmedia/debug). `debug` is simple to use, works in Node.js and browser, does not require configuration and it is fast. However, problems arise when you need to parse logs. Anything but one-line text messages cannot be parsed in a safe way.
  42. To log structured data, I have been using [Winston](https://github.com/winstonjs/winston) and [Bunyan](https://github.com/trentm/node-bunyan). These packages are great for application-level logging. I have preferred Bunyan because of the [Bunyan CLI program](https://github.com/trentm/node-bunyan#cli-usage) used to pretty-print logs. However, these packages require program-level configuration – when constructing an instance of a logger, you need to define the transport and the log-level. This makes them unsuitable for use in code designed to be consumed by other applications.
  43. Then there is [pino](https://github.com/pinojs/pino). pino is fast JSON logger, it has CLI program equivalent to Bunyan, it decouples transports, and it has sane default configuration. Unfortunately, you still need to instantiate logger instance at the application-level. This makes it more suitable for application-level logging just like Winston and Bunyan.
  44. I needed a logger that:
  45. * Does not block the event cycle (=fast).
  46. * Does not require initialisation.
  47. * Produces structured data.
  48. * [Decouples transports](#transports).
  49. * Has a [CLI program](#cli-program).
  50. * Works in Node.js and browser.
  51. * Configurable using environment variables.
  52. In other words,
  53. * a logger that I can use in an application code and in dependencies.
  54. * a logger that allows to correlate logs between the main application code and the dependency code.
  55. * a logger that works well with transports in external processes.
  56. Roarr is this logger.
  57. <a name="roarr-usage"></a>
  58. ## Usage
  59. <a name="roarr-usage-producing-logs"></a>
  60. ### Producing logs
  61. Roarr logger API for producing logs is the same in Node.js and browser.
  62. 1. Import `roarr`
  63. 2. Use any of the [API](#api) methods to log messages.
  64. Example:
  65. ```js
  66. import log from 'roarr';
  67. log('foo');
  68. ```
  69. <a name="roarr-usage-consuming-logs"></a>
  70. ### Consuming logs
  71. Roarr logs are consumed differently in Node.js and browser.
  72. <a name="roarr-usage-consuming-logs-node-js"></a>
  73. #### Node.js
  74. In Node.js, Roarr logging is disabled by default. To enable logging, you must start program with an environment variable `ROARR_LOG` set to `true`, e.g.
  75. ```bash
  76. ROARR_LOG=true node ./index.js
  77. ```
  78. All logs will be written to stdout.
  79. <a name="roarr-usage-consuming-logs-browser"></a>
  80. #### Browser
  81. In a browser, you must implement `ROARR.write` method to read logs, e.g.
  82. ```js
  83. import {
  84. ROARR,
  85. } from 'roarr';
  86. ROARR.write = () => {};
  87. ```
  88. The API of the `ROARR.write` is:
  89. ```js
  90. (message: string) => void;
  91. ```
  92. Example implementation:
  93. ```js
  94. import {
  95. ROARR,
  96. } from 'roarr';
  97. ROARR.write = (message) => {
  98. console.log(JSON.parse(message));
  99. };
  100. ```
  101. or if you are initializing `ROARR.write` _before_ `roarr` is loaded:
  102. ```js
  103. // Ensure that `globalThis.ROARR` is configured.
  104. const ROARR = globalThis.ROARR = globalThis.ROARR || {};
  105. ROARR.write = (message) => {
  106. console.log(JSON.parse(message));
  107. };
  108. ```
  109. If your platform does not support [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis), use [`globalthis` polyfill](https://www.npmjs.com/package/globalthis).
  110. <a name="roarr-usage-filtering-logs"></a>
  111. ### Filtering logs
  112. <a name="roarr-usage-filtering-logs-node-js-1"></a>
  113. #### Node.js
  114. In Node.js, Roarr prints all or none logs (refer to the [`ROARR_LOG` environment variable](#environment-variables) documentation).
  115. Use [`roarr filter` CLI program](#filter-program) to filter the logs that are written to stdout by the program, e.g.
  116. ```bash
  117. ROARR_LOG=true node ./index.js | roarr filter '{"context.logLevel":{gt:30}}'
  118. ```
  119. Alternatively, use a JSON processor such as [jq](https://stedolan.github.io/jq/)
  120. <a name="roarr-usage-filtering-logs-browser-1"></a>
  121. #### Browser
  122. In a browser, Roarr calls `globalThis.ROARR.write` for every log message. Implement your own custom logic to filter logs, e.g.
  123. ```js
  124. globalThis.ROARR.write = (message) => {
  125. const payload = JSON.parse(message);
  126. if (payload.context.logLevel > 30) {
  127. console.log(payload);
  128. }
  129. };
  130. ```
  131. <a name="roarr-log-message-format"></a>
  132. ## Log message format
  133. |Property name|Contents|
  134. |---|---|
  135. |`context`|Arbitrary, user-provided structured data. See [context property names](#context-property-names).|
  136. |`message`|User-provided message formatted using [printf](https://en.wikipedia.org/wiki/Printf_format_string).|
  137. |`sequence`|An incremental ID.|
  138. |`time`|Unix timestamp in milliseconds.|
  139. |`version`|Roarr log message format version.|
  140. Example:
  141. ```js
  142. {
  143. "context": {
  144. "application": "task-runner",
  145. "hostname": "curiosity.local",
  146. "instanceId": "01BVBK4ZJQ182ZWF6FK4EC8FEY",
  147. "taskId": 1
  148. },
  149. "message": "starting task ID 1",
  150. "sequence": 0,
  151. "time": 1506776210000,
  152. "version": "1.0.0"
  153. }
  154. ```
  155. <a name="roarr-api"></a>
  156. ## API
  157. `roarr` package exports a function with the following API:
  158. ```js
  159. export type LoggerType =
  160. (
  161. context: MessageContextType,
  162. message: string,
  163. c?: SprintfArgumentType,
  164. d?: SprintfArgumentType,
  165. e?: SprintfArgumentType,
  166. f?: SprintfArgumentType,
  167. g?: SprintfArgumentType,
  168. h?: SprintfArgumentType,
  169. i?: SprintfArgumentType,
  170. k?: SprintfArgumentType
  171. ) => void |
  172. (
  173. message: string,
  174. b?: SprintfArgumentType,
  175. c?: SprintfArgumentType,
  176. d?: SprintfArgumentType,
  177. e?: SprintfArgumentType,
  178. f?: SprintfArgumentType,
  179. g?: SprintfArgumentType,
  180. h?: SprintfArgumentType,
  181. i?: SprintfArgumentType,
  182. k?: SprintfArgumentType
  183. ) => void;
  184. ```
  185. To put it into words:
  186. * First parameter can be either a string (message) or an object.
  187. * If first parameter is an object (context), the second parameter must be a string (message).
  188. * Arguments after the message parameter are used to enable [printf message formatting](https://en.wikipedia.org/wiki/Printf_format_string).
  189. * Printf arguments must be of a primitive type (`string | number | boolean | null`).
  190. * There can be up to 9 printf arguments (or 8 if the first parameter is the context object).
  191. Refer to the [Usage documentation](#usage) for common usage examples.
  192. <a name="roarr-api-adopt"></a>
  193. ### <code>adopt</code>
  194. ```js
  195. <T>(routine: () => Promise<T>, context: MessageContextType) => Promise<T>,
  196. ```
  197. `adopt` function uses Node.js [`domain`](https://nodejs.org/api/domain.html) to pass-down context properties.
  198. When using `adopt`, context properties will be added to all _all_ Roarr messages within the same asynchronous context, e.g.
  199. ```js
  200. await log.adopt(
  201. async () => {
  202. log('foo 0');
  203. await log.adopt(
  204. () => {
  205. log('foo 1');
  206. },
  207. {
  208. baz: 'baz 1',
  209. },
  210. );
  211. },
  212. {
  213. bar: 'bar 0',
  214. },
  215. );
  216. // {"context":{"bar":"bar 0"},"message":"foo 0","sequence":0,"time":1531914656076,"version":"1.0.0"}
  217. // {"context":{"bar":"bar 0","baz":"baz 1"},"message":"foo 1","sequence":1,"time":1531914656077,"version":"1.0.0"}]
  218. ```
  219. <a name="roarr-api-adopt-requirements"></a>
  220. #### Requirements
  221. * `adopt` method only works in Node.js.
  222. * You must shim Node.js using [`domain-parent`](https://github.com/gajus/domain-parent).
  223. <a name="roarr-api-child"></a>
  224. ### <code>child</code>
  225. ```js
  226. (context: TranslateMessageFunctionType | MessageContextType) => LoggerType,
  227. ```
  228. The `child` function has two signatures:
  229. 1. Accepts an object.
  230. 2. Accepts a function.
  231. <a name="roarr-api-child-object-parameter"></a>
  232. #### Object parameter
  233. ```js
  234. (context: MessageContextType) => LoggerType;
  235. ```
  236. Creates a child logger appending the provided `context` object to the previous logger context.
  237. Example:
  238. ```js
  239. import log from 'roarr';
  240. const childLog = log.child({
  241. foo: 'bar'
  242. });
  243. log.debug('foo 1');
  244. childLog.debug('foo 2');
  245. // {"context":{"logLevel":20},"message":"foo 1","sequence":0,"time":1531914529921,"version":"1.0.0"}
  246. // {"context":{"foo":"bar","logLevel":20},"message":"foo 2","sequence":1,"time":1531914529922,"version":"1.0.0"}
  247. ```
  248. Refer to [middlewares](#middlewares) documentation for use case examples.
  249. <a name="roarr-api-child-function-parameter"></a>
  250. #### Function parameter
  251. ```js
  252. (translateMessage: TranslateMessageFunctionType) => LoggerType;
  253. ```
  254. Creates a child logger where every message is intercepted.
  255. Example:
  256. ```js
  257. import log from 'roarr';
  258. const childLog = log.child((message) => {
  259. return {
  260. ...message,
  261. message: message.message.replace('foo', 'bar'),
  262. }
  263. });
  264. log.debug('foo 1');
  265. childLog.debug('foo 2');
  266. // {"context":{"logLevel":20},"message":"foo 1","sequence":0,"time":1531914656076,"version":"1.0.0"}
  267. // {"context":{"logLevel":20},"message":"bar 2","sequence":1,"time":1531914656077,"version":"1.0.0"}
  268. ```
  269. <a name="roarr-api-getcontext"></a>
  270. ### <code>getContext</code>
  271. Returns the current context.
  272. Example:
  273. ```js
  274. import log from 'roarr';
  275. const childLogger = log.child({
  276. foo: 'bar'
  277. });
  278. childLogger.getContext();
  279. // {foo: 'bar'}
  280. ```
  281. <a name="roarr-api-trace"></a>
  282. ### <code>trace</code>
  283. <a name="roarr-api-debug"></a>
  284. ### <code>debug</code>
  285. <a name="roarr-api-info"></a>
  286. ### <code>info</code>
  287. <a name="roarr-api-warn"></a>
  288. ### <code>warn</code>
  289. <a name="roarr-api-error"></a>
  290. ### <code>error</code>
  291. <a name="roarr-api-fatal"></a>
  292. ### <code>fatal</code>
  293. Convenience methods for logging a message with `logLevel` context property value set to a numeric value representing the [log level](#log-levels), e.g.
  294. ```js
  295. import log from 'roarr';
  296. log.trace('foo');
  297. log.debug('foo');
  298. log.info('foo');
  299. log.warn('foo');
  300. log.error('foo');
  301. log.fatal('foo');
  302. ```
  303. Produces output:
  304. ```
  305. {"context":{"logLevel":10},"message":"foo","sequence":0,"time":1506776210000,"version":"1.0.0"}
  306. {"context":{"logLevel":20},"message":"foo","sequence":1,"time":1506776210000,"version":"1.0.0"}
  307. {"context":{"logLevel":30},"message":"foo","sequence":2,"time":1506776210000,"version":"1.0.0"}
  308. {"context":{"logLevel":40},"message":"foo","sequence":3,"time":1506776210000,"version":"1.0.0"}
  309. {"context":{"logLevel":50},"message":"foo","sequence":4,"time":1506776210000,"version":"1.0.0"}
  310. {"context":{"logLevel":60},"message":"foo","sequence":5,"time":1506776210000,"version":"1.0.0"}
  311. ```
  312. <a name="roarr-middlewares"></a>
  313. ## Middlewares
  314. Roarr logger supports middlewares implemented as [`child`](#child) message translate functions, e.g.
  315. ```js
  316. import log from 'roarr';
  317. import createSerializeErrorMiddleware from '@roarr/middleware-serialize-error';
  318. const childLog = log.child(createSerializeErrorMiddleware());
  319. const error = new Error('foo');
  320. log.debug({error}, 'bar');
  321. childLog.debug({error}, 'bar');
  322. // {"context":{"logLevel":20,"error":{}},"message":"bar","sequence":0,"time":1531918373676,"version":"1.0.0"}
  323. // {"context":{"logLevel":20,"error":{"name":"Error","message":"foo","stack":"[REDACTED]"}},"message":"bar","sequence":1,"time":1531918373678,"version":"1.0.0"}
  324. ```
  325. Roarr middlwares enable translation of every bit of information that is used to construct a log message.
  326. The following are the official middlewares:
  327. * [`@roarr/middleware-serialize-error`](https://github.com/gajus/roarr-middleware-serialize-error)
  328. Raise an issue to add your middleware of your own creation.
  329. <a name="roarr-cli-program"></a>
  330. ## CLI program
  331. Roarr CLI program provides ability to filter and pretty-print Roarr logs.
  332. ![CLI output demo](./.README/cli-output-demo.png)
  333. CLI program has been moved to a separate package [`@roarr/cli`](https://github.com/gajus/roarr-cli).
  334. ```bash
  335. npm install @roarr/cli -g
  336. ```
  337. Explore all CLI commands and options using `roarr --help` or refer to [`@roarr/cli`](https://github.com/gajus/roarr-cli) documentation.
  338. <a name="roarr-transports"></a>
  339. ## Transports
  340. A transport in most logging libraries is something that runs in-process to perform some operation with the finalised log line. For example, a transport might send the log line to a standard syslog server after processing the log line and reformatting it.
  341. Roarr does not support in-process transports.
  342. Roarr does not support in-process transports because Node processes are single threaded processes (ignoring some technical details). Given this restriction, Roarr purposefully offloads handling of the logs to external processes so that the threading capabilities of the OS can be used (or other CPUs).
  343. Depending on your configuration, consider one of the following log transports:
  344. * [Beats](https://www.elastic.co/products/beats) for aggregating at a process level (written in Go).
  345. * [logagent](https://github.com/sematext/logagent-js) for aggregating at a process level (written in JavaScript).
  346. * [Fluentd](https://www.fluentd.org/) for aggregating logs at a container orchestration level (e.g. Kubernetes) (written in Ruby).
  347. <a name="roarr-node-js-environment-variables"></a>
  348. ## Node.js environment variables
  349. Use environment variables to control `roarr` behaviour.
  350. |Name|Type|Function|Default|
  351. |---|---|---|---|
  352. |`ROARR_LOG`|Boolean|Enables/ disables logging.|`false`|
  353. |`ROARR_STREAM`|`STDOUT`, `STDERR`|Name of the stream where the logs will be written.|`STDOUT`|
  354. When using `ROARR_STREAM=STDERR`, use [`3>&1 1>&2 2>&3 3>&-`](https://stackoverflow.com/a/2381643/368691) to pipe stderr output.
  355. <a name="roarr-conventions"></a>
  356. ## Conventions
  357. <a name="roarr-conventions-context-property-names"></a>
  358. ### Context property names
  359. Roarr does not have reserved context property names. However, I encourage use of the following conventions:
  360. |Context property name|Use case|
  361. |---|---|
  362. |`application`|Name of the application (do not use in code intended for distribution; see `package` property instead).|
  363. |`logLevel`|A numeric value indicating the [log level](#log-levels). See [API](#api) for the build-in loggers with a pre-set log-level.|
  364. |`namespace`|Namespace within a package, e.g. function name. Treat the same way that you would construct namespaces when using the [`debug`](https://github.com/visionmedia/debug) package.|
  365. |`package`|Name of the NPM package.|
  366. The `roarr pretty-print` [CLI program](#cli-program) is using the context property names suggested in the conventions to pretty-print the logs for the developer inspection purposes.
  367. <a name="roarr-conventions-context-property-names-log-levels"></a>
  368. #### Log levels
  369. The `roarr pretty-print` [CLI program](#cli-program) translates `logLevel` values to the following human-readable names:
  370. |`logLevel`|Human-readable name|
  371. |---|---|
  372. |10|TRACE|
  373. |20|DEBUG|
  374. |30|INFO|
  375. |40|WARN|
  376. |50|ERROR|
  377. |60|FATAL|
  378. <a name="roarr-conventions-using-roarr-in-an-application"></a>
  379. ### Using Roarr in an application
  380. To avoid code duplication, you can use a singleton pattern to export a logger instance with predefined context properties (e.g. describing the application).
  381. I recommend to create a file `Logger.js` in the project directory. Inside this file create and export a child instance of Roarr with context parameters describing the project and the script instance, e.g.
  382. ```js
  383. /**
  384. * @file Example contents of a Logger.js file.
  385. */
  386. import log from 'roarr';
  387. const Logger = log.child({
  388. // .foo property is going to appear only in the logs that are created using
  389. // the current instance of a Roarr logger.
  390. foo: 'bar'
  391. });
  392. export default Logger;
  393. ```
  394. Roarr does not have reserved context property names. However, I encourage use of the [conventions](#conventions).
  395. <a name="roarr-recipes"></a>
  396. ## Recipes
  397. <a name="roarr-recipes-logging-errors"></a>
  398. ### Logging errors
  399. This is not specific to Roarr – this suggestion applies to any kind of logging.
  400. If you want to include an instance of [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) in the context, you must serialize the error.
  401. The least-error prone way to do this is to use an existing library, e.g. [`serialize-error`](https://www.npmjs.com/package/serialize-error).
  402. ```js
  403. import log from 'roarr';
  404. import serializeError from 'serialize-error';
  405. // [..]
  406. send((error, result) => {
  407. if (error) {
  408. log.error({
  409. error: serializeError(error)
  410. }, 'message not sent due to a remote error');
  411. return;
  412. }
  413. // [..]
  414. });
  415. ```
  416. Without using serialisation, your errors will be logged without the error name and stack trace.
  417. <a name="roarr-recipes-using-with-elasticsearch"></a>
  418. ### Using with Elasticsearch
  419. If you are using [Elasticsearch](https://www.elastic.co/products/elasticsearch), you will want to create an [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html).
  420. The following serves as the ground work for the index template. It includes the main Roarr log message properties (context, message, time) and the context properties suggested in the [conventions](#conventions).
  421. ```json
  422. {
  423. "mappings": {
  424. "log_message": {
  425. "_source": {
  426. "enabled": true
  427. },
  428. "dynamic": "strict",
  429. "properties": {
  430. "context": {
  431. "dynamic": true,
  432. "properties": {
  433. "application": {
  434. "type": "keyword"
  435. },
  436. "hostname": {
  437. "type": "keyword"
  438. },
  439. "instanceId": {
  440. "type": "keyword"
  441. },
  442. "logLevel": {
  443. "type": "integer"
  444. },
  445. "namespace": {
  446. "type": "text"
  447. },
  448. "package": {
  449. "type": "text"
  450. }
  451. }
  452. },
  453. "message": {
  454. "type": "text"
  455. },
  456. "time": {
  457. "format": "epoch_millis",
  458. "type": "date"
  459. }
  460. }
  461. }
  462. },
  463. "template": "logstash-*"
  464. }
  465. ```
  466. <a name="roarr-recipes-using-with-scalyr"></a>
  467. ### Using with Scalyr
  468. If you are using [Scalyr](https://www.scalyr.com/), you will want to create a custom parser `RoarrLogger`:
  469. ```js
  470. {
  471. patterns: {
  472. tsPattern: "\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{4}\\s[\\d:]+",
  473. tsPattern_8601: "\\d{4}-\\d{2}-\\d{2}T[\\d:.]+Z"
  474. }
  475. formats: [
  476. {format: "${parse=json}$"},
  477. {format: ".*\"time\":$timestamp=number$,.*"},
  478. {format: "$timestamp=tsPattern$ GMT $detail$"},
  479. {format: "$timestamp=tsPattern_8601$ $detail$"}
  480. ]
  481. }
  482. ```
  483. and configure the individual programs to use `RoarrLogger`. In case of Kubernetes, this means adding a `log.config.scalyr.com/attributes.parser: RoarrLogger` annotation to the associated deployment, pod or container.
  484. <a name="roarr-recipes-documenting-use-of-roarr"></a>
  485. ### Documenting use of Roarr
  486. If your package is using Roarr, include instructions in `README.md` describing how to enable logging, e.g.
  487. ```md
  488. ## Logging
  489. This package is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log the program's state.
  490. Export `ROARR_LOG=true` environment variable to enable log printing to stdout.
  491. Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs.
  492. ```