-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging: undefined namespace when logging string with format specifiers eg %d #22935
Comments
Doing some tests to figure this one out, we do indeed have a weird situation with specifier strings %d %s etc and it happens to be used in the date format of the network_map discovery modified test.logger.js it('Logs special chars', () => {
logger.setLevel('debug');
const logSpy = jest.spyOn(logger.winston, 'log');
consoleWriteSpy.mockClear();
let i = 1;
logger.debug('default namespace');
expect(logSpy).toHaveBeenLastCalledWith('debug', 'default namespace', {namespace: 'z2m'});
expect(consoleWriteSpy).toHaveBeenCalledTimes(i++);
logger.debug('specific namespace','z2m:mqtt');
expect(logSpy).toHaveBeenLastCalledWith('debug', 'specific namespace', {namespace: 'z2m:mqtt'});
expect(consoleWriteSpy).toHaveBeenCalledTimes(i++);
let net_map='special chars {"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state}}"}],"availability_mode":"all","device":{"hw_version":"zStack3x0 20230507","identifiers":["zigbee2mqtt_bridge_0xieeeAddr"],"manufacturer":"Zigbee2MQTT","model":"Bridge","name":"Zigbee2MQTT Bridge","sw_version":"1.37.1"},"enabled_by_default":false,"entity_category":"diagnostic","json_attributes_template":"{{value_json.data.value | tojson }}","json_attributes_topic":"zigbee2mqtt/bridge/response/networkmap","name":"Networkmap","object_id":"zigbee2mqtt_bridge_network_map","origin":{"name":"Zigbee2MQTT","sw":"1.37.1","url":"https:/www.zigbee2mqtt.io"},"state_topic":"zigbee2mqtt/bridge/responsenetworkmap","unique_id":"bridge_0xieeeAddr_network_map_zigbee2mqtt","value_template":"{{ now().strftime(\'%Y-%m-%d %H:%M:%S\') }}"}';
logger.debug(net_map,'z2m:mqtt');
expect(logSpy).toHaveBeenLastCalledWith('debug', net_map, {namespace: 'z2m:mqtt'});
expect(consoleWriteSpy).toHaveBeenCalledTimes(i++);
net_map='{"value_template":"{{ now().strftime(\'%Y-%m-%d %H:%M:%S\') }}"}';
logger.debug(net_map,'z2m:mqtt');
expect(logSpy).toHaveBeenLastCalledWith('debug', net_map, {namespace: 'z2m:mqtt'});
expect(consoleWriteSpy).toHaveBeenCalledTimes(i++);
net_map='%Y-%m-%d %H:%M:%S';
logger.debug(net_map,'z2m:mqtt');
expect(logSpy).toHaveBeenLastCalledWith('debug', net_map, {namespace: 'z2m:mqtt'});
expect(consoleWriteSpy).toHaveBeenCalledTimes(i++);
net_map='%Y';
logger.debug(net_map,'z2m:mqtt');
expect(logSpy).toHaveBeenLastCalledWith('debug', net_map, {namespace: 'z2m:mqtt'});
expect(consoleWriteSpy).toHaveBeenCalledTimes(i++); the test result is all green, but the actual logs are not : test log output
So the high level winston logger does see the right strings/parameters, but it seems that it then interprets the strings with format specifiers. @Nerivec do you see where this could come from ? I'm at the limit of my capabilities to debug this further... |
That bug is in my TODO list already, but I haven't gotten to it yet. |
* POC: Allow hierarchical filtering of logger namespaces matches the closes defined namespace log level: advanced: log_namespaced_levels: 'zh:zstack:unpi': info would also apply to zh:zstack:unpi:write and zh:zstack:unpi:parse To limit runtime penalty uses the namespacedLevels as a lazy cache * Move namespace levels to separate cache Avoid poluting the namespacedLevel in the config / UI Add cache reset on config time log level change * Actually use the cache * Optimize/Cleanup * Add some namespace hierarchy filter tests * More coverage. * Fix #22935 --------- Co-authored-by: Nerivec <62446222+Nerivec@users.noreply.github.com>
* POC: Allow hierarchical filtering of logger namespaces matches the closes defined namespace log level: advanced: log_namespaced_levels: 'zh:zstack:unpi': info would also apply to zh:zstack:unpi:write and zh:zstack:unpi:parse To limit runtime penalty uses the namespacedLevels as a lazy cache * Move namespace levels to separate cache Avoid poluting the namespacedLevel in the config / UI Add cache reset on config time log level change * Actually use the cache * Optimize/Cleanup * Add some namespace hierarchy filter tests * More coverage. * Fix Koenkk#22935 --------- Co-authored-by: Nerivec <62446222+Nerivec@users.noreply.github.com>
What happened?
Looking at the debug logs , sumbled upon an oddity with the new namespace logging ouputting an
undefined
:z2m 1.37.1
z2m 1.38.0
What did you expect to happen?
I expected that the namespace would be used
How to reproduce it (minimal and precise)
z2m:mqtt
namespacegrep 'network_map' zigbee2mqtt.log
Zigbee2MQTT version
1.38.0
Adapter firmware version
20230507
Adapter
Sonoff ZBDongle-P
Setup
container on pi3
Debug log
see above
The text was updated successfully, but these errors were encountered: