Energy logging code