title: How to open syslog files in Python
body: <p>I am trying an assignment to open a syslog for a server program (called ticky) that creates logs and errors and then assign the errors to a dictionary and export to a csv file to sort and host to a webpage,</p>
  <p>I am unsure of how to access syslog files, as the course only went into sys.argv and I don't know if this can be used or if I need to figure out how to use syslog module. Once the log is opened, the regex will pull the error message and add it to the dictionary, either creating a new entry or adding value to an existing key.</p>
  <p>Am I on the right track?</p>
  <pre><code>    #!/usr/bin/env python3
  
      import re
      import sys
  
      errors = {}
  
      # log line format
      # Jun 1 11:06:48 ubuntu.local ticky: ERROR: Connection to DB failed (username)
  
      logfile = sys.argv[1]
      # NOTE: Check to find correct log file
      with open(logfile) as f:
          for line in f:
              if &quot;ERROR:&quot; not in line:
                  continue
              regex_error = r&quot;ERROR: (\d+) &quot;
              &quot;&quot;&quot;searches for error messages&quot;&quot;&quot;
              error = re.search(regex_error, line)
              if error is None:
                  continue
              name = error[1]
              errors[name] = errors.get(name, 0) + 1
  </code></pre>