Skip to content

Commit 2ec8f1b

Browse files
committed
logging management
1 parent c979b2f commit 2ec8f1b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

doc/grid_identification.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Activate verbose
3434

3535
.. code-block:: python
3636
37-
import logging
38-
logging.getLogger().setLevel('DEBUG') # Available options: ERROR, WARNING, INFO, DEBUG
37+
from py_eddy_tracker import start_logger
38+
start_logger().setLevel('DEBUG') # Available options: ERROR, WARNING, INFO, DEBUG
3939
4040
Run identification
4141

@@ -74,6 +74,7 @@ Save identification data
7474

7575
.. code-block:: python
7676
77+
from netCDF import Dataset
7778
with Dataset(date.strftime('share/Anticyclonic_%Y%m%d.nc'), 'w') as h:
7879
a.to_netcdf(h)
7980
with Dataset(date.strftime('share/Cyclonic_%Y%m%d.nc'), 'w') as h:

doc/observation_manipulation.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
===================================================
22
How manipulate tracking/identification observations
33
===================================================
4+
5+
Eddies subsetting
6+
*****************
7+
8+
EddySubSetter will allow to select eddies on an atlas or on simple identification file.
9+
10+
'''bash
11+
'--period' options will allow to sel
12+
'''

src/py_eddy_tracker/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@
3333
import zarr
3434

3535

36+
def start_logger():
37+
FORMAT_LOG = "%(levelname)-8s %(asctime)s %(module)s.%(funcName)s :\n\t\t\t\t\t%(message)s"
38+
# set up logging to CONSOLE
39+
console = logging.StreamHandler()
40+
console.setFormatter(ColoredFormatter(FORMAT_LOG))
41+
logger = logging.getLogger('pet')
42+
# add the handler to the root logger
43+
logger.addHandler(console)
44+
return logger
45+
46+
3647
class ColoredFormatter(logging.Formatter):
3748
COLOR_LEVEL = dict(
3849
CRITICAL="\037[37;41m",
@@ -60,9 +71,6 @@ class EddyParser(ArgumentParser):
6071
"""General parser for applications
6172
"""
6273

63-
FORMAT_LOG = "%(levelname)-8s %(asctime)s %(module)s." \
64-
"%(funcName)s :\n\t\t\t\t\t%(message)s"
65-
6674
def __init__(self, *args, **kwargs):
6775
super(EddyParser, self).__init__(*args, **kwargs)
6876
self.add_base_argument()
@@ -77,12 +85,7 @@ def add_base_argument(self):
7785
' ERROR, CRITICAL')
7886

7987
def parse_args(self, *args, **kwargs):
80-
# set up logging to CONSOLE
81-
console = logging.StreamHandler()
82-
console.setFormatter(ColoredFormatter(self.FORMAT_LOG))
83-
logger = logging.getLogger('pet')
84-
# add the handler to the root logger
85-
logger.addHandler(console)
88+
logger = start_logger()
8689
# Parsing
8790
opts = super(EddyParser, self).parse_args(*args, **kwargs)
8891
# set current level

0 commit comments

Comments
 (0)