unilog
Unilog module aimed at facilitating the development and logging complex data structures, mainly for python2.7. In python3, there is no such pain when printing complex data structures, so python3 support is due to backward compatibility with the old code. But for python3, the functionality of registering converters will be useful, for printing or logging complex data structures that do not override the __str__ method or need to represent them in a different way. The functionality of registering converters is also available for python2.7.
Unilog provides 3 functions (their description can be obtained by the help function):
as_unicode
as_str
register_converter
Installation
$ pip install unilog
Example
data = {
'date': datetime.date(2016, 12, 6),
'datetime': datetime.datetime(2016, 12, 6, 11, 22, 33, 444444),
'str': 'item1',
'str2': 'пункт2',
u'юникод': u'пункт3',
'int': 4,
'float': 4.44,
'bytearray': bytearray([0, 1, 2]),
'NoneType': None,
'True': True,
'False': False,
'list': [
datetime.date(2016, 12, 6), datetime.datetime(2016, 12, 6, 11, 22, 33, 444444),
'item1', 'пункт2', u'пункт3', 4, 4.44, bytearray([0, 1, 2]), None, True, False
],
'tuple': (
datetime.date(2016, 12, 6), datetime.datetime(2016, 12, 6, 11, 22, 33, 444444),
'item1', 'пункт2', u'пункт3', 4, 4.44, bytearray([0, 1, 2]), None, True, False
),
'generator': (i for i in xrange(3, 6))
}
# default python2.7 behavior
>>> print unicode(data)
{'bytearray': bytearray(b'\x00\x01\x02'), 'tuple': (datetime.date(2016, 12, 6),
datetime.datetime(2016, 12, 6, 11, 22, 33, 444444), 'item1',
'\xd0\xbf\xd1\x83\xd0\xbd\xd0\xba\xd1\x822', u'\u043f\u0443\u043d\u043a\u04423', 4, 4.44,
bytearray(b'\x00\x01\x02'), None, True, False), 'int': 4, 'float': 4.44,
'datetime': datetime.datetime(2016, 12, 6, 11, 22, 33, 444444), 'date': datetime.date(2016, 12, 6),
'False': False, 'generator': <generator object <genexpr> at 0x7ff51a58df00>,
'str2': '\xd0\xbf\xd1\x83\xd0\xbd\xd0\xba\xd1\x822', 'list': [datetime.date(2016, 12, 6),
datetime.datetime(2016, 12, 6, 11, 22, 33, 444444), 'item1',
'\xd0\xbf\xd1\x83\xd0\xbd\xd0\xba\xd1\x822', u'\u043f\u0443\u043d\u043a\u04423', 4, 4.44,
bytearray(b'\x00\x01\x02'), None, True, False], 'str': 'item1',
u'\u044e\u043d\u0438\u043a\u043e\u0434': u'\u043f\u0443\u043d\u043a\u04423', 'True': True,
'NoneType': None}
# use unilog.as_unicode function
>>> print unilog.as_unicode(data)
{'bytearray': b'\\x00\\x01\\x02', 'tuple': (u'2016-12-06', u'2016-12-06 11:22:33.444444', 'item1',
'пункт2', u'пункт3', 4, 4.44, b'\\x00\\x01\\x02', None, True, False), 'int': 4, 'float': 4.44,
'datetime': u'2016-12-06 11:22:33.444444', 'date': u'2016-12-06', 'False': False,
'generator': '<generator object <genexpr> at 0x7ff51a58df00>', 'str2': 'пункт2',
'list': [u'2016-12-06', u'2016-12-06 11:22:33.444444', 'item1', 'пункт2', u'пункт3', 4, 4.44,
b'\\x00\\x01\\x02', None, True, False], 'str': 'item1', u'юникод': u'пункт3', 'True': True, 'NoneType': None}
# use unilog.as_unicode function with pretty print
>>> print unilog.as_unicode(data, pretty=True)
{
'bytearray': b'\\x00\\x01\\x02',
'tuple': (
u'2016-12-06',
u'2016-12-06 11:22:33.444444',
'item1',
'пункт2',
u'пункт3',
4,
4.44,
b'\\x00\\x01\\x02',
None,
True,
False
),
'int': 4,
'float': 4.44,
'datetime': u'2016-12-06 11:22:33.444444',
'date': u'2016-12-06',
'False': False,
'generator': '<generator object <genexpr> at 0x7ff51a58df00>',
'str2': 'пункт2',
'list': [
u'2016-12-06',
u'2016-12-06 11:22:33.444444',
'item1',
'пункт2',
u'пункт3',
4,
4.44,
b'\\x00\\x01\\x02',
None,
True,
False
],
'str': 'item1',
u'юникод': u'пункт3',
'True': True,
'NoneType': None
}
License
MIT licensed. See the bundled LICENSE file for more details.
Metadata
Release files for unilog 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unilog-2.0.0.tar.gz | 4.5 kB | Without provenance | Details for unilog-2.0.0.tar.gz |
Release files / unilog-2.0.0.tar.gz
| Download URL | unilog-2.0.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5256dd85bb9ba331cee1d4c4c59ac44e98e99052be1487162fd0e93d01090e82
|
|
BLAKE2b-256 checksum How to use checksums |
ca5af1e0be335facc69e9590b0f89cb3011366d4b12979d2103dff87306cb871
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for unilog 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.