Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
60bcba05
Commit
60bcba05
authored
6 months ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
feat: simplify implementation to JSON per line
parent
a2492532
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1059
[webservice] Intoduce Global Logger for xfel-calibrate
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xfel_calibrate/setup_logging.py
+1
-34
1 addition, 34 deletions
src/xfel_calibrate/setup_logging.py
with
1 addition
and
34 deletions
src/xfel_calibrate/setup_logging.py
+
1
−
34
View file @
60bcba05
...
...
@@ -34,39 +34,6 @@ class CustomJsonFormatter(jsonlogger.JsonFormatter):
log_record
[
'
exc_info
'
]
=
self
.
formatException
(
record
.
exc_info
)
class
JSONArrayHandler
(
logging
.
FileHandler
):
def
__init__
(
self
,
filename
,
mode
=
'
a
'
,
encoding
=
None
,
delay
=
False
):
super
().
__init__
(
filename
,
mode
,
encoding
,
delay
)
self
.
file_empty
=
True
def
emit
(
self
,
record
):
try
:
msg
=
self
.
format
(
record
)
json_msg
=
json
.
loads
(
msg
)
with
self
.
lock
:
if
self
.
stream
is
None
:
self
.
stream
=
self
.
_open
()
if
self
.
file_empty
:
self
.
stream
.
write
(
'
[
\n
'
)
self
.
file_empty
=
False
else
:
self
.
stream
.
write
(
'
,
\n
'
)
json
.
dump
(
json_msg
,
self
.
stream
,
indent
=
2
)
self
.
stream
.
flush
()
except
Exception
:
self
.
handleError
(
record
)
def
close
(
self
):
if
self
.
stream
is
not
None
:
with
self
.
lock
:
if
not
self
.
file_empty
:
self
.
stream
.
write
(
'
\n
]
'
)
super
().
close
()
# Create a logger
logger
=
logging
.
getLogger
()
logger
.
setLevel
(
logging
.
INFO
)
...
...
@@ -80,7 +47,7 @@ formatter = CustomJsonFormatter(
# Function to create a file handler with job-specific JSON log file
def
create_job_specific_handler
(
log_level
,
file_suffix
):
log_file
=
f
'
{
file_suffix
}
_
{
JOB_ID
}
.json
'
handler
=
JSONArray
Handler
(
log_file
,
mode
=
'
a+
'
,
delay
=
True
)
handler
=
logging
.
File
Handler
(
log_file
,
delay
=
True
)
handler
.
setLevel
(
log_level
)
handler
.
setFormatter
(
formatter
)
return
handler
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment