Mailing List Archive

How to get the current set LOG MASK in Python's syslog module?
X-Post: https://stackoverflow.com/q/73814924/4865723

Hello,

I'm aware that there is a `logging` package that is more _modern_ then
[`syslog`](https://docs.python.org/3/library/syslog.html). But I have
old code here to deal with that does use `syslog`. So that question is
specific to `syslog` and not to `logging`.

I would like to get the current `LOG_MASK`, which is kind of a logging
level. According to the docu it seems that `syslog` doesn't have a
mechanism for that.

Does someone has an idea?

The docu also tells me that `syslog` does let pass all messages by
default.
My point is I do manipulate via `syslog.setlogmask()` the current log
leve. At the end I would like to set it back to its previous value.

Kind
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to get the current set LOG_MASK in Python's syslog module? [ In reply to ]
According to documentation syslog.setlogmask returns the current mask so
save the value to reset later on.

Oldval = syslog.setlogmask(newmask)

This sets oldval to original mask.

On Thu, 22 Sep 2022, 14:32 , <c.buhtz@posteo.jp> wrote:

> X-Post: https://stackoverflow.com/q/73814924/4865723
>
> Hello,
>
> I'm aware that there is a `logging` package that is more _modern_ then
> [`syslog`](https://docs.python.org/3/library/syslog.html). But I have
> old code here to deal with that does use `syslog`. So that question is
> specific to `syslog` and not to `logging`.
>
> I would like to get the current `LOG_MASK`, which is kind of a logging
> level. According to the docu it seems that `syslog` doesn't have a
> mechanism for that.
>
> Does someone has an idea?
>
> The docu also tells me that `syslog` does let pass all messages by
> default.
> My point is I do manipulate via `syslog.setlogmask()` the current log
> leve. At the end I would like to set it back to its previous value.
>
> Kind
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to get the current set LOG_MASK in Python's syslog module? [ In reply to ]
On Thu, 22 Sep 2022 13:28:57 +0000, c.buhtz@posteo.jp declaimed the
following:


>I would like to get the current `LOG_MASK`, which is kind of a logging
>level. According to the docu it seems that `syslog` doesn't have a
>mechanism for that.
>

There is a function .LOG_MASK() but it seems to just return 2^arg

>>> import syslog
>>> syslog.LOG_MASK(1)
2
>>> syslog.LOG_MASK(2)
4
>>> syslog.LOG_MASK(3)
8
>>> syslog.LOG_MASK(4)
16
>>> syslog.LOG_MASK(0)
1
>>> syslog.LOG_MASK(256)
1
>>> syslog.LOG_MASK(16)
65536
>>> syslog.__doc__
>>> syslog.LOG_MASK(17)
131072
>>> syslog.LOG_MASK(32)
1
>>> syslog.LOG_MASK(24)
16777216
>>>

That is in the Windows Linux (Debian) subsystem.


>Does someone has an idea?
>
>The docu also tells me that `syslog` does let pass all messages by
>default.
>My point is I do manipulate via `syslog.setlogmask()` the current log
>leve. At the end I would like to set it back to its previous value.
>
>Kind


--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to get the current set LOG_MASK in Python's syslog module? [ In reply to ]
On Thu, 22 Sept 2022 at 23:46, Richard Moseley
<richardmoseley4@gmail.com> wrote:
>
> According to documentation syslog.setlogmask returns the current mask so
> save the value to reset later on.
>
> Oldval = syslog.setlogmask(newmask)
>
> This sets oldval to original mask.

This on its own suggests an odd technique that should work but won't be great:

oldval = syslog.setlogmask(1234)
syslog.setlogmask(oldval)

But the Python function just passes the value straight to the
underlying system call, and thus treats zero specially:

"""
The setlogmask() function sets this logmask for the calling
process, and returns the previous mask. If the mask argument is
0, the current logmask is not modified.
"""

So you should be able to do:

current_mask = syslog.setlogmask(0)

The Python docs do say to refer to the man pages, but IMO it would be
worth mentioning this feature specifically in the docs.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list