Re: One-liner to merge lists?

2022-02-27 Thread Barry Scott



> On 22 Feb 2022, at 09:30, Chris Angelico  wrote:
> 
> On Tue, 22 Feb 2022 at 20:24, Frank Millman  > wrote:
>> 
>> Hi all
>> 
>> I think this should be a simple one-liner, but I cannot figure it out.
>> 
>> I have a dictionary with a number of keys, where each value is a single
>> list -
>> 
> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']}
>> 
>> I want to combine all values into a single list -
>> 
> ans = ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
>> 
>> I can do this -
>> 
> a = []
> for v in d.values():
>> ...   a.extend(v)
>> ...
> a
>> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
>> 
>> I can also do this -
>> 
> from itertools import chain
> a = list(chain(*d.values()))
> a
>> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> 
>> 
>> Is there a simpler way?
>> 
> 
> itertools.chain is a good option, as it scales well to arbitrary
> numbers of lists (and you're guaranteed to iterate over them all just
> once as you construct the list). But if you know that the lists aren't
> too large or too numerous, here's another method that works:
> 
 sum(d.values(), [])
> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> 
> It's simply adding all the lists together, though you have to tell it
> that you don't want a numeric summation.

If you code is performance sensitive do not use sum() as it creates lots of tmp 
list that are deleted.

I have an outstanding ticket at work to replace all use of sum() on lists as 
when we profiled it
stands out as a slow operation. We have a lots of list of list that we need to 
flatten.

Barry


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


ping script

2022-02-27 Thread Byung-Hee HWANG
simple ping check script with python3 (Python 3.9.2)
tested under Debian 11 Bullseye:

soyeomul@penguin:~/gitlab/test$ ./fping.py localhost
ok
soyeomul@penguin:~/gitlab/test$ ./fping.py python.org
ok
soyeomul@penguin:~/gitlab/test$ ./fping.py python3.org
python3.org: No address associated with hostname
something is wrong...
soyeomul@penguin:~/gitlab/test$ 

Signed-off-by: Byung-Hee HWANG 
---
 fping.py | 31 +++
 1 file changed, 31 insertions(+)
 create mode 100755 fping.py

diff --git a/fping.py b/fping.py
new file mode 100755
index 000..ccc1e58
--- /dev/null
+++ b/fping.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from subprocess import PIPE, Popen
+from os import path
+import sys
+
+"""
+REFERENCE:
+
+"""
+
+if not path.isfile('/usr/bin/fping'):
+sys.exit("you first install fping, then try again...")
+
+def check(xyz):
+cmd = "fping %s" % (xyz)
+try_ = Popen(cmd, stdout=PIPE, shell=True)
+output = try_.communicate()[0].decode("utf-8")
+
+return output
+
+
+if __name__ == "__main__":
+xyz = sys.argv[1]
+if "alive" in check(xyz):
+print("ok")
+else:
+print("something is wrong...")
+
+# 2022-02-27, GNU Emacs 27.1 (Debian 11 Bullseye)
-- 
2.30.2

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


Re: ping script

2022-02-27 Thread Barry Scott



> On 27 Feb 2022, at 13:53, Byung-Hee HWANG  wrote:
> 
> simple ping check script with python3 (Python 3.9.2)
> tested under Debian 11 Bullseye:
> 
> soyeomul@penguin:~/gitlab/test$ ./fping.py localhost
> ok
> soyeomul@penguin:~/gitlab/test$ ./fping.py python.org
> ok
> soyeomul@penguin:~/gitlab/test$ ./fping.py python3.org
> python3.org: No address associated with hostname
> something is wrong...

This is correct python3.org  is only setup for email.
Use the host and dig commands to check for yourself.

Compare

$ host python.org 

with

$ host python3.org

And compare:

$ dig -t A python.org 
$ dig -t MX python.org 

with

$ dig -t A python3.org 
$ dig -t MX python3.org 

Barry

