Comments (6)
A related/perhaps the same issue is relevant error reporting. I've run into issues where mintpy crashes and it turns out to be simple file naming conventions; e.g. underscores vs dashes in a name. Usually the crash point happens well after the actual issue code, so some sort of verbose log file could be helpful when sorting this out.
from mintpy.
Would it be useful to capture all print commands and then write it to a log file? I do that in my software. Here is the template I use for my own projects. I use 2 functions where 1 function is used to run the CLI and capture output, the 2nd function writes it to a log file.
I am sharing my CLI tool I use which I got from Whitebox Tools with some revisions for logging.
def _run_command(self, cmd: str, cwd: Union[str, None]) -> int:
"""
Run command and log to file
:param cmd: Command to execute
:param cwd: Current working directory
:return: Return code 0 is success. 1 is failure
"""
# Create file to capture output
if not os.path.exists(self.log_file):
with open(self.log_file, 'w', newline='') as f:
f.write('DINSAR LOG FILE\n')
f.write(f'TIMESTAMP: {self.timestamp}\n')
f.write('======================================\n')
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, bufsize=0, universal_newlines=True,
cwd=cwd)
return_code = 0
while proc is not None:
try:
line = proc.stdout.readline()
except UnicodeDecodeError:
sys.stdout.flush()
continue
sys.stdout.flush()
if line != '':
print_line = line.replace('\n', '')
print(print_line)
with open(self.log_file, 'a', newline='') as f:
f.write(line)
# Catch errors using string matching
if 'Error:' in line:
msg = f'WARNING: Possible CLI failure'
self._print_to_log(msg)
return_code = 1
else:
break
return return_code
def _print_to_log(self, input_var, print_to_terminal=True) -> None:
"""
Object print command that will also print to the log file
:return:
"""
input_var = str(input_var)
if print_to_terminal:
print(input_var)
path = self.log_file
file_exists = os.path.exists(path)
with open(path, 'a', newline='') as f:
if not file_exists:
f.write('MINTPY LOG FILE\n')
f.write(f'TIMESTAMP: {self.timestamp}\n')
f.write('======================================\n')
if not input_var.endswith('\n'):
input_var += '\n'
f.write(input_var)
Here is a sample log file from my own analyses:
Using the functions as an example, you will have to replace every print()
statement with _print_to_log()
. E.g., _print_to_log('Hello world')
.
If you just want to write it to the log file and not print on the terminal then set print_to_terminal=False
.
from mintpy.
@falkamelung I have not seen (2) in other projects, could you give some references?
We should apply proper logging. I would recommend you to find a permanent solution with proper documentation so that other developers could easily follow it.
from mintpy.
This remains an issue
from mintpy.
Since this issue still remains, let's keep it open for future reference.
from mintpy.
@jlmaurer Could you post an example so that we could be more aware of the scenario? That would help shape the future logging style.
from mintpy.
Related Issues (20)
- hyp3 + mintpy: Error in Second Step (Modify Network) HOT 1
- metadata inconsistency for UTM coordinates HOT 4
- `hyp3`: more metadata for `HDF-EOS5` support HOT 6
- The quality of the time series degrades as the distance from the reference point increases. HOT 1
- Support for multiple GNSS HOT 4
- Projection of Liine-of-Sight (LoS) displacement to the downslope component. HOT 3
- `lalo2yx` behaves incorrectly when set of lat/lons cross UTM zone boundary HOT 2
- in the MintPy tutorial of ScopeEarth2023, theSanFranSenDT42.tar HOT 1
- smallbaselineAPP_aria.ipynb in the tutorial of EarthScope2023οΌthe SanFranSenDT42.tar downloaded from zenodo by 'wget' can't be unzip HOT 2
- `view.py numInvIfgram.h5` error for `RidgecrestSenDT71` HOT 1
- Problem with working on step - invert_network HOT 1
- error in prep_gmtsar : not reading *prm files HOT 1
- Request for Large Image Size
- Can't load HyP3 `INSAR_ISCE_BURST` data in v1.6.0 HOT 3
- FileExistsError: NO two *.prm files found! for prep_gmtsar.py HOT 11
- Reference Point Lalo to XY conversion HOT 1
- How to combine snap with mintpy? HOT 1
- Template RidgecrestSenDT71 timeseries.h5 issue. HOT 2
- Output KMZs not properly geocoded for time series in UTM
- timeseries_SET_ERA5_ramp_demErr.h5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mintpy.