title: python logging formatter order and formating record
body: <p>I have a custom formatter for my Python console log.</p>
  <p>Can someone help me how the whole thing could look nicer and maybe in a for loop?</p>
  <p>I get a long log in the class with a lot of keys and values that I don't need for the console. I want to filter and sort 4 or if available 5 values out of the object.</p>
  <p>This is my code:</p>
  <pre><code>class CustomFormatter(logging.Formatter):
      def_keys = ['asctime', 'name', 'levelname', 'msg']
      def_keys_id = ['asctime', 'name', 'levelname', 'ID', 'msg']
  
      def format(self, record):
          extra = {k: v for k, v in record.__dict__.items()
                   if k in self.def_keys_id}
          extra = collections.OrderedDict(extra)
          if len(extra) &gt; 4:
              for k in self.def_keys_id:
                  extra.move_to_end(k)
              b = list(extra.values())
              c = b[0]+&quot; - &quot;+b[1]+&quot; - &quot;+b[2]+&quot; - &quot;+b[3]+&quot; - &quot;+b[4]
          else:
              for k in self.def_keys:
                  extra.move_to_end(k)
              b = list(extra.values())
              c = b[0]+&quot; - &quot;+b[1]+&quot; - &quot;+b[2]+&quot; - &quot;+b[3]
          return str(c)
  </code></pre>
  <p>Sorted and formatted then come back that:</p>
  <pre><code>Wed Jan  5 11:10:00 2022 - main_logger - INFO - 12345 - run main
  </code></pre>