-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #932 from SpiNNakerManchester/log_to_db
Send log messages to the database
- Loading branch information
Showing
8 changed files
with
175 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
spinn_front_end_common/interface/provenance/log_store_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) 2017-2022 The University of Manchester | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import sqlite3 | ||
from spinn_utilities.log_store import LogStore | ||
from spinn_utilities.overrides import overrides | ||
from .provenance_writer import ProvenanceWriter | ||
from .provenance_reader import ProvenanceReader | ||
|
||
|
||
class LogStoreDB(LogStore): | ||
|
||
@overrides(LogStore.store_log) | ||
def store_log(self, level, message, timestamp=None): | ||
try: | ||
with ProvenanceWriter() as db: | ||
db.store_log(level, message, timestamp) | ||
except sqlite3.OperationalError as ex: | ||
if "database is locked" in ex.args: | ||
# Ok ignore this one | ||
# DO NOT log this error here or you will loop forever! | ||
return | ||
# all others are bad | ||
raise | ||
|
||
@overrides(LogStore.retreive_log_messages) | ||
def retreive_log_messages(self, min_level=0): | ||
return ProvenanceReader().retreive_log_messages(min_level) | ||
|
||
@overrides(LogStore.get_location) | ||
def get_location(self): | ||
return ProvenanceReader.get_last_run_database_path() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters