Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Iliya Manolov
neoppod
Commits
17fc0ef9
Commit
17fc0ef9
authored
Oct 27, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logger: new _setup() method to setup the logger when lock is already acquired
This commit only moves code from setup() to _setup()
parent
88c0d6f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
51 deletions
+54
-51
neo/lib/logger.py
neo/lib/logger.py
+54
-51
No files found.
neo/lib/logger.py
View file @
17fc0ef9
...
@@ -135,59 +135,62 @@ class NEOLogger(Logger):
...
@@ -135,59 +135,62 @@ class NEOLogger(Logger):
while
max_size
<
self
.
_record_size
:
while
max_size
<
self
.
_record_size
:
self
.
_record_size
-=
RECORD_SIZE
+
len
(
q
.
popleft
().
msg
)
self
.
_record_size
-=
RECORD_SIZE
+
len
(
q
.
popleft
().
msg
)
def
_setup
(
self
,
filename
=
None
,
reset
=
False
):
from
.
import
protocol
as
p
global
uuid_str
uuid_str
=
p
.
uuid_str
if
self
.
_db
is
not
None
:
self
.
_db
.
close
()
if
not
filename
:
self
.
_db
=
None
self
.
_record_queue
.
clear
()
self
.
_record_size
=
0
return
if
filename
:
self
.
_db
=
sqlite3
.
connect
(
filename
,
check_same_thread
=
False
)
q
=
self
.
_db
.
execute
if
self
.
_max_size
is
None
:
q
(
"PRAGMA synchronous = OFF"
)
q
(
"PRAGMA journal_mode = MEMORY"
)
if
reset
:
for
t
in
'log'
,
'packet'
:
q
(
'DROP TABLE IF EXISTS '
+
t
)
q
(
"""CREATE TABLE IF NOT EXISTS log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date REAL NOT NULL,
name TEXT,
level INTEGER NOT NULL,
pathname TEXT,
lineno INTEGER,
msg TEXT)
"""
)
q
(
"""CREATE INDEX IF NOT EXISTS _log_i1 ON log(date)"""
)
q
(
"""CREATE TABLE IF NOT EXISTS packet (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date REAL NOT NULL,
name TEXT,
msg_id INTEGER NOT NULL,
code INTEGER NOT NULL,
peer TEXT NOT NULL,
body BLOB)
"""
)
q
(
"""CREATE INDEX IF NOT EXISTS _packet_i1 ON packet(date)"""
)
q
(
"""CREATE TABLE IF NOT EXISTS protocol (
date REAL PRIMARY KEY NOT NULL,
text BLOB NOT NULL)
"""
)
with
open
(
inspect
.
getsourcefile
(
p
))
as
p
:
p
=
buffer
(
bz2
.
compress
(
p
.
read
()))
for
t
,
in
q
(
"SELECT text FROM protocol ORDER BY date DESC"
):
if
p
==
t
:
break
else
:
with
self
.
_db
:
q
(
"INSERT INTO protocol VALUES (?,?)"
,
(
time
(),
p
))
def
setup
(
self
,
filename
=
None
,
reset
=
False
):
def
setup
(
self
,
filename
=
None
,
reset
=
False
):
with
self
:
with
self
:
from
.
import
protocol
as
p
self
.
_setup
(
filename
,
reset
)
global
uuid_str
uuid_str
=
p
.
uuid_str
if
self
.
_db
is
not
None
:
self
.
_db
.
close
()
if
not
filename
:
self
.
_db
=
None
self
.
_record_queue
.
clear
()
self
.
_record_size
=
0
return
if
filename
:
self
.
_db
=
sqlite3
.
connect
(
filename
,
check_same_thread
=
False
)
q
=
self
.
_db
.
execute
if
self
.
_max_size
is
None
:
q
(
"PRAGMA synchronous = OFF"
)
q
(
"PRAGMA journal_mode = MEMORY"
)
if
reset
:
for
t
in
'log'
,
'packet'
:
q
(
'DROP TABLE IF EXISTS '
+
t
)
q
(
"""CREATE TABLE IF NOT EXISTS log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date REAL NOT NULL,
name TEXT,
level INTEGER NOT NULL,
pathname TEXT,
lineno INTEGER,
msg TEXT)
"""
)
q
(
"""CREATE INDEX IF NOT EXISTS _log_i1 ON log(date)"""
)
q
(
"""CREATE TABLE IF NOT EXISTS packet (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date REAL NOT NULL,
name TEXT,
msg_id INTEGER NOT NULL,
code INTEGER NOT NULL,
peer TEXT NOT NULL,
body BLOB)
"""
)
q
(
"""CREATE INDEX IF NOT EXISTS _packet_i1 ON packet(date)"""
)
q
(
"""CREATE TABLE IF NOT EXISTS protocol (
date REAL PRIMARY KEY NOT NULL,
text BLOB NOT NULL)
"""
)
with
open
(
inspect
.
getsourcefile
(
p
))
as
p
:
p
=
buffer
(
bz2
.
compress
(
p
.
read
()))
for
t
,
in
q
(
"SELECT text FROM protocol ORDER BY date DESC"
):
if
p
==
t
:
break
else
:
with
self
.
_db
:
q
(
"INSERT INTO protocol VALUES (?,?)"
,
(
time
(),
p
))
__del__
=
setup
__del__
=
setup
def
isEnabledFor
(
self
,
level
):
def
isEnabledFor
(
self
,
level
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment