old_contents: import os
  import time
  import sqlite3
  from contextlib import closing
  import config
  
  
  def init_db():
      with closing(get_db()) as db:
          schema_path = os.path.join(config.Config["app_path"], "schema.sql")
          with open(schema_path, "r") as f:
              db.executescript(f.read())
          db.commit()
  
  
  def get_db():
      conn = sqlite3.connect(config.Config["dbfile"])
      return conn
  
  
  def write_log(message, error=False, alarm=False):
      with closing(get_db()) as db:
          db.cursor().execute(
              "insert into log "
              "(error, alarm, message, log_time) "
              "values (:error, :alarm, ':message', :time);",
              {
                  "error": error,
                  "alarm": alarm,
                  "message": message,
                  "time": time.time()
              })
  
new_contents: import os
  import time
  import sqlite3
  from contextlib import closing
  import config
  
  
  def init_db():
      with closing(get_db()) as db:
          schema_path = os.path.join(config.Config["app_path"], "schema.sql")
          with open(schema_path, "r") as f:
              db.executescript(f.read())
          db.commit()
  
  
  def get_db():
      conn = sqlite3.connect(config.Config["dbfile"])
      return conn
  
  
  def write_log(message, error=False, alarm=False):
      with closing(get_db()) as db:
          db.cursor().execute(
              "insert into log "
              "(error, alarm, message, log_time) "
              "values (:error, :alarm, ':message', :time);",
              {
                  "error": error,
                  "alarm": alarm,
                  "message": message,
                  "time": time.time()
              })
          db.commit()
  
subject: make sure to commit logs to db