> soyeomul@penguin:~/gitlab/test$ 
> 
> Signed-off-by: Byung-Hee HWANG 
> ---
> fping.py | 31 +++
> 1 file changed, 31 insertions(+)
> create mode 100755 fping.py
> 
> diff --git a/fping.py b/fping.py
> new file mode 100755
> index 000..ccc1e58
> --- /dev/null
> +++ b/fping.py
> @@ -0,0 +1,31 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8 -*-
> +
> +from subprocess import PIPE, Popen
> +from os import path
> +import sys
> +
> +"""
> +REFERENCE:
> +
> +"""
> +
> +if not path.isfile('/usr/bin/fping'):
> +sys.exit("you first install fping, then try again...")
> +
> +def check(xyz):
> +cmd = "fping %s" % (xyz)
> +try_ = Popen(cmd, stdout=PIPE, shell=True)
> +output = try_.communicate()[0].decode("utf-8")
> +
> +return output
> +
> +
> +if __name__ == "__main__":
> +xyz = sys.argv[1]
> +if "alive" in check(xyz):
> +print("ok")
> +else:
> +print("something is wrong...")
> +
> +# 2022-02-27, GNU Emacs 27.1 (Debian 11 Bullseye)
> -- 
> 2.30.2
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: One-liner to merge lists?

2022-02-27 Thread MRAB

On 2022-02-27 08:51, Barry Scott wrote:




On 22 Feb 2022, at 09:30, Chris Angelico  wrote:

On Tue, 22 Feb 2022 at 20:24, Frank Millman mailto:[email protected]>> wrote:


Hi all

I think this should be a simple one-liner, but I cannot figure it out.

I have a dictionary with a number of keys, where each value is a single
list -


d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']}


I want to combine all values into a single list -


ans = ['aaa', 'bbb', 'ccc', 'fff', 'ggg']


I can do this -


a = []
for v in d.values():

...   a.extend(v)
...

a

['aaa', 'bbb', 'ccc', 'fff', 'ggg']

I can also do this -


from itertools import chain
a = list(chain(*d.values()))
a

['aaa', 'bbb', 'ccc', 'fff', 'ggg']




Is there a simpler way?



itertools.chain is a good option, as it scales well to arbitrary
numbers of lists (and you're guaranteed to iterate over them all just
once as you construct the list). But if you know that the lists aren't
too large or too numerous, here's another method that works:


sum(d.values(), [])

['aaa', 'bbb', 'ccc', 'fff', 'ggg']

It's simply adding all the lists together, though you have to tell it
that you don't want a numeric summation.


If you code is performance sensitive do not use sum() as it creates lots of tmp 
list that are deleted.

I have an outstanding ticket at work to replace all use of sum() on lists as 
when we profiled it
stands out as a slow operation. We have a lots of list of list that we need to 
flatten.


I think that 'sum' uses '__add__' but not '__iadd__'.

If it copied the given value, if present, and then used '__iadd__', if 
present, wouldn't that speed it up?

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


Re: One-liner to merge lists?

2022-02-27 Thread Chris Angelico
On Mon, 28 Feb 2022 at 03:24, MRAB  wrote:
>
> On 2022-02-27 08:51, Barry Scott wrote:
> >
> >
> >> On 22 Feb 2022, at 09:30, Chris Angelico  wrote:
> >>
> >> On Tue, 22 Feb 2022 at 20:24, Frank Millman  >> > wrote:
> >>>
> >>> Hi all
> >>>
> >>> I think this should be a simple one-liner, but I cannot figure it out.
> >>>
> >>> I have a dictionary with a number of keys, where each value is a single
> >>> list -
> >>>
> >> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']}
> >>>
> >>> I want to combine all values into a single list -
> >>>
> >> ans = ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> >>>
> >>> I can do this -
> >>>
> >> a = []
> >> for v in d.values():
> >>> ...   a.extend(v)
> >>> ...
> >> a
> >>> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> >>>
> >>> I can also do this -
> >>>
> >> from itertools import chain
> >> a = list(chain(*d.values()))
> >> a
> >>> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> >>
> >>>
> >>> Is there a simpler way?
> >>>
> >>
> >> itertools.chain is a good option, as it scales well to arbitrary
> >> numbers of lists (and you're guaranteed to iterate over them all just
> >> once as you construct the list). But if you know that the lists aren't
> >> too large or too numerous, here's another method that works:
> >>
> > sum(d.values(), [])
> >> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> >>
> >> It's simply adding all the lists together, though you have to tell it
> >> that you don't want a numeric summation.
> >
> > If you code is performance sensitive do not use sum() as it creates lots of 
> > tmp list that are deleted.
> >
> > I have an outstanding ticket at work to replace all use of sum() on lists 
> > as when we profiled it
> > stands out as a slow operation. We have a lots of list of list that we need 
> > to flatten.
> >
> I think that 'sum' uses '__add__' but not '__iadd__'.
>
> If it copied the given value, if present, and then used '__iadd__', if
> present, wouldn't that speed it up?

It's hardly relevant. If you care about speed, use chain(), like
everyone's been saying all along :)

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


Getting Syslog working on OSX Monterey

2022-02-27 Thread Philip Bloom via Python-list
Hello,

First time mailing and looking for help/guidance.  Hopefully not too in the
wrong place.

We've had an app with logging to a /var/log for many years through
logging.sysloghandler.  Recently, though, I noticed that it suddenly was
getting no logs whatsoever over there and investigated, believing the
recent triggering change was upgrading to Mac OSX 12 (Monterey).

My understanding is a bit primitive, but our config had never been hard to
follow previously and I may be missing something fundamental.  I've looked
over a number of online examples but they don't seem to be running
correctly either.  I'm on Python 3.6.8 (though we're about to start an
upgrade to the latest stable, if that in theory may have changes to syslog
handling).  I'm mostly ending up here since I'm finding such differences in
response between python modules I'd expect to be fairly similar.

Separating into a test script I've been testing with logging.SysLogHandler,
syslog, and the command line 'syslog -s'.  Replaced all below with a
placeholder appName but it's normally a fairly unique setupCDNGUI name.

Example with syslog (python module):  - This will show up in System.log but
not in Apple's Console for all messages to device, though won't get all the
way to file.
import syslog
syslog.syslog(syslog.LOG_NOTICE, 'AppName: THIS IS A TEST - Processing
started')
syslog.syslog(syslog.LOG_ERR, 'AppName: THIS IS A TEST ERROR - Processing
started')

Example with SyslogHandler: - This doesn't seem to show up anywhere besides
the screen log, which is odd to me as reading the docs, I understood this
to be a logging integration into the syslog module, so expected similar
behavior in at least what was sent out.  Syslog handler is definitely
picked up in logging.handlers

root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
basic_datefmt = '%m/%d/%Y %I:%M:%S %p'

formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s',
datefmt=basic_datefmt)
syslog_format = logging.Formatter(fmt='SetupCDNGUI: %(message)s',
datefmt=basic_datefmt)

scrhandler = logging.StreamHandler()
scrhandler.setFormatter(formatter)
root_logger.addHandler(scrhandler)

sys_handler = SysLogHandler(address='/var/run/syslog')
#sys_handler.encodePriority(SysLogHandler.LOG_USER, SysLogHandler.LOG_ALERT)
# Tried with the above, but didn't make a difference.  Neither did not
defining the address and letting it go to local host.
sys_handler.setFormatter(syslog_format)
root_logger.addHandler(sys_handler)

logging.critical("This is a test")
logging.error("This is a test error")
logging.info("Still a test")
logging.debug("Testy test")

Using command line: Oddly, this gets to Console.Apps messages from device
reliably, though doesn't get picked up by syslog -w or get received by the
ASL config redirect:
syslog -s -l error -k Message "appName: this is a test2"
syslog -s -l notice -k Message "appName: this is a test3"

ASL configuration, which is loaded according to syslog -config:
> /var/log/appName/appName.log mode=0640 compress format=std rotate=seq
file_max=50M all_max=500M
? [CA= Sender appName] file /var/log/appName/appName.log

My end goal is really to get just a working python logging ->
var/log/appname/appname.log again so glad to just be pointed in the right
direction if way off base.

-- 
Philip Bloom
Director, Services Engineering
*AppLovin Corporation*
M: (786)-338-1439 <786-338-1439>
[image: LinkedIn]  [image:
Twitter]  [image: Facebook]
 [image: Instagram]

[image: AppLovin] 
-- 
https://mail.python.org/mailman/listinfo/python-list


Timezone for datetime.date objects

2022-02-27 Thread Morten W. Petersen
Hi.

I'm working on a project where I need to query data for a given year, in
the correct timezone.  For accounting purposes.

The code I worked on today is here, see also the version history:

https://github.com/morphex/ethereum-classic-taxman/blob/main/generate_csv.py

I was initially using the date object to get the right timespan, but then
found that using the right timezone with that was a bit of a pain.  So I
went for the datetime object instead, specifying 0 on hour, minute and
second.

What's the thinking behind this with the date object?  Wouldn't it be nice
to be able to specify a timezone?

Regards,

Morten

-- 
I am https://leavingnorway.info
Videos at https://www.youtube.com/user/TheBlogologue
Twittering at http://twitter.com/blogologue
Blogging at http://blogologue.com
Playing music at https://soundcloud.com/morten-w-petersen
Also playing music and podcasting here:
http://www.mixcloud.com/morten-w-petersen/
On Google+ here https://plus.google.com/107781930037068750156
On Instagram at https://instagram.com/morphexx/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Syslog working on OSX Monterey

2022-02-27 Thread Dennis Lee Bieber
On Sun, 27 Feb 2022 08:34:21 -0800, Philip Bloom
 declaimed the following:

>
>sys_handler = SysLogHandler(address='/var/run/syslog')

As I read the documentation, the address is supposed to be the NETWORK
address of the machine to receive the log messages...

https://docs.python.org/3/library/logging.handlers.html#sysloghandler

>#sys_handler.encodePriority(SysLogHandler.LOG_USER, SysLogHandler.LOG_ALERT)
># Tried with the above, but didn't make a difference.  Neither did not
>defining the address and letting it go to local host.
>sys_handler.setFormatter(syslog_format)
>root_logger.addHandler(sys_handler)
>
>logging.critical("This is a test")
>logging.error("This is a test error")
>logging.info("Still a test")
>logging.debug("Testy test")
>
>Using command line: Oddly, this gets to Console.Apps messages from device
>reliably, though doesn't get picked up by syslog -w or get received by the
>ASL config redirect:
>syslog -s -l error -k Message "appName: this is a test2"
>syslog -s -l notice -k Message "appName: this is a test3"
>
>ASL configuration, which is loaded according to syslog -config:
>> /var/log/appName/appName.log mode=0640 compress format=std rotate=seq
>file_max=50M all_max=500M
>? [CA= Sender appName] file /var/log/appName/appName.log
>
>My end goal is really to get just a working python logging ->
>var/log/appname/appname.log again so glad to just be pointed in the right
>direction if way off base.


-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Syslog working on OSX Monterey

2022-02-27 Thread Philip Bloom via Python-list
Thanks.  Had tried it with no address, which defaults to ('localhost',
'514') as well as address='/var/run/syslog' which had been working
previously, and the doc recommends as:
For example, on Linux it’s usually ‘/dev/log’ but on OS/X it’s
‘/var/run/syslog’. You’ll need to check your platform and use the
appropriate address (you may need to do this check at runtime if your
application needs to run on several platforms)

Aiming for this to be being picked up on the same computer I'm running the
test script (Python -> Logging -> SyslogHandler -> Mac OS Syslogd -> parsed
ASL config -> /var/log/Appname/Appname.log).   It's why I think I may be
missing something fundamental, but it feels like something subtle changed
in the latest OSX.

On Sun, Feb 27, 2022 at 11:26 AM Dennis Lee Bieber 
wrote:

> On Sun, 27 Feb 2022 08:34:21 -0800, Philip Bloom
>  declaimed the following:
>
> >
> >sys_handler = SysLogHandler(address='/var/run/syslog')
>
> As I read the documentation, the address is supposed to be the
> NETWORK
> address of the machine to receive the log messages...
>
> https://docs.python.org/3/library/logging.handlers.html#sysloghandler
>
> >#sys_handler.encodePriority(SysLogHandler.LOG_USER,
> SysLogHandler.LOG_ALERT)
> ># Tried with the above, but didn't make a difference.  Neither did not
> >defining the address and letting it go to local host.
> >sys_handler.setFormatter(syslog_format)
> >root_logger.addHandler(sys_handler)
> >
> >logging.critical("This is a test")
> >logging.error("This is a test error")
> >logging.info("Still a test")
> >logging.debug("Testy test")
> >
> >Using command line: Oddly, this gets to Console.Apps messages from device
> >reliably, though doesn't get picked up by syslog -w or get received by the
> >ASL config redirect:
> >syslog -s -l error -k Message "appName: this is a test2"
> >syslog -s -l notice -k Message "appName: this is a test3"
> >
> >ASL configuration, which is loaded according to syslog -config:
> >> /var/log/appName/appName.log mode=0640 compress format=std rotate=seq
> >file_max=50M all_max=500M
> >? [CA= Sender appName] file /var/log/appName/appName.log
> >
> >My end goal is really to get just a working python logging ->
> >var/log/appname/appname.log again so glad to just be pointed in the right
> >direction if way off base.
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> [email protected]
> http://wlfraed.microdiversity.freeddns.org/
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Philip Bloom
Director, Services Engineering
*AppLovin Corporation*
M: (786)-338-1439 <786-338-1439>
[image: LinkedIn]  [image:
Twitter]  [image: Facebook]
 [image: Instagram]

