i think we all agree that syslog on macos is a lost cause.
the corollary is that pointing python logging at syslog (via 
logging.handlers.SysLogHandler) is doomed

i accept that syslog works fine on most platforms, but it is not feasible for 
macos
but there is the simple alternative for macos users of using a different 
handler:

i patched log_dict in bin/weeutil/logger.py to add a 
logging.handlers.RotatingFileHandler and it worked fine.
adding it via weewx.conf gives a type conversion error that seems simple to fix.
with the fix, i would suggest this be added to the macos installation 
instructions for user to add to weewx.conf (or make it part of the installation 
process)

details follow...

weewx.conf (yes, using that ‘root’ hack introduced to work around a ConfigObj 
limitation):

[Logging]
  [[loggers]]
    [[[root]]]
      level = DEBUG
      propogate = True
      handlers = syslog, rotate
  [[handlers]]
    [[[rotate]]]
      level = DEBUG
      formatter = standard
      class = logging.handlers.RotatingFileHandler
      filename = /tmp/weewx.log
      maxBytes = 10000000
      backupCount = 2

gives the following error, which on the face of it would take a simple fix of 
type conversions:

Traceback (most recent call last):
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py",
 line 563, in configure
    handler = self.configure_handler(handlers[name])
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py",
 line 736, in configure_handler
    result = factory(**kwargs)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/handlers.py",
 line 146, in __init__
    if maxBytes > 0:
TypeError: '>' not supported between instances of 'str' and ‘int’ < - - - SEE 
HERE

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "bin/weewxd", line 261, in <module>
    main()
  File "bin/weewxd", line 136, in main
    weeutil.logger.setup(options.log_label, config_dict)
  File "/opt/weewx/bin/weeutil/logger.py", line 203, in setup
    logging.config.dictConfig(log_dict)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py",
 line 800, in dictConfig
    dictConfigClass(config).configure()
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py",
 line 571, in configure
    '%r' % name) from e
ValueError: Unable to configure handler 'rotate'

the log_dict it produces before crashing seems correct:

{'version': 1, 'disable_existing_loggers': False, 'loggers': {'': {'level': 
'DEBUG', 'propagate': True, 'handlers': ['syslog'], 'propogate': 'True'}}, 
'handlers': {'syslog': {'level': 'DEBUG', 'formatter': 'standard', 'class': 
'logging.handlers.SysLogHandler', 'address': '/var/run/syslog', 'facility': 
'local1'}, 'console': {'level': 'DEBUG', 'formatter': 'verbose', 'class': 
'logging.StreamHandler', 'stream': 'ext://sys.stdout'}, 'rotate': {'level': 
'DEBUG', 'formatter': 'standard', 'class': 
'logging.handlers.RotatingFileHandler', 'filename': '/tmp/weewx.log', 
'maxBytes': '10000000', 'backupCount': '2'}}, 'formatters': {'simple': 
{'format': '%(levelname)s %(message)s'}, 'standard': {'format': 
'weewx[%(process)d] %(levelname)s %(name)s: %(message)s'}, 'verbose': 
{'format': '%(asctime)s  weewx[%(process)d] %(levelname)s %(name)s: 
%(message)s', 'datefmt': '%Y-%m-%d %H:%M:%S'}}}

cheers

> On 2 May 2020, at 10:42 pm, Tom Keffer <tkef...@gmail.com> wrote:
> 
> Logging from Python under MacOS High Sierra and later is a complete mystery. 
> I have been unable to get it to work and, it seems, neither have other 
> <https://apple.stackexchange.com/questions/256769/how-to-use-logger-command-on-sierra>
>  users 
> <https://stackoverflow.com/questions/49805750/macos-high-sierra-syslog-does-not-work/51052538>.
> 
> Wish I could be of more help...
> 
> -tk
> 
> On Sat, May 2, 2020 at 5:26 AM Graham Eddy <graham.e...@gmail.com 
> <mailto:graham.e...@gmail.com>> wrote:
> i reported this incorrectly. instead of giveing me an unchanged logger 
> format, it gives me no lines at all (from the point the weewx.conf log format 
> is parsed).  even the following does the same (no logger output). commenting 
> out the “format” line reverts to lines being produced, in original format of 
> course
> 
> [Logging]
>   [[formatters]]
>     [[[standard]]]
>       format = '%(message)s'

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/85C23BE1-912C-4EAA-80AC-F7E81F8EE021%40gmail.com.

Reply via email to