Skip to content

Commit f9a0e1f

Browse files
authored
docs: added logging documentation (#25)
* added documentation on logging levels * added environment variable for logging * added logging redirecting docs
1 parent 4bf059d commit f9a0e1f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

docs/logging.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
Logging is used throughout dgraphpandas using the standard [logging module](https://docs.python.org/3/library/logging.html).
3+
4+
## Command Line
5+
6+
If you are using the command line tool then setting the logging level is as simple as passing an additional parameter.
7+
8+
```sh
9+
dgraphpandas -v DEBUG
10+
```
11+
12+
Where the following levels are supported: `DEBUG,INFO,WARNING,ERROR,NOTSET`
13+
14+
### Coloring Logs
15+
By default these will log to stdout with no color but you can also add coloring by installing the [`coloredlogs`](https://pypi.org/project/coloredlogs/) module 🌈.
16+
17+
```sh
18+
python -m pip install coloredlogs
19+
```
20+
21+
### Environment Variables
22+
23+
The logging level can also be set via environment variable:
24+
25+
```sh
26+
export DGRAPHPANDAS_LOG=DEBUG
27+
```
28+
29+
## Module
30+
31+
If you are using dgraphpandas in your own script then you can set logging on a more granular level like so:
32+
33+
```py
34+
import logging
35+
import dgraphpandas as dpd
36+
37+
logging.basicConfig()
38+
logging.getLogger('dgraphpandas.rdf').setLevel(logging.DEBUG)
39+
logging.getLogger('dgraphpandas.types').setLevel(logging.DEBUG)
40+
logging.getLogger('dgraphpandas.config').setLevel(logging.DEBUG)
41+
logging.getLogger('dgraphpandas.strategies.horizontal').setLevel(logging.DEBUG)
42+
logging.getLogger('dgraphpandas.strategies.vertical').setLevel(logging.DEBUG)
43+
logging.getLogger('dgraphpandas.strategies.vertical_helpers').setLevel(logging.DEBUG)
44+
logging.getLogger('dgraphpandas.strategies.schema').setLevel(logging.DEBUG)
45+
logging.getLogger('dgraphpandas.writers.upserts').setLevel(logging.DEBUG)
46+
logging.getLogger('dgraphpandas.writers.schema').setLevel(logging.DEBUG)
47+
48+
# your logic
49+
dpd.to_rdf('input.csv', config, 'config_key')
50+
```
51+
52+
Naturally this means that you can redirect logs to any handler you would like:
53+
54+
```py
55+
logging_file = 'dgraphpandas.log'
56+
57+
logging.basicConfig()
58+
rdf_logger = logging.getLogger('dgraphpandas.rdf')
59+
rdf_logger.setLevel(logging.DEBUG)
60+
61+
# Create and add any Handler
62+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
63+
file_handler = logging.FileHandler(logging_file)
64+
file_handler.setFormatter(formatter)
65+
66+
rdf_logger.addHandler(file_handler)
67+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ nav:
77
- Getting Started: 'getting_started.md'
88
- Horizontal & Vertical Formats: 'horizontal_and_vertical_formats.md'
99
- Configuration: 'configuration.md'
10+
- Logging: 'logging.md'
1011
- Schema & Types: 'schema_and_types.md'
1112
- Working with Larger Files: 'working_with_larger_files.md'
1213
- Samples:

0 commit comments

Comments
 (0)