Not to bring up old issues but, I am trying to format my logs. I read the
wiki attached to this thread and I have this configuration working in my
weewx.conf:
# ===== LOGGING SETUP (Configured 09/04/2021) =====
[Logging]]
[[root]]
handlers = rotate,
[[loggers]]
[[handlers]]
[[[rotate]]]
level = INFO
formatter = standard
class = logging.handlers.RotatingFileHandler
filename = /mnt/sandisk_512_ssd/weewx/logs/weewx.log
maxBytes = 1000000
backupCount = 10
# ===== END LOGGING SETUP =====
But I want to format the logging out using a custom formatter as such:
# ==== PROPOSED CHANGE TO MY WEEWX.CONF =====
[Logging]
[[formatters]]
[[[ddj]]]
format =
'%(asctime)s [%(levelname)s] [%(threadName)s] [%(name)s : %(funcName)s]
%(message)s'
[[root]]
handlers = rotate,
[[loggers]]
[[handlers]]
[[[rotate]]]
level = INFO
formatter = ddj
class = logging.handlers.RotatingFileHandler
filename = /mnt/sandisk_512_ssd/weewx/logs/weewx.log
maxBytes = 1000000
backupCount = 10
# ===== END LOGGING SETUP =====
I am running Weewx 4.5.1 on a Raspberry Pi using Raspbian O/S (32bit) which
is essentially Debian buster.
Is there a way to express a formatter in the weewx.conf file so the logging
object will format the results for me?
On Friday, August 21, 2020 at 3:27:49 PM UTC-4 [email protected] wrote:
> Just like to say I updated to 4.x and just added
>
> [Logging]
> [[handlers]]
> [[[rotate]]]
> filename = /tmp/weewx.log
>
> To the top section of my weewx.conf file (after version) and it is
> WONDERFUL to finally have real log output from weewx. It's beautiful! I
> might cry for not having to stare at Console.app and hope for something. :)
> Thank you all for your continued efforts.
> On Sunday, May 3, 2020 at 4:54:13 AM UTC-7 [email protected] wrote:
>
>> I like your fix better. Added in commit 6348741
>> <https://github.com/weewx/weewx/commit/6348741c64f55c5b2d34d9b9c70a5ed0b6d55c7f>
>> .
>>
>> I also made the rotating log handler the default for MacOS.
>>
>> One problem I've discovered: if you 'declare' a handler, then the logging
>> facility goes ahead and instantiates it, whether or not you actually use
>> it. That means the program crashes when it tries to create
>> /var/log/weewx.log unless its run with sudo privileges.
>>
>> So, for non-Mac systems, I took the handler back out, and put
>> instructions on how to declare it in the wiki documentation
>> <https://bit.ly/2StYSHb>.
>>
>> -tk
>>
>>
>> On Sun, May 3, 2020 at 12:11 AM Graham Eddy <[email protected]> wrote:
>>
>>> woops! i missed your reference to replacement weeutil/logger.py…
>>> putting that in place, it works fine on macos.
>>> it achieves the two things i was after: logs entries in a file (a basic
>>> function missing from weewx on macos for such a long time!), and allows
>>> customising message formats
>>>
>>> i have two critiques about this fix:
>>>
>>> (1) linux would want [syslog] handlers only but macos would want
>>> [rotate] for default. easiest is to default correctly for one in the code
>>> and override it in weewx.conf for the other (applied either by user or
>>> installation script). if both enabled, harmless (if not duplicating entries
>>> in one logfile on linux) but wasteful
>>>
>>> (2) shim approach is per- logging handler class only. would be pretty
>>> easy for python user to add another shim in user/extensions.py but…
>>> alternatively, do the string->int conversions e.g. add after line 130 in
>>> weeutil/logger.py “log_config['Logging'].walk(_fix)” something like:
>>>
>>> def _intify_string_leaf(section, key):
>>>
>>> if isinstance(section[key], str):
>>> # The value is a string...
>>> try:
>>> value = int(section[key])
>>> except ValueError:
>>> pass
>>> else:
>>> # ... looks like an int, so make it one
>>> section[key] = value
>>> log_config['Logging'].walk(_intify_string_leaf)
>>>
>>> (this works.) conversely, intifying all leaves could have unintended
>>> consequences...
>>>
>>> thanks for all that! cheers
>>>
>>> On 3 May 2020, at 5:07 am, Tom Keffer <[email protected]> wrote:
>>>
>>> Try this version of weeutil/logger.py. It includes a shim that does the
>>> proper type conversion before passing on arguments to
>>> logging.handlers.RotatingFileHandler.
>>>
>>> To use should be as simple as adding this to weewx.conf (alas, NOT
>>> TESTED):
>>>
>>> [Logging]
>>> [[loggers]]
>>> [[[root]]]
>>> handlers = syslog, rotate
>>> [[handlers]]
>>> [[[rotate]]]
>>> filename = /tmp/weewx.log
>>>
>>> By default, it logs to /var/log/weewx.log. Hence, the need to override
>>> that option if you want to log to /tmp/weewx.log.
>>>
>>>
>>> --
>>> 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 [email protected].
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/weewx-user/AB7F41D1-FD08-400D-B80A-01E53BD42D5A%40gmail.com
>>>
>>> <https://groups.google.com/d/msgid/weewx-user/AB7F41D1-FD08-400D-B80A-01E53BD42D5A%40gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/819f1a6c-2ae0-4861-a5c1-726512243c5an%40googlegroups.com.