Skip to content

Commit 1d014d6

Browse files
authored
Merge pull request #23 from keitheis/renamed_turn_logging_things
Renamed turn_logging_...thing
2 parents 5cf6ff5 + 4ede81c commit 1d014d6

File tree

5 files changed

+64
-35
lines changed

5 files changed

+64
-35
lines changed

CHANGES.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
(Unrelease)
22
===================
33

4+
- Renamed:
5+
6+
- ``turn_logging_datetime(on=True)``
7+
- ``turn_logging_thread_name(on=False)``
8+
- ``turn_logging_process_id(on=False)``
9+
410
- Support most same APIs between alog and Alogger.
511
- Add ``alog.pdir()`` for handy replacing ``[attr for attr in dir(obj)
612
if not attr.startswith("_")]``.

README.rst

+27-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ Alog
1010
.. image:: http://img.shields.io/pypi/v/alog.svg?style=flat
1111
:target: https://pypi.org/pypi/alog
1212

13-
Python logging for Humans. Your goto logging module without panic on context
14-
swtich.
13+
Your goto Pythonlogging module without panic on context swtich.
1514

1615
**Warning:** No more ``logger = logging.getLogger(__name__)`` in your every file.
1716

@@ -95,12 +94,36 @@ with ``logging`` module:
9594
2016-11-23 12:16:30 INFO [__main__:1] Hello log!
9695
9796
97+
Tips
98+
----
99+
100+
.. code-block:: python
101+
102+
import alog
103+
104+
a_complex_json_dict = {...} # or a_complex_dict
105+
alog.info(alog.pformat(a_complex_dict))
106+
107+
restaurant = Restaurant(...)
108+
alog.info(alog.pdir(restaurant))
109+
# or just skip attributes starts with "__":
110+
alog.info(alog.pdir(restaurant, str_not_startswith="__"))
111+
# instead of
112+
alog.info([attr for attr in dir(restaurant) if attr.startswith("_")])
113+
114+
# Play threads?
115+
alog.turn_logging_thread_name(on=True)
116+
# Processes?
117+
alog.turn_logging_process_id(on=True)
118+
# No datetime wanted?
119+
alog.turn_logging_datetime(on=False)
120+
98121
Why should you use logging instead of print
99122
-------------------------------------------
100123

101124
The main goal of logging is to figure out what was going on and to get the
102-
insights. ``print``, by default, does only pure string output. No timestamp, no
103-
module hint, and no level control, comparing to a pretty logging record.
125+
insight. ``print``, by default, does simply pure string output. No timestamp,
126+
no module hint, and no level control, comparing to a pretty logging record.
104127

105128
Lets start with ``aproject/models/user.py`` :
106129

alog/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def reset_global_alog():
6767
info = default_logger.info
6868
debug = default_logger.debug
6969
log = default_logger.log
70-
default_logger.turn_log_datetime(on=True)
70+
default_logger.turn_logging_datetime(on=True)
7171

7272

7373
def init_alogger(alog_config, default_root_name=None):
@@ -91,19 +91,19 @@ def getLogger(*args, **kwargs):
9191
# --- Alogger APIs --- #
9292

9393

94-
def turn_log_datetime(on, alogger=None):
94+
def turn_logging_datetime(on, alogger=None):
9595
alogger = alogger or default_logger
96-
return alogger.turn_log_datetime(on)
96+
return alogger.turn_logging_datetime(on)
9797

9898

99-
def turn_thread_name(on, alogger=None):
99+
def turn_logging_thread_name(on, alogger=None):
100100
alogger = alogger or default_logger
101-
return alogger.turn_thread_name(on)
101+
return alogger.turn_logging_thread_name(on)
102102

103103

104-
def turn_process_id(on, alogger=None):
104+
def turn_logging_process_id(on, alogger=None):
105105
alogger = alogger or default_logger
106-
return alogger.turn_process_id(on)
106+
return alogger.turn_logging_process_id(on)
107107

108108

109109
def set_level(level, alogger=None):

alog/alogger.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _get_logger_showing_fs(self):
8686
fs = self.alog_config['default_format']
8787
return fs
8888

89-
def turn_log_datetime(self, on):
89+
def turn_logging_datetime(self, on):
9090
if (
9191
self.alog_config.get('custom_format') or
9292
self.alog_config['showing_log_datetime'] == bool(on)
@@ -98,7 +98,7 @@ def turn_log_datetime(self, on):
9898
fs = "%(asctime)s " + fs
9999
self.set_format(fs, is_default=True)
100100

101-
def turn_thread_name(self, on):
101+
def turn_logging_thread_name(self, on):
102102
if (
103103
self.alog_config.get('custom_format') or
104104
self.alog_config['showing_thread_name'] == bool(on)
@@ -109,7 +109,7 @@ def turn_thread_name(self, on):
109109
fs = self._get_logger_showing_fs()
110110
self.set_format(fs, is_default=True)
111111

112-
def turn_process_id(self, on):
112+
def turn_logging_process_id(self, on):
113113
if (
114114
self.alog_config.get('custom_format') or
115115
self.alog_config['showing_process_id'] == bool(on)

tests/base.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,39 @@ def test_warning(self):
5858
def test_warn(self):
5959
self._alog.warn(msg)
6060

61-
def test_turn_thread_name(self):
62-
self._alog.turn_process_id(True)
63-
self._alog.turn_thread_name(True)
61+
def test_turn_logging_thread_name(self):
62+
self._alog.turn_logging_process_id(True)
63+
self._alog.turn_logging_thread_name(True)
6464

65-
def test_turn_thread_name_with_custom_format(self):
65+
def test_turn_logging_thread_name_with_custom_format(self):
6666
self._alog.set_format("blah")
67-
self._alog.turn_thread_name(True)
67+
self._alog.turn_logging_thread_name(True)
6868

69-
def test_turn_process_id_with_custom_format(self):
69+
def test_turn_logging_process_id_with_custom_format(self):
7070
self._alog.set_format("blah")
71-
self._alog.turn_process_id(True)
71+
self._alog.turn_logging_process_id(True)
7272

73-
def test_turn_log_datetime_with_custom_format(self):
73+
def test_turn_logging_datetime_with_custom_format(self):
7474
self._alog.set_format("blah")
75-
self._alog.turn_log_datetime(True)
75+
self._alog.turn_logging_datetime(True)
7676

7777
def test_not_turn_thread_name(self):
78-
self._alog.turn_thread_name(True)
79-
self._alog.turn_thread_name(False)
78+
self._alog.turn_logging_thread_name(True)
79+
self._alog.turn_logging_thread_name(False)
8080

8181
def test_not_turn_process_id(self):
82-
self._alog.turn_process_id(True)
83-
self._alog.turn_process_id(False)
82+
self._alog.turn_logging_process_id(True)
83+
self._alog.turn_logging_process_id(False)
8484

8585
def test_not_turn_process_id_and_turn_thread_name(self):
86-
self._alog.turn_thread_name(True)
87-
self._alog.turn_process_id(True)
88-
self._alog.turn_process_id(False)
86+
self._alog.turn_logging_thread_name(True)
87+
self._alog.turn_logging_process_id(True)
88+
self._alog.turn_logging_process_id(False)
8989

9090
def test_turn_process_id_and_not_turn_thread_name(self):
91-
self._alog.turn_thread_name(True)
92-
self._alog.turn_process_id(True)
93-
self._alog.turn_thread_name(False)
91+
self._alog.turn_logging_thread_name(True)
92+
self._alog.turn_logging_process_id(True)
93+
self._alog.turn_logging_thread_name(False)
9494

9595
def test_info(self):
9696
self._alog.info(msg)
@@ -122,5 +122,5 @@ class Thing(object):
122122
thing = Thing()
123123
thing._private_thing = True
124124
thing.public_thing = True
125-
assert "public_thing" in str(self._alog.pdir(thing))
126-
assert "_private_thing" not in str(self._alog.pdir(thing))
125+
assert "public_thing" in self._alog.pdir(thing)
126+
assert "_private_thing" not in self._alog.pdir(thing)

0 commit comments

Comments
 (0)