question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A sort_keys would be nice.

I know I can implement it myself with a few lines of code, but that doesn’t work from a logging config file.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dclar43commented, Oct 9, 2018

I’d like this feature as well and I’m kind of confused why this was closed.

@tuukkamustonen said that OrderedDict wouldn’t need to be used because passing sort_keys=True to json.dumps handles the sorting.

Then @offero said

Yes, use sort_keys. Making a new OrderedDict for each log output would be a large overhead.

and closed it. Which doesn’t really make sense to me. Maybe I’m misunderstanding something.

As far as I can tell the only way we can effectively call json.dumps with sort_keys=True is to pass our own json_serializer to JsonFormatter.

Some brief profiling:

Test data is from a JSON file containing 8000 randomly generated entries(generated using https://www.json-generator.com) into a dict.

I ran both json.dumps(data) and json.dumps(data, sort_keys=True) 100 times.

The former spent a total time of 14,554ms in iterencode while the ladder spent 16,580ms in iterencode.

So on average not sorting took 145.54ms and sorting took 165.8ms resulting in a 20.26ms difference between the two.

These numbers are from Python 3.7 but Python 3.5 showed similar results.

0reactions
dckccommented, Aug 13, 2017

I don’t understand. How do you recommend I use sort_keys from a logging config file? I don’t see any way to do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sortkeys | Looker
The sortkeys parameter lets you specify one or more columns of a persistent derived table (PDT) or an aggregate table on which to...
Read more >
Module:Sortkey
This module sanitizes and escapes sortkeys so that they can be used inside the data-sort-value attribute of HTML tags in combination with table...
Read more >
Sorting HOW TO — Python 3.11.1 documentation
Python lists have a built-in list.sort() method that modifies the list in-place. There is also a sorted() built-in function that builds a new...
Read more >
jq Manual (development version)
Flush the output after each JSON object is printed (useful if you're piping a slow data source into jq and piping jq's output...
Read more >
sortKey doesn't work on product connection in the ...
Describe the bug If I add sortKey as an arg to the products connection in the unoptimized sdk, either I get a PRICE...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found