Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csppfetch
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
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
cspp_geo
csppfetch
Commits
d8e394ec
Commit
d8e394ec
authored
4 years ago
by
Alan De Smet
Browse files
Options
Downloads
Patches
Plain Diff
Expanded logging support
parent
7820b39f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
example/aitf-update-cache
+10
-8
10 additions, 8 deletions
example/aitf-update-cache
example/aitf/argparsetools.py
+30
-7
30 additions, 7 deletions
example/aitf/argparsetools.py
example/aitf/conlog.py
+22
-0
22 additions, 0 deletions
example/aitf/conlog.py
with
62 additions
and
15 deletions
example/aitf-update-cache
+
10
−
8
View file @
d8e394ec
...
@@ -7,7 +7,8 @@ import tempfile
...
@@ -7,7 +7,8 @@ import tempfile
sys
.
path
.
append
(
os
.
path
.
abspath
(
'
..
'
))
sys
.
path
.
append
(
os
.
path
.
abspath
(
'
..
'
))
from
csppfetch
import
DownloadStatistics
from
csppfetch
import
DownloadStatistics
import
aitf.ancil
import
aitf.ancil
from
aitf.conlog
import
add_console_logging
import
aitf.conlog
import
logging
# Environment variable that can hold the path to the cache
# Environment variable that can hold the path to the cache
...
@@ -75,12 +76,13 @@ def parse_args():
...
@@ -75,12 +76,13 @@ def parse_args():
return
args
return
args
def
print_download_report
(
name
,
stats
):
def
log_download_report
(
name
,
stats
):
print
(
name
)
logging
.
summary
(
name
)
print
(
"
\n
"
.
join
([
"
"
+
x
for
x
in
stats
.
report
()]))
for
x
in
stats
.
report
():
logging
.
summary
(
"
"
+
x
)
def
main
():
def
main
():
#add_console
_logging()
aitf
.
conlog
.
setup
_logging
()
args
=
parse_args
()
args
=
parse_args
()
sststats
=
DownloadStatistics
()
sststats
=
DownloadStatistics
()
...
@@ -89,7 +91,7 @@ def main():
...
@@ -89,7 +91,7 @@ def main():
end_time
=
args
.
newest
,
end_time
=
args
.
newest
,
download_stats
=
sststats
,
download_stats
=
sststats
,
)
)
print
_download_report
(
"
SST Download Summary
"
,
sststats
)
log
_download_report
(
"
SST Download Summary
"
,
sststats
)
gfsstats
=
DownloadStatistics
()
gfsstats
=
DownloadStatistics
()
aitf
.
ancil
.
GFS
.
update_cache
(
args
.
dir
,
aitf
.
ancil
.
GFS
.
update_cache
(
args
.
dir
,
...
@@ -97,9 +99,9 @@ def main():
...
@@ -97,9 +99,9 @@ def main():
end_time
=
args
.
newest
,
end_time
=
args
.
newest
,
download_stats
=
gfsstats
,
download_stats
=
gfsstats
,
)
)
print
_download_report
(
"
GFS Download Summary
"
,
gfsstats
)
log
_download_report
(
"
GFS Download Summary
"
,
gfsstats
)
print
_download_report
(
"
Total Download Summary
"
,
sststats
+
gfsstats
)
log
_download_report
(
"
Total Download Summary
"
,
sststats
+
gfsstats
)
return
0
return
0
...
...
This diff is collapsed.
Click to expand it.
example/aitf/argparsetools.py
+
30
−
7
View file @
d8e394ec
...
@@ -11,11 +11,33 @@ CACHE_ENV="CSPP_GEO_AITF_CACHE"
...
@@ -11,11 +11,33 @@ CACHE_ENV="CSPP_GEO_AITF_CACHE"
def
argerror
(
msg
):
def
argerror
(
msg
):
raise
argparse
.
ArgumentTypeError
(
msg
)
raise
argparse
.
ArgumentTypeError
(
msg
)
logging_levels
=
None
def
initialize_logging_level_info
():
import
logging
global
logging_levels
# Need to delay until logging is configured
logging_levels
=
[
(
'
warnings
'
,
logging
.
WARNING
)
]
# These are from conlog, but I don't want to depend on them.
if
hasattr
(
logging
,
'
SUMMARY
'
):
logging_levels
+=
[
(
'
a summary
'
,
logging
.
SUMMARY
)
]
if
hasattr
(
logging
,
'
PROGRESS
'
):
logging_levels
+=
[
(
'
progress
'
,
logging
.
PROGRESS
)
]
logging_levels
+=
[(
'
general information
'
,
logging
.
INFO
),
(
'
debugging information
'
,
logging
.
DEBUG
)
]
def
add_verbose_quiet_args
(
parser
):
def
add_verbose_quiet_args
(
parser
):
import
logging
initialize_logging_level_info
()
helplist
=
[]
for
i
,
lvldesc
in
enumerate
([
x
[
0
]
for
x
in
logging_levels
[
1
:]]):
helplist
.
append
(
"
-
"
+
(
"
v
"
*
(
i
+
1
))
+
f
"
adds
{
lvldesc
}
,
"
)
help
=
"
increase verbosity of output;
"
+
""
.
join
(
helplist
)
+
'
(default: only warnings and errors)
'
g
=
parser
.
add_mutually_exclusive_group
()
g
=
parser
.
add_mutually_exclusive_group
()
g
.
add_argument
(
'
--verbose
'
,
'
-v
'
,
dest
=
'
verbosity
'
,
action
=
'
count
'
,
g
.
add_argument
(
'
--verbose
'
,
'
-v
'
,
dest
=
'
verbosity
'
,
action
=
'
count
'
,
help
=
'
increase verbosity of output;-v adds a summary, -vv adds general information, -vvv adds debugging information (default: only warnings and errors)
'
help
=
help
)
)
g
.
add_argument
(
'
--quiet
'
,
'
-q
'
,
dest
=
'
silent
'
,
action
=
'
store_true
'
,
g
.
add_argument
(
'
--quiet
'
,
'
-q
'
,
dest
=
'
silent
'
,
action
=
'
store_true
'
,
help
=
'
only print errors
'
help
=
'
only print errors
'
)
)
...
@@ -23,11 +45,12 @@ def add_verbose_quiet_args(parser):
...
@@ -23,11 +45,12 @@ def add_verbose_quiet_args(parser):
def
process_verbosity
(
args
):
def
process_verbosity
(
args
):
import
logging
import
logging
#logging_levels = [logging.WARNING, logging.SUMMARY, logging.INFO, logging.DEBUG]
levels
=
[
x
[
1
]
for
x
in
logging_levels
]
logging_levels
=
[
logging
.
WARNING
,
logging
.
INFO
,
logging
.
DEBUG
]
if
args
.
verbosity
is
None
:
if
args
.
verbosity
is
None
:
args
.
verbosity
=
0
args
.
verbosity
=
0
if
args
.
verbosity
>=
len
(
logging_levels
):
args
.
verbosity
=
-
1
if
args
.
verbosity
>=
len
(
logging_levels
):
args
.
log_level
=
logging_levels
[
args
.
verbosity
]
args
.
verbosity
=
len
(
logging_levels
)
-
1
args
.
log_level
=
logging_levels
[
args
.
verbosity
][
1
]
if
args
.
silent
:
if
args
.
silent
:
args
.
log_level
=
logging
.
ERROR
args
.
log_level
=
logging
.
ERROR
logging
.
getLogger
().
setLevel
(
args
.
log_level
)
logging
.
getLogger
().
setLevel
(
args
.
log_level
)
...
...
This diff is collapsed.
Click to expand it.
example/aitf/conlog.py
+
22
−
0
View file @
d8e394ec
...
@@ -3,6 +3,19 @@
...
@@ -3,6 +3,19 @@
import
logging
import
logging
import
sys
import
sys
def
create_log_level
(
level
,
name
):
logging
.
addLevelName
(
level
,
name
.
upper
())
def
logger_func
(
self
,
message
,
*
args
,
**
kws
):
if
self
.
isEnabledFor
(
level
):
self
.
_log
(
level
,
message
,
args
,
**
kws
)
def
logging_func
(
message
,
*
args
,
**
kws
):
logging
.
log
(
level
,
message
,
*
args
,
**
kws
)
setattr
(
logging
.
Logger
,
name
.
lower
(),
logger_func
)
setattr
(
logging
,
name
.
lower
(),
logging_func
)
setattr
(
logging
,
name
.
upper
(),
level
)
logging
.
basicConfig
()
def
add_console_logging
():
def
add_console_logging
():
"""
Log to console, prefixing entries with the log level
"""
Log to console, prefixing entries with the log level
...
@@ -14,6 +27,8 @@ def add_console_logging():
...
@@ -14,6 +27,8 @@ def add_console_logging():
labels
=
{
labels
=
{
logging
.
DEBUG
:
"
debug:
"
,
logging
.
DEBUG
:
"
debug:
"
,
logging
.
INFO
:
""
,
logging
.
INFO
:
""
,
logging
.
PROGRESS
:
""
,
logging
.
SUMMARY
:
""
,
logging
.
WARNING
:
"
Warning:
"
,
logging
.
WARNING
:
"
Warning:
"
,
logging
.
ERROR
:
"
ERROR:
"
,
logging
.
ERROR
:
"
ERROR:
"
,
logging
.
CRITICAL
:
"
CRITICAL ERROR:
"
,
logging
.
CRITICAL
:
"
CRITICAL ERROR:
"
,
...
@@ -29,8 +44,15 @@ def add_console_logging():
...
@@ -29,8 +44,15 @@ def add_console_logging():
console_handler
.
setFormatter
(
console_formatter
)
console_handler
.
setFormatter
(
console_formatter
)
root
=
logging
.
getLogger
()
root
=
logging
.
getLogger
()
root
.
handlers
.
clear
()
root
.
addHandler
(
console_handler
)
root
.
addHandler
(
console_handler
)
root
.
setLevel
(
logging
.
DEBUG
)
root
.
setLevel
(
logging
.
DEBUG
)
return
console_handler
return
console_handler
def
setup_logging
():
create_log_level
(
25
,
"
SUMMARY
"
)
create_log_level
(
22
,
"
PROGRESS
"
)
logging
.
basicConfig
()
add_console_logging
()
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