Skip to content

Commit c862605

Browse files
committed
[format] add duration-divisor
1 parent 77d102f commit c862605

17 files changed

Lines changed: 285 additions & 53 deletions

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ Features:
188188
to specify the field that contains a duration in the
189189
log message. If a duration is available, it will be
190190
used to calculate time spans in the TIMELINE view.
191+
If the value of field is a number that is not in
192+
seconds, the `duration-divisor` property can be used
193+
to convert it. For example, if the duration field is
194+
in milliseconds, the divisor should be 1000. The
195+
duration can be accessed in the SQL vtables through
196+
the `log_duration` column. For JSON-lines logs, the
197+
special `__duration__` field name can be used in the
198+
`line-format` to add a humanized version of the
199+
duration to the pretty-printed message.
191200
* The TIMELINE view now shows rows for user-defined tags
192201
and partitions. Each tagged log line appears as a
193202
separate entry in the timeline. Tags whose names start

docs/schemas/format-v1.schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@
189189
"description": "The name of the duration field in the log message pattern",
190190
"type": "string"
191191
},
192+
"duration-divisor": {
193+
"title": "/<format_name>/duration-divisor",
194+
"description": "The value to divide a duration by to convert it to seconds. For example, if the duration field is in milliseconds, the divisor should be 1000.",
195+
"type": [
196+
"integer",
197+
"number"
198+
]
199+
},
192200
"url": {
193201
"title": "/<format_name>/url",
194202
"description": "A URL with more information about this log format",
@@ -499,7 +507,7 @@
499507
"$ref": "#/definitions/style"
500508
},
501509
"captures": {
502-
"description": "The style to use for the entire pattern",
510+
"description": "Styles for individual named capture groups in the pattern",
503511
"title": "/<format_name>/value/<value_name>/highlights/<highlight_name>/captures",
504512
"type": "object",
505513
"patternProperties": {

docs/source/formats.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ object with the following fields:
208208
of the message field that should be inserted at this point in the
209209
message. The special :code:`__timestamp__` field name can be used to
210210
insert a human-readable timestamp. The :code:`__level__` field can be
211-
used to insert the level name as defined by lnav.
211+
used to insert the level name as defined by lnav. The
212+
:code:`__duration__` field can be used to insert a humanized duration
213+
value (e.g. "1m23s") when a duration field is defined for the format.
212214

213215
.. tip::
214216

@@ -356,6 +358,10 @@ object with the following fields:
356358
operation. If a duration is available, it will be used to calculate
357359
time spans in the TIMELINE view.
358360

361+
:duration-divisor: The value to divide a duration by to convert it to
362+
seconds. For example, if the duration field is in milliseconds,
363+
the divisor should be 1000.
364+
359365
:src-file-field: (v0.14.0+) The name of the field that contains the source
360366
file name where the log statement originated. This field is accessible
361367
in SQL queries as the :code:`log_src_file` column.

src/formats/mongodb_json_log.json

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"level-field": "s",
99
"body-field": "msg",
1010
"timestamp-field": "t/$date",
11+
"duration-field": "attr/durationMillis",
12+
"duration-divisor": 1000,
1113
"line-format": [
1214
{
1315
"field": "__timestamp__"
@@ -50,10 +52,27 @@
5052
"default-value": ""
5153
},
5254
{
53-
"prefix": " (\u2194 ",
54-
"field": "attr/durationMillis",
55+
"prefix": " deleted ",
56+
"field": "attr/ndeleted",
5557
"default-value": "",
56-
"suffix": "ms"
58+
"suffix": " doc(s) using"
59+
},
60+
{
61+
"prefix": " inserted ",
62+
"field": "attr/ninserted",
63+
"default-value": "",
64+
"suffix": " doc(s) using"
65+
},
66+
{
67+
"prefix": " got ",
68+
"field": "attr/nreturned",
69+
"default-value": "",
70+
"suffix": " doc(s) using"
71+
},
72+
{
73+
"prefix": " (\u2194 ",
74+
"field": "__duration__",
75+
"default-value": ""
5776
},
5877
{
5978
"prefix": " ",
@@ -135,6 +154,18 @@
135154
"debug4": "D4",
136155
"debug5": "D5"
137156
},
157+
"opid": {
158+
"source": "from-whole-msg",
159+
"description": {
160+
"find": {
161+
"format": [
162+
{
163+
"field": "attr/ns"
164+
}
165+
]
166+
}
167+
}
168+
},
138169
"value": {
139170
"s": {
140171
"kind": "string",
@@ -166,6 +197,16 @@
166197
"hidden": true,
167198
"description": "Additional attributes for the log message"
168199
},
200+
"attr/action/outcome/errorMessage": {
201+
"kind": "string",
202+
"highlights": {
203+
"error": {
204+
"base-style": {
205+
"color": "Red"
206+
}
207+
}
208+
}
209+
},
169210
"attr/authenticationDatabase": {
170211
"kind": "string",
171212
"description": "The authenticating database for a connection"
@@ -211,6 +252,35 @@
211252
"kind": "json",
212253
"description": "The document for a command"
213254
},
255+
"attr/errMsg": {
256+
"kind": "string",
257+
"highlights": {
258+
"error": {
259+
"base-style": {
260+
"color": "Red"
261+
}
262+
}
263+
}
264+
},
265+
"attr/errName": {
266+
"kind": "string",
267+
"highlights": {
268+
"error": {
269+
"base-style": {
270+
"color": "Red"
271+
}
272+
}
273+
}
274+
},
275+
"attr/error": {
276+
"highlights": {
277+
"error": {
278+
"base-style": {
279+
"color": "Red"
280+
}
281+
}
282+
}
283+
},
214284
"attr/durationMillis": {
215285
"kind": "integer",
216286
"description": "The duration of the operation in milliseconds"
@@ -224,6 +294,14 @@
224294
"description": "The namespace for a query",
225295
"identifier": true
226296
},
297+
"attr/ndeleted": {
298+
"kind": "integer",
299+
"description": "The number of documents deleted"
300+
},
301+
"attr/ninserted": {
302+
"kind": "integer",
303+
"description": "The number of documents inserted"
304+
},
227305
"attr/ns" : {
228306
"kind": "string",
229307
"description": "The namespace for a query"
@@ -232,6 +310,10 @@
232310
"kind": "integer",
233311
"description": "The number of documents deleted"
234312
},
313+
"attr/nreturned": {
314+
"kind": "integer",
315+
"description": "The number of documents returned by the query"
316+
},
235317
"attr/originatingCommand/filter": {
236318
"kind": "json",
237319
"description": "The filter of the originating command for a query"

0 commit comments

Comments
 (0)