ValueLoggingDelegate.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2016 Kevin Herron
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.html.
  12. */
  13. package at.acdp.opcur.opc;
  14. import org.eclipse.milo.opcua.sdk.server.api.nodes.VariableNode;
  15. import org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext;
  16. import org.eclipse.milo.opcua.sdk.server.nodes.delegates.AttributeDelegate;
  17. import org.eclipse.milo.opcua.sdk.server.nodes.delegates.DelegatingAttributeDelegate;
  18. import org.eclipse.milo.opcua.stack.core.UaException;
  19. import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. public class ValueLoggingDelegate extends DelegatingAttributeDelegate {
  23. private final Logger logger = LoggerFactory.getLogger(getClass());
  24. public ValueLoggingDelegate() {}
  25. public ValueLoggingDelegate(AttributeDelegate parent) {
  26. super(parent);
  27. }
  28. @Override
  29. public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
  30. DataValue value = super.getValue(context, node);
  31. // only log external reads
  32. if (context.getSession().isPresent()) {
  33. logger.info(
  34. "getValue() nodeId={} value={}",
  35. node.getNodeId(), value);
  36. }
  37. return value;
  38. }
  39. @Override
  40. public void setValue(AttributeContext context, VariableNode node, DataValue value) throws UaException {
  41. // only log external writes
  42. if (context.getSession().isPresent()) {
  43. logger.info(
  44. "setValue() nodeId={} value={}",
  45. node.getNodeId(), value);
  46. }
  47. super.setValue(context, node, value);
  48. }
  49. }