[image: AppLovin] 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Syslog working on OSX Monterey

2022-02-27 Thread Dennis Lee Bieber
On Sun, 27 Feb 2022 14:17:39 -0500, Dennis Lee Bieber
 declaimed the following:

APOLOGIES -- I thought I KILLED the draft message, not sent it...


-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Aw: PYT - How can I subscribe to a topic in the mailing list?

2022-02-27 Thread Ethan Furman

On 2/21/22 3:19 AM, vanyp wrote:

> The option to filter by topic is offered in the mailing list subscription 
customization page, although
> no option list is given. Topics may have been a project that was never 
implemented.

Topics are not currently enabled.  I suspect for them to be useful, people would have to be diligent about setting them, 
which, quite frankly, I don't see happening -- some don't even set a useful subject line.


--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: One-liner to merge lists?

2022-02-27 Thread Peter Otten

On 27/02/2022 17:28, Chris Angelico wrote:

On Mon, 28 Feb 2022 at 03:24, MRAB  wrote:


On 2022-02-27 08:51, Barry Scott wrote:




On 22 Feb 2022, at 09:30, Chris Angelico  wrote:

On Tue, 22 Feb 2022 at 20:24, Frank Millman mailto:[email protected]>> wrote:


Hi all

I think this should be a simple one-liner, but I cannot figure it out.

I have a dictionary with a number of keys, where each value is a single
list -


d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']}


I want to combine all values into a single list -


ans = ['aaa', 'bbb', 'ccc', 'fff', 'ggg']


I can do this -


a = []
for v in d.values():

...   a.extend(v)
...

a

['aaa', 'bbb', 'ccc', 'fff', 'ggg']

I can also do this -


from itertools import chain
a = list(chain(*d.values()))
a

['aaa', 'bbb', 'ccc', 'fff', 'ggg']




Is there a simpler way?



itertools.chain is a good option, as it scales well to arbitrary
numbers of lists (and you're guaranteed to iterate over them all just
once as you construct the list). But if you know that the lists aren't
too large or too numerous, here's another method that works:


sum(d.values(), [])

['aaa', 'bbb', 'ccc', 'fff', 'ggg']

It's simply adding all the lists together, though you have to tell it
that you don't want a numeric summation.


If you code is performance sensitive do not use sum() as it creates lots of tmp 
list that are deleted.

I have an outstanding ticket at work to replace all use of sum() on lists as 
when we profiled it
stands out as a slow operation. We have a lots of list of list that we need to 
flatten.


I think that 'sum' uses '__add__' but not '__iadd__'.

If it copied the given value, if present, and then used '__iadd__', if
present, wouldn't that speed it up?


It's hardly relevant. If you care about speed, use chain(), like
everyone's been saying all along :)


Not everyone. I believe (*) that __iadd__ is faster, and again, you can
spell it

functools.reduce(operator.iconcat, list_of_lists, [])

(*) Actual measurements left as an exercise ;)

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


Re: Timezone for datetime.date objects

2022-02-27 Thread Cameron Simpson
On 27Feb2022 11:16, Morten W. Petersen  wrote:
>I was initially using the date object to get the right timespan, but 
>then
>found that using the right timezone with that was a bit of a pain.  So I
>went for the datetime object instead, specifying 0 on hour, minute and
>second.
>
>What's the thinking behind this with the date object?  Wouldn't it be nice
>to be able to specify a timezone?

This has come up before. My own opinion is that no, it would be a bad 
idea. You're giving subday resolution to an object which is inherently 
"days". Leaving aside the many complications it brings (compare two 
dates, now requiring timezone context?) you've already hit on the easy 
and simple solution: datetimes.

I'd even go so far as to suggest that if you needed a timezone for 
precision, then dates are the _wrong_ precision to work in.

Anyway, personally I am -1 on the idea.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Timezone for datetime.date objects

2022-02-27 Thread Chris Angelico
On Mon, 28 Feb 2022 at 08:51, Cameron Simpson  wrote:
>
> On 27Feb2022 11:16, Morten W. Petersen  wrote:
> >I was initially using the date object to get the right timespan, but
> >then
> >found that using the right timezone with that was a bit of a pain.  So I
> >went for the datetime object instead, specifying 0 on hour, minute and
> >second.
> >
> >What's the thinking behind this with the date object?  Wouldn't it be nice
> >to be able to specify a timezone?
>
> This has come up before. My own opinion is that no, it would be a bad
> idea. You're giving subday resolution to an object which is inherently
> "days". Leaving aside the many complications it brings (compare two
> dates, now requiring timezone context?) you've already hit on the easy
> and simple solution: datetimes.
>
> I'd even go so far as to suggest that if you needed a timezone for
> precision, then dates are the _wrong_ precision to work in.
>

I would agree. If you have timestamps and you're trying to determine
whether they're within a certain range, and timezones matter, then
your range is not days; it begins at a specific point in time and ends
at a specific point in time. Is that point midnight? 2AM? Start/close
of business? It could be anything, and I don't see a problem with
requiring that it be specified.

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


Re: Getting Syslog working on OSX Monterey

2022-02-27 Thread Barry


> On 27 Feb 2022, at 18:36, Philip Bloom via Python-list 
>  wrote:
> 
> Hello,
> 
> First time mailing and looking for help/guidance.  Hopefully not too in the
> wrong place.
> 
> We've had an app with logging to a /var/log for many years through
> logging.sysloghandler.  Recently, though, I noticed that it suddenly was
> getting no logs whatsoever over there and investigated, believing the
> recent triggering change was upgrading to Mac OSX 12 (Monterey).
> 
> My understanding is a bit primitive, but our config had never been hard to
> follow previously and I may be missing something fundamental.  I've looked
> over a number of online examples but they don't seem to be running
> correctly either.  I'm on Python 3.6.8 (though we're about to start an
> upgrade to the latest stable, if that in theory may have changes to syslog
> handling).  I'm mostly ending up here since I'm finding such differences in
> response between python modules I'd expect to be fairly similar.
> 
> Separating into a test script I've been testing with logging.SysLogHandler,
> syslog, and the command line 'syslog -s'.  Replaced all below with a
> placeholder appName but it's normally a fairly unique setupCDNGUI name.
> 
> Example with syslog (python module):  - This will show up in System.log but
> not in Apple's Console for all messages to device, though won't get all the
> way to file.
> import syslog
> syslog.syslog(syslog.LOG_NOTICE, 'AppName: THIS IS A TEST - Processing
> started')
> syslog.syslog(syslog.LOG_ERR, 'AppName: THIS IS A TEST ERROR - Processing
> started')
> 
> Example with SyslogHandler: - This doesn't seem to show up anywhere besides
> the screen log, which is odd to me as reading the docs, I understood this
> to be a logging integration into the syslog module, so expected similar
> behavior in at least what was sent out.  Syslog handler is definitely
> picked up in logging.handlers
> 
> root_logger = logging.getLogger()
> root_logger.setLevel(logging.DEBUG)
> basic_datefmt = '%m/%d/%Y %I:%M:%S %p'
> 
> formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s',
> datefmt=basic_datefmt)
> syslog_format = logging.Formatter(fmt='SetupCDNGUI: %(message)s',
> datefmt=basic_datefmt)
> 
> scrhandler = logging.StreamHandler()
> scrhandler.setFormatter(formatter)
> root_logger.addHandler(scrhandler)
> 
> sys_handler = SysLogHandler(address='/var/run/syslog')
> #sys_handler.encodePriority(SysLogHandler.LOG_USER, SysLogHandler.LOG_ALERT)
> # Tried with the above, but didn't make a difference.  Neither did not
> defining the address and letting it go to local host.
> sys_handler.setFormatter(syslog_format)
> root_logger.addHandler(sys_handler)
> 
> logging.critical("This is a test")
> logging.error("This is a test error")
> logging.info("Still a test")
> logging.debug("Testy test")
> 
> Using command line: Oddly, this gets to Console.Apps messages from device
> reliably, though doesn't get picked up by syslog -w or get received by the
> ASL config redirect:
> syslog -s -l error -k Message "appName: this is a test2"
> syslog -s -l notice -k Message "appName: this is a test3"
> 
> ASL configuration, which is loaded according to syslog -config:
>> /var/log/appName/appName.log mode=0640 compress format=std rotate=seq
> file_max=50M all_max=500M
> ? [CA= Sender appName] file /var/log/appName/appName.log
> 
> My end goal is really to get just a working python logging ->
> var/log/appname/appname.log again so glad to just be pointed in the right
> direction if way off base.

If you look at the code of the logging modules syslog handle you will see that
it does not use syslog. It’s assuming that it can network to a syslog listener.
Such a listener is not running on my systems as far as I know.

I have always assumed that if I want a logger syslog handler that I would have
to implement it myself. So far I have code that uses syslog directly and have
not written that code yet.

Barry

> 
> -- 
> Philip Bloom
> Director, Services Engineering
> *AppLovin Corporation*
> M: (786)-338-1439 <786-338-1439>
> [image: LinkedIn]  [image:
> Twitter]  [image: Facebook]
>  [image: Instagram]
> 
> [image: AppLovin] 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: ping script

2022-02-27 Thread 황병희
Dear Barry,

Barry Scott  writes:

>> [...]
> This is correct python3.org  is only setup for email.
> Use the host and dig commands to check for yourself.

It is very amazing! Thanks for explanation!

> Compare
>
> $ host python.org 
>
> with
>
> $ host python3.org
>
> And compare:
>
> $ dig -t A python.org 
> $ dig -t MX python.org 
>
> with
>
> $ dig -t A python3.org 
> $ dig -t MX python3.org 
>
> Barry
>

Sincerely, Linux fan Byung-Hee

-- 
^고맙습니다 _布德天下_ 감사합니다_^))//
-- 
https://mail.python.org/mailman/listinfo/python-list