Skip to content

Commit 25736c5

Browse files
Merge pull request #189 from rustprooflabs/logging-to-stdout
Logs go to stdout instead of internally defined logfile
2 parents 65ad907 + 767ff93 commit 25736c5

File tree

3 files changed

+9
-51
lines changed

3 files changed

+9
-51
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ mkdir ~/pgosm-data
5656
```
5757

5858
Set environment variables for the temporary Postgres connection in Docker.
59+
These are required for the Docker container to run.
60+
5961

6062
```bash
6163
export POSTGRES_USER=postgres
@@ -74,11 +76,10 @@ docker run --name pgosm -d --rm \
7476
```
7577

7678
Run the processing for the Washington D.C. The `docker/pgosm_flex.py` script
77-
requires three (3) parameters, typical use will use four (4) to include
79+
requires two (2) parameters, typical use will use three (3) to include
7880
the `--subregion`.
7981

8082

81-
* PgOSM-Flex layer set (`run-all`)
8283
* Total RAM for osm2pgsql, Postgres and OS (`8`)
8384
* Region (`north-america/us`)
8485
* Sub-region (`district-of-columbia`) (Optional)
@@ -87,10 +88,7 @@ the `--subregion`.
8788

8889
```bash
8990
docker exec -it \
90-
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
91-
-e POSTGRES_USER=$POSTGRES_USER \
9291
pgosm python3 docker/pgosm_flex.py \
93-
--layerset=run-all \
9492
--ram=8 \
9593
--region=north-america/us \
9694
--subregion=district-of-columbia

docker/pgosm_flex.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ def run_pgosm_flex(layerset, layerset_path, ram, region, subregion,
101101
subregion = None
102102

103103
paths = get_paths(base_path=basepath)
104-
log_file = get_log_path(region, subregion, paths)
105104

106-
setup_logger(log_file, debug)
105+
setup_logger(debug)
107106
logger = logging.getLogger('pgosm-flex')
108107
logger.info('PgOSM Flex starting...')
109108
prepare_data(region=region,
@@ -196,14 +195,11 @@ def set_env_vars(region, subregion, srid, language, pgosm_date, layerset,
196195

197196

198197

199-
def setup_logger(log_file, debug):
198+
def setup_logger(debug):
200199
"""Prepares logging.
201200
202201
Parameters
203202
------------------------------
204-
log_file : str
205-
Path to log file
206-
207203
debug : bool
208204
Enables debug mode when True. INFO when False.
209205
"""
@@ -213,7 +209,7 @@ def setup_logger(log_file, debug):
213209
log_level = logging.INFO
214210

215211
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(module)s:%(message)s'
216-
logging.basicConfig(filename=log_file,
212+
logging.basicConfig(stream=sys.stdout,
217213
level=log_level,
218214
filemode='w',
219215
format=log_format)
@@ -222,43 +218,9 @@ def setup_logger(log_file, debug):
222218
logging.getLogger('urllib3').setLevel(logging.INFO)
223219

224220
logger = logging.getLogger('pgosm-flex')
225-
logger.setLevel(log_level)
226-
handler = logging.FileHandler(filename=log_file)
227-
handler.setLevel(log_level)
228-
formatter = logging.Formatter(log_format)
229-
handler.setFormatter(formatter)
230-
logger.addHandler(handler)
231221
logger.debug('Logger configured')
232222

233223

234-
def get_log_path(region, subregion, paths):
235-
"""Returns path to log_file for given region/subregion.
236-
237-
Parameters
238-
---------------------
239-
region : str
240-
subregion : str
241-
paths : dict
242-
243-
Returns
244-
---------------------
245-
log_file : str
246-
"""
247-
region_clean = region.replace('/', '-')
248-
if subregion is None:
249-
filename = f'{region_clean}.log'
250-
else:
251-
filename = f'{region_clean}-{subregion}.log'
252-
253-
# Users will see this when they run, can copy/paste tail command.
254-
# Path matches path if following project's main README.md
255-
print(f'Log filename: {filename}')
256-
print('If running in Docker following procedures the file can be monitored')
257-
print(f' tail -f ~/pgosm-data/{filename}')
258-
259-
log_file = os.path.join(paths['out_path'], filename)
260-
return log_file
261-
262224

263225
def get_paths(base_path):
264226
"""Returns dictionary of various paths used.
@@ -622,7 +584,7 @@ def run_osm2pgsql(osm2pgsql_command, paths):
622584
paths : dict
623585
"""
624586
logger = logging.getLogger('pgosm-flex')
625-
logger.info(f'Running {osm2pgsql_command}')
587+
logger.info(f'Running osm2pgsql')
626588

627589
output = subprocess.run(osm2pgsql_command.split(),
628590
text=True,

docs/DOCKER-RUN.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ The 3rd parameter tells the script the server has 8 GB RAM available for osm2pgs
5858

5959
```bash
6060
docker exec -it \
61-
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_USER=$POSTGRES_USER \
6261
pgosm python3 docker/pgosm_flex.py \
6362
--layerset=default \
6463
--ram=8 \
6564
--region=north-america/us \
66-
--subregion=district-of-columbia
65+
--subregion=district-of-columbia \
66+
&> ~/pgosm-data/pgosm-flex.log
6767
```
6868

6969

@@ -121,7 +121,6 @@ used during development.
121121
122122
```bash
123123
docker exec -it \
124-
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_USER=$POSTGRES_USER \
125124
pgosm python3 docker/pgosm_flex.py \
126125
--layerset=poi \
127126
--layerset-path=/custom-layerset/ \
@@ -164,7 +163,6 @@ Define the layerset name (`--layerset=poi`) and path
164163
165164
```bash
166165
docker exec -it \
167-
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_USER=$POSTGRES_USER \
168166
pgosm python3 docker/pgosm_flex.py \
169167
--layerset=poi \
170168
--layerset-path=/custom-layerset/ \

0 commit comments

Comments
 (0)