Commit graph

31 commits

Author SHA1 Message Date
bfd0544ff8 Fix errors reported by mypy
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-10-13 12:45:51 +02:00
428692ea3a Streamline Python file headers somewhat
- Add coding statement
  - Import all modules in one line where possible
  - Order: __future__, typing, plain imports, from imports,
    janware modules

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-07-10 05:14:06 +02:00
0a1a6e5e17 log.get_caller_pos(): Fix None module
<W> jw-client-devops-web.py       [  29] Exiting jw-client-devops-web.py
Exception ignored in: <function App.__del__ at 0x7f3ddeb8f560>
Traceback (most recent call last):
  File "/home/jan/local/src/jw.dev/proj/jw-client-devops-web/src/python/jw/devops/client/web/cmds/App.py", line 43, in __del__
  File "/home/jan/local/src/jw.dev/proj/jw-python/tools/python/jwutils/log.py", line 167, in slog
  File "/home/jan/local/src/jw.dev/proj/jw-python/tools/python/jwutils/log.py", line 126, in get_caller_pos
AttributeError: 'NoneType' object has no attribute '__name__'

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-06-05 22:57:55 +02:00
6e70529f7a log.(add|rm)_capture_stream(): Add functions
Add functions log.(add|rm)_capture_stream(). The functions are meant
to capture everything passed to syslog into the stream objects
installed by it. Not sure about future semantics changes:
add_capture_stream() takes a currently unused flags argument, and it
suppresses everything else logged until the stream is removed again.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-06-03 15:25:44 +02:00
748b850532 log.set_level(): Return current flags
Make log.set_level() return the flags that were set before setting
the flags passed as argument.

Support None as flags argument, in which case it doesn't change
anything and only returns the currently set flags.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-06-03 15:17:08 +02:00
cf122e44be log.slog(): Support log flag "module"
If module is present in the log flags string, the module is prepended
to each log message. The length of the module prefix can be set via
the new set_module_name_length() function.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-06-01 15:14:48 +02:00
7399388f60 Fix errors reported by mypy
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-29 16:51:07 +01:00
d5e268a03b log: Add throw()
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-28 10:17:27 +01:00
2462ad8c60 log: Add log_level()
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-28 10:17:17 +01:00
45b5a8fb5a log: Add prio_gets_logged()
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-18 16:42:33 +01:00
3a7fb50979 Apply monkeytype traces
Run

       monkeytype run jw-acc.py --log-level debug db import --format mdb-json-dir dbs
       monkeytype list-modules | grep ^jw | while read m; do
               monkeytype apply $m
       done

and fix the fallout.

Signed-off-by: Jan Lindemann <jan@janware.com>
2024-12-15 15:35:29 +01:00
27813efc04 Fix bogus type errors dug up by mypy
Signed-off-by: Jan Lindemann <jan@janware.com>
2024-06-02 12:05:44 +02:00
319d97e8bc log.py: Fix mypy warning (Incompatible types in assignment)
Fix mypy warning

   jwutils/log.py:209: error: Incompatible types in assignment
   (expression has type int, variable has type Literal[5])

Signed-off-by: Jan Lindemann <jan@janware.com>
2022-10-04 13:11:44 +02:00
8029b672bf slog(): Add only_printable keyword argument
Add only_printable keyword argument to slog(). It defaults to False.
If it's true, non-printable characters are not logged but replaced
with a printable character.

Signed-off-by: Jan Lindemann <jan@janware.com>
2020-05-16 15:33:13 +00:00
4a047ca260 log.remove_from_prefix(): Add support for str argument
In addition to an integer, a string can now be passed, which allows

	prefix = ' | '
	append_to_prefix(prefix)
	slog(INFO, "something")
	remove_from_prefix(prefx)

Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-23 10:32:05 +02:00
5924ec9769 log.get_caller_pos(): Add kwargs argument
Add a kwargs keyword argument. This should allow a kwargs containing
a "caller=" argument to be passed to the function and just do the
right thing. Badly tested.

Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-11 10:56:30 +02:00
77d43aebad Add type annotations from monkeytype + jw-devops/test
Add type annotations as generated by monkeytype and jw-devops/test, plus some
hand editing to satisfy both monkeytype and mypy.

Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-10 17:55:36 +02:00
79ebb798c7 slog_m(): Support kwarg "caller"
Treat slog_m() to a caller keyword argument, up to now only supported
by slog().

Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-04 11:12:11 +02:00
08f9aae61a log.get_caller_pos(): Implement frames > 1
Signed-off-by: Jan Lindemann <jan@janware.com>
2019-12-30 17:46:20 +01:00
26d322023a log.py: Improve console color implementation
o Remove unnecessary function prio_colors()
o Don't output color codes on non-TTY output

Signed-off-by: Jan Lindemann <jan@janware.com>
2019-12-23 18:01:53 +01:00
2171e1e16e log.py: Add support for flag "date"
Signed-off-by: Jan Lindemann <jan@janware.com>
2019-12-21 19:08:51 +00:00
d3faa8ee85 log.py: Add utilities, better list-support in slog_m()
- Add functions: append_to_prefix(),
  remove_from_prefix() set_filename_length()
- Make slog_m() log one list item per line
- Add console_color_chars(prio)

Signed-off-by: Jan Lindemann <jan@janware.com>
2019-10-30 15:46:26 +01:00
036a978130 log.py: Add slog_m() (multiline logging)
Signed-off-by: Jan Lindemann <jan@janware.com>
2019-10-28 12:50:17 +01:00
1cdb38b767 log.py: Make some variables private
Add leading underscore to variables that should not be visible
outside of log.py. Also do some indentation beautification.

Signed-off-by: Jan Lindemann <jan@janware.com>
2019-10-28 10:59:20 +01:00
6dd594d47b Fix multiple Python 3 compatibility issues
Changes in Python 3 that made the code choke:

  o basestring is merged into str
  o print() needs parentesis
  o Class inheritance syntax changed
  o Abstract baseclass (ABCMeta) syntax changed
  o map.iteritems() is replaced by map.items()
  o Inconsistent use of tabs and spaces are no longer tolerated

Signed-off-by: Jan Lindemann <jan@janware.com>
2019-03-10 16:38:59 +01:00
8c5934725c grammar.py: Add support for --irrelevant-symbols
Arguments to --irrelevant-symbols are not meant to be represented in the
AST resulting from parsing.

Also, add pad() to misc.py.

Signed-off-by: Jan Lindemann <jan@janware.com>
2017-10-30 10:00:25 +01:00
860f7d8cab Implement caller keyword argument to slog()
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-10-27 18:58:53 +02:00
4e3a6630da log.py: Add set_flags()
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-10-25 10:06:29 +02:00
d15242600a log.py: Fix non-working slog()
No idea how this ever worked. Still not sure about the best way.

Signed-off-by: Jan Lindemann <jan@janware.com>
2017-10-16 12:22:49 +02:00
0aecc8d076 Make jwutils.log module somewhat usable
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-08-07 18:05:53 +02:00
36aac73b5d Add Object.py and log.py
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-07-30 18:51:19 +02:00