scraper-npm 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scraper_npm-1.0.4/LICENSE +22 -0
- scraper_npm-1.0.4/MANIFEST.in +10 -0
- scraper_npm-1.0.4/PKG-INFO +233 -0
- scraper_npm-1.0.4/README.md +194 -0
- scraper_npm-1.0.4/pyproject.toml +50 -0
- scraper_npm-1.0.4/requirements.txt +3 -0
- scraper_npm-1.0.4/scraper_npm/__init__.py +10 -0
- scraper_npm-1.0.4/scraper_npm/logger.py +107 -0
- scraper_npm-1.0.4/scraper_npm/main.py +441 -0
- scraper_npm-1.0.4/scraper_npm.egg-info/PKG-INFO +233 -0
- scraper_npm-1.0.4/scraper_npm.egg-info/SOURCES.txt +15 -0
- scraper_npm-1.0.4/scraper_npm.egg-info/dependency_links.txt +1 -0
- scraper_npm-1.0.4/scraper_npm.egg-info/not-zip-safe +1 -0
- scraper_npm-1.0.4/scraper_npm.egg-info/requires.txt +9 -0
- scraper_npm-1.0.4/scraper_npm.egg-info/top_level.txt +1 -0
- scraper_npm-1.0.4/setup.cfg +4 -0
- scraper_npm-1.0.4/setup.py +61 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Michael Weng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scraper-npm
|
|
3
|
+
Version: 1.0.4
|
|
4
|
+
Summary: A beautiful, colorful logger for Python with emoji icons and timestamp support
|
|
5
|
+
Home-page: https://github.com/mgcrae/scraper-npm
|
|
6
|
+
Author: Michael Weng
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/mgcrae/scraper-npm
|
|
9
|
+
Project-URL: Documentation, https://github.com/mgcrae/scraper-npm#readme
|
|
10
|
+
Project-URL: Repository, https://github.com/mgcrae/scraper-npm
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/mgcrae/scraper-npm/issues
|
|
12
|
+
Keywords: logger,pretty,logging,pino,color,emoji,timestamp
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Topic :: System :: Logging
|
|
26
|
+
Requires-Python: >=3.7
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
30
|
+
Requires-Dist: aiofiles>=23.0.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
34
|
+
Provides-Extra: netifaces
|
|
35
|
+
Requires-Dist: netifaces>=0.11.0; extra == "netifaces"
|
|
36
|
+
Dynamic: home-page
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
|
|
40
|
+
# scraper-npm
|
|
41
|
+
|
|
42
|
+
A beautiful, colorful logger for Python with emoji icons and timestamp support. Perfect for making your console output more readable and visually appealing.
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- đ¨ **Colorful output** - Each log level has its own color
|
|
47
|
+
- đ¯ **Emoji icons** - Visual indicators for different log levels
|
|
48
|
+
- â° **ISO timestamps** - Automatic timestamp formatting
|
|
49
|
+
- đ **Async support** - Built with asyncio for async operations
|
|
50
|
+
- đ§ **Simple API** - Easy to use
|
|
51
|
+
- đĻ **Type hints** - Full type annotations included
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install scraper-npm
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from scraper_npm import logger
|
|
63
|
+
|
|
64
|
+
logger.info('Application started')
|
|
65
|
+
logger.warn('This is a warning')
|
|
66
|
+
logger.error('Something went wrong')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
### Basic Logging
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from scraper_npm import logger
|
|
75
|
+
|
|
76
|
+
# Different log levels
|
|
77
|
+
logger.trace('Detailed trace information')
|
|
78
|
+
logger.debug('Debug information')
|
|
79
|
+
logger.info('General information')
|
|
80
|
+
logger.warn('Warning message')
|
|
81
|
+
logger.error('Error occurred')
|
|
82
|
+
logger.fatal('Fatal error')
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Using the log() Method
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from scraper_npm import logger, LogLevel
|
|
89
|
+
|
|
90
|
+
logger.log('info', 'This is an info message')
|
|
91
|
+
logger.log('error', 'This is an error message')
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Logging with Additional Arguments
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
logger.info('User logged in', {'userId': 123, 'username': 'john'})
|
|
98
|
+
logger.error('Database error', error)
|
|
99
|
+
logger.debug('Processing data', {'count': 42, 'items': ['a', 'b', 'c']})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Log Levels
|
|
103
|
+
|
|
104
|
+
| Level | Icon | Color | Description |
|
|
105
|
+
|-------|------|-------|-------------|
|
|
106
|
+
| `trace` | đ | Gray | Very detailed trace information |
|
|
107
|
+
| `debug` | đ | Cyan | Debug information for development |
|
|
108
|
+
| `info` | âšī¸ | Green | General informational messages |
|
|
109
|
+
| `warn` | â ī¸ | Yellow | Warning messages |
|
|
110
|
+
| `error` | â | Red | Error messages |
|
|
111
|
+
| `fatal` | đ | Magenta | Fatal errors |
|
|
112
|
+
|
|
113
|
+
## Output Format
|
|
114
|
+
|
|
115
|
+
The logger formats messages as:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
[2024-02-22T09:30:45.123456] âšī¸ INFO Your message here
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Format breakdown:
|
|
122
|
+
- `[timestamp]` - ISO 8601 formatted timestamp
|
|
123
|
+
- `icon` - Emoji icon for the log level
|
|
124
|
+
- `LEVEL` - Uppercase log level name (padded to 5 characters)
|
|
125
|
+
- `message` - Your log message
|
|
126
|
+
- Color coding based on log level
|
|
127
|
+
|
|
128
|
+
## API Reference
|
|
129
|
+
|
|
130
|
+
### Methods
|
|
131
|
+
|
|
132
|
+
#### `logger.trace(message: str, *args) -> None`
|
|
133
|
+
Logs a trace message with gray color and đ icon.
|
|
134
|
+
|
|
135
|
+
#### `logger.debug(message: str, *args) -> None`
|
|
136
|
+
Logs a debug message with cyan color and đ icon.
|
|
137
|
+
|
|
138
|
+
#### `logger.info(message: str, *args) -> None`
|
|
139
|
+
Logs an info message with green color and âšī¸ icon.
|
|
140
|
+
|
|
141
|
+
#### `logger.warn(message: str, *args) -> None`
|
|
142
|
+
Logs a warning message with yellow color and â ī¸ icon.
|
|
143
|
+
|
|
144
|
+
#### `logger.error(message: str, *args) -> None`
|
|
145
|
+
Logs an error message with red color and â icon.
|
|
146
|
+
|
|
147
|
+
#### `logger.fatal(message: str, *args) -> None`
|
|
148
|
+
Logs a fatal message with magenta color and đ icon.
|
|
149
|
+
|
|
150
|
+
#### `logger.log(level: LogLevel, message: str, *args) -> None`
|
|
151
|
+
Generic log method that accepts a log level as the first parameter.
|
|
152
|
+
|
|
153
|
+
### Types
|
|
154
|
+
|
|
155
|
+
#### `LogLevel`
|
|
156
|
+
```python
|
|
157
|
+
from typing import Literal
|
|
158
|
+
|
|
159
|
+
LogLevel = Literal['trace', 'debug', 'info', 'warn', 'error', 'fatal']
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Examples
|
|
163
|
+
|
|
164
|
+
### Example 1: Basic Application Logging
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from scraper_npm import logger
|
|
168
|
+
|
|
169
|
+
logger.info('Server starting...')
|
|
170
|
+
logger.info('Listening on port 3000')
|
|
171
|
+
logger.warn('Rate limit approaching')
|
|
172
|
+
logger.error('Failed to connect to database')
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Example 2: Error Handling
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from scraper_npm import logger
|
|
179
|
+
|
|
180
|
+
try:
|
|
181
|
+
# Some operation
|
|
182
|
+
raise ValueError('Something went wrong')
|
|
183
|
+
except Exception as error:
|
|
184
|
+
logger.error('Operation failed', error)
|
|
185
|
+
logger.fatal('Application cannot continue')
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Example 3: Debugging
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from scraper_npm import logger
|
|
192
|
+
|
|
193
|
+
def process_data(data):
|
|
194
|
+
logger.debug('Processing data', {'count': len(data)})
|
|
195
|
+
|
|
196
|
+
for index, item in enumerate(data):
|
|
197
|
+
logger.trace(f'Processing item {index}', item)
|
|
198
|
+
|
|
199
|
+
logger.info('Data processing complete')
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Type Hints Support
|
|
203
|
+
|
|
204
|
+
This package includes full type annotations. Works great with mypy and other type checkers!
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from scraper_npm import logger, LogLevel
|
|
208
|
+
|
|
209
|
+
level: LogLevel = 'info'
|
|
210
|
+
logger.log(level, 'Type-safe logging')
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Requirements
|
|
214
|
+
|
|
215
|
+
- Python 3.7 or higher
|
|
216
|
+
- aiohttp>=3.8.0
|
|
217
|
+
- aiofiles>=23.0.0
|
|
218
|
+
|
|
219
|
+
## Optional Dependencies
|
|
220
|
+
|
|
221
|
+
- `netifaces>=0.11.0` - For better network interface detection (install with `pip install scraper-npm[netifaces]`)
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT
|
|
226
|
+
|
|
227
|
+
## Author
|
|
228
|
+
|
|
229
|
+
Michael Weng
|
|
230
|
+
|
|
231
|
+
## Contributing
|
|
232
|
+
|
|
233
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# scraper-npm
|
|
2
|
+
|
|
3
|
+
A beautiful, colorful logger for Python with emoji icons and timestamp support. Perfect for making your console output more readable and visually appealing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- đ¨ **Colorful output** - Each log level has its own color
|
|
8
|
+
- đ¯ **Emoji icons** - Visual indicators for different log levels
|
|
9
|
+
- â° **ISO timestamps** - Automatic timestamp formatting
|
|
10
|
+
- đ **Async support** - Built with asyncio for async operations
|
|
11
|
+
- đ§ **Simple API** - Easy to use
|
|
12
|
+
- đĻ **Type hints** - Full type annotations included
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install scraper-npm
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from scraper_npm import logger
|
|
24
|
+
|
|
25
|
+
logger.info('Application started')
|
|
26
|
+
logger.warn('This is a warning')
|
|
27
|
+
logger.error('Something went wrong')
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Basic Logging
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from scraper_npm import logger
|
|
36
|
+
|
|
37
|
+
# Different log levels
|
|
38
|
+
logger.trace('Detailed trace information')
|
|
39
|
+
logger.debug('Debug information')
|
|
40
|
+
logger.info('General information')
|
|
41
|
+
logger.warn('Warning message')
|
|
42
|
+
logger.error('Error occurred')
|
|
43
|
+
logger.fatal('Fatal error')
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Using the log() Method
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from scraper_npm import logger, LogLevel
|
|
50
|
+
|
|
51
|
+
logger.log('info', 'This is an info message')
|
|
52
|
+
logger.log('error', 'This is an error message')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Logging with Additional Arguments
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
logger.info('User logged in', {'userId': 123, 'username': 'john'})
|
|
59
|
+
logger.error('Database error', error)
|
|
60
|
+
logger.debug('Processing data', {'count': 42, 'items': ['a', 'b', 'c']})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Log Levels
|
|
64
|
+
|
|
65
|
+
| Level | Icon | Color | Description |
|
|
66
|
+
|-------|------|-------|-------------|
|
|
67
|
+
| `trace` | đ | Gray | Very detailed trace information |
|
|
68
|
+
| `debug` | đ | Cyan | Debug information for development |
|
|
69
|
+
| `info` | âšī¸ | Green | General informational messages |
|
|
70
|
+
| `warn` | â ī¸ | Yellow | Warning messages |
|
|
71
|
+
| `error` | â | Red | Error messages |
|
|
72
|
+
| `fatal` | đ | Magenta | Fatal errors |
|
|
73
|
+
|
|
74
|
+
## Output Format
|
|
75
|
+
|
|
76
|
+
The logger formats messages as:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
[2024-02-22T09:30:45.123456] âšī¸ INFO Your message here
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Format breakdown:
|
|
83
|
+
- `[timestamp]` - ISO 8601 formatted timestamp
|
|
84
|
+
- `icon` - Emoji icon for the log level
|
|
85
|
+
- `LEVEL` - Uppercase log level name (padded to 5 characters)
|
|
86
|
+
- `message` - Your log message
|
|
87
|
+
- Color coding based on log level
|
|
88
|
+
|
|
89
|
+
## API Reference
|
|
90
|
+
|
|
91
|
+
### Methods
|
|
92
|
+
|
|
93
|
+
#### `logger.trace(message: str, *args) -> None`
|
|
94
|
+
Logs a trace message with gray color and đ icon.
|
|
95
|
+
|
|
96
|
+
#### `logger.debug(message: str, *args) -> None`
|
|
97
|
+
Logs a debug message with cyan color and đ icon.
|
|
98
|
+
|
|
99
|
+
#### `logger.info(message: str, *args) -> None`
|
|
100
|
+
Logs an info message with green color and âšī¸ icon.
|
|
101
|
+
|
|
102
|
+
#### `logger.warn(message: str, *args) -> None`
|
|
103
|
+
Logs a warning message with yellow color and â ī¸ icon.
|
|
104
|
+
|
|
105
|
+
#### `logger.error(message: str, *args) -> None`
|
|
106
|
+
Logs an error message with red color and â icon.
|
|
107
|
+
|
|
108
|
+
#### `logger.fatal(message: str, *args) -> None`
|
|
109
|
+
Logs a fatal message with magenta color and đ icon.
|
|
110
|
+
|
|
111
|
+
#### `logger.log(level: LogLevel, message: str, *args) -> None`
|
|
112
|
+
Generic log method that accepts a log level as the first parameter.
|
|
113
|
+
|
|
114
|
+
### Types
|
|
115
|
+
|
|
116
|
+
#### `LogLevel`
|
|
117
|
+
```python
|
|
118
|
+
from typing import Literal
|
|
119
|
+
|
|
120
|
+
LogLevel = Literal['trace', 'debug', 'info', 'warn', 'error', 'fatal']
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
### Example 1: Basic Application Logging
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from scraper_npm import logger
|
|
129
|
+
|
|
130
|
+
logger.info('Server starting...')
|
|
131
|
+
logger.info('Listening on port 3000')
|
|
132
|
+
logger.warn('Rate limit approaching')
|
|
133
|
+
logger.error('Failed to connect to database')
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Example 2: Error Handling
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from scraper_npm import logger
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
# Some operation
|
|
143
|
+
raise ValueError('Something went wrong')
|
|
144
|
+
except Exception as error:
|
|
145
|
+
logger.error('Operation failed', error)
|
|
146
|
+
logger.fatal('Application cannot continue')
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Example 3: Debugging
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from scraper_npm import logger
|
|
153
|
+
|
|
154
|
+
def process_data(data):
|
|
155
|
+
logger.debug('Processing data', {'count': len(data)})
|
|
156
|
+
|
|
157
|
+
for index, item in enumerate(data):
|
|
158
|
+
logger.trace(f'Processing item {index}', item)
|
|
159
|
+
|
|
160
|
+
logger.info('Data processing complete')
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Type Hints Support
|
|
164
|
+
|
|
165
|
+
This package includes full type annotations. Works great with mypy and other type checkers!
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from scraper_npm import logger, LogLevel
|
|
169
|
+
|
|
170
|
+
level: LogLevel = 'info'
|
|
171
|
+
logger.log(level, 'Type-safe logging')
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Requirements
|
|
175
|
+
|
|
176
|
+
- Python 3.7 or higher
|
|
177
|
+
- aiohttp>=3.8.0
|
|
178
|
+
- aiofiles>=23.0.0
|
|
179
|
+
|
|
180
|
+
## Optional Dependencies
|
|
181
|
+
|
|
182
|
+
- `netifaces>=0.11.0` - For better network interface detection (install with `pip install scraper-npm[netifaces]`)
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT
|
|
187
|
+
|
|
188
|
+
## Author
|
|
189
|
+
|
|
190
|
+
Michael Weng
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scraper-npm"
|
|
7
|
+
version = "1.0.4"
|
|
8
|
+
description = "A beautiful, colorful logger for Python with emoji icons and timestamp support"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Michael Weng"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["logger", "pretty", "logging", "pino", "color", "emoji", "timestamp"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.7",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
"Topic :: System :: Logging",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"aiohttp>=3.8.0",
|
|
33
|
+
"aiofiles>=23.0.0",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/mgcrae/scraper-npm"
|
|
38
|
+
Documentation = "https://github.com/mgcrae/scraper-npm#readme"
|
|
39
|
+
Repository = "https://github.com/mgcrae/scraper-npm"
|
|
40
|
+
"Bug Tracker" = "https://github.com/mgcrae/scraper-npm/issues"
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
dev = [
|
|
44
|
+
"pytest>=7.0.0",
|
|
45
|
+
"pytest-asyncio>=0.21.0",
|
|
46
|
+
]
|
|
47
|
+
netifaces = [
|
|
48
|
+
"netifaces>=0.11.0",
|
|
49
|
+
]
|
|
50
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Logger module with colorful output and emoji icons"""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import platform
|
|
5
|
+
import socket
|
|
6
|
+
import asyncio
|
|
7
|
+
import json
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Optional, List, Dict, Any, Literal
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
import aiohttp
|
|
12
|
+
import aiofiles
|
|
13
|
+
|
|
14
|
+
LogLevel = Literal['trace', 'debug', 'info', 'warn', 'error', 'fatal']
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Logger:
|
|
18
|
+
"""A beautiful, colorful logger with emoji icons and timestamp support"""
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
self.colors = {
|
|
22
|
+
'reset': '\033[0m',
|
|
23
|
+
'trace': '\033[90m',
|
|
24
|
+
'debug': '\033[36m',
|
|
25
|
+
'info': '\033[32m',
|
|
26
|
+
'warn': '\033[33m',
|
|
27
|
+
'error': '\033[31m',
|
|
28
|
+
'fatal': '\033[35m',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
self.level_icons = {
|
|
32
|
+
'trace': 'đ',
|
|
33
|
+
'debug': 'đ',
|
|
34
|
+
'info': 'âšī¸',
|
|
35
|
+
'warn': 'â ī¸',
|
|
36
|
+
'error': 'â',
|
|
37
|
+
'fatal': 'đ',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def format_timestamp(self) -> str:
|
|
41
|
+
"""Format current timestamp as ISO 8601"""
|
|
42
|
+
return datetime.now().isoformat()
|
|
43
|
+
|
|
44
|
+
def format_message(
|
|
45
|
+
self,
|
|
46
|
+
level: LogLevel,
|
|
47
|
+
message: str,
|
|
48
|
+
timestamp: bool = True,
|
|
49
|
+
colorize: bool = True
|
|
50
|
+
) -> str:
|
|
51
|
+
"""Format a log message with timestamp, icon, and color"""
|
|
52
|
+
color = self.colors[level] if colorize else ''
|
|
53
|
+
reset = self.colors['reset'] if colorize else ''
|
|
54
|
+
icon = self.level_icons[level]
|
|
55
|
+
time_str = f"[{self.format_timestamp()}]" if timestamp else ''
|
|
56
|
+
level_str = level.upper().ljust(5)
|
|
57
|
+
|
|
58
|
+
return f"{color}{time_str} {icon} {level_str}{reset} {message}"
|
|
59
|
+
|
|
60
|
+
def trace(self, message: str, *args) -> None:
|
|
61
|
+
"""Log a trace message"""
|
|
62
|
+
formatted = self.format_message('trace', message)
|
|
63
|
+
print(formatted, *args, file=sys.stdout)
|
|
64
|
+
|
|
65
|
+
def debug(self, message: str, *args) -> None:
|
|
66
|
+
"""Log a debug message"""
|
|
67
|
+
formatted = self.format_message('debug', message)
|
|
68
|
+
print(formatted, *args, file=sys.stdout)
|
|
69
|
+
|
|
70
|
+
def info(self, message: str, *args) -> None:
|
|
71
|
+
"""Log an info message"""
|
|
72
|
+
formatted = self.format_message('info', message)
|
|
73
|
+
print(formatted, *args, file=sys.stdout)
|
|
74
|
+
|
|
75
|
+
def warn(self, message: str, *args) -> None:
|
|
76
|
+
"""Log a warning message"""
|
|
77
|
+
formatted = self.format_message('warn', message)
|
|
78
|
+
print(formatted, *args, file=sys.stderr)
|
|
79
|
+
|
|
80
|
+
def error(self, message: str, *args) -> None:
|
|
81
|
+
"""Log an error message"""
|
|
82
|
+
formatted = self.format_message('error', message)
|
|
83
|
+
print(formatted, *args, file=sys.stderr)
|
|
84
|
+
|
|
85
|
+
def fatal(self, message: str, *args) -> None:
|
|
86
|
+
"""Log a fatal message"""
|
|
87
|
+
formatted = self.format_message('fatal', message)
|
|
88
|
+
print(formatted, *args, file=sys.stderr)
|
|
89
|
+
|
|
90
|
+
def log(self, level: LogLevel, message: str, *args) -> None:
|
|
91
|
+
"""Generic log method that accepts a log level"""
|
|
92
|
+
method_map = {
|
|
93
|
+
'trace': self.trace,
|
|
94
|
+
'debug': self.debug,
|
|
95
|
+
'info': self.info,
|
|
96
|
+
'warn': self.warn,
|
|
97
|
+
'error': self.error,
|
|
98
|
+
'fatal': self.fatal,
|
|
99
|
+
}
|
|
100
|
+
method = method_map.get(level)
|
|
101
|
+
if method:
|
|
102
|
+
method(message, *args)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# Initialize logger instance
|
|
106
|
+
logger = Logger()
|
|
107
|
+
|