internal RosOutLogger(string typeName, string nodeId, LogLevel logLevel, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat)
            : base(typeName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
        {
            _nodeId = nodeId;
            _node   = Ros.GetNodes().FirstOrDefault(x => x.NodeId == _nodeId);

            if (_node != null)
            {
                _publisher = _node.LogPubliser;
            }
        }
        protected override void WriteInternal(LogLevel targetLevel, object message, Exception e)
        {
            var sb = new StringBuilder();

            FormatOutput(sb, targetLevel, message, e);

            if (_node == null)
            {
                _node = Ros.GetNodes().FirstOrDefault(x => x.NodeId == _nodeId);
            }

            LogLevel currentLevel = LogLevel.Info;
            string   nodeId       = "unknown";

            if (_node != null)
            {
                currentLevel = _node.LogLevel.ToLogLevel();
                nodeId       = _node.NodeId;
            }

            if (_publisher == null && _node != null)
            {
                _publisher = _node.LogPubliser;
            }

            if (_publisher != null)
            {
                if (targetLevel >= currentLevel)
                {
                    _publisher.OnNext(new Log()
                    {
                        name  = nodeId,
                        level = currentLevel.ToLogLevel(),
                        msg   = message.ToString()
                    });
                }
            }
        }
Beispiel #3
0
        public void Start()
        {
            var node = Ros.InitNodeAsync("/rosout", enableLogger: false).Result;

            var publisher  = node.PublisherAsync <Log>("/rosout_agg").Result;
            var subscriber = node.SubscriberAsync <Log>("/rosout").Result;


            subscriber.Subscribe(x =>
            {
                Console.WriteLine(x);
            });

            var d = subscriber.Publish(xs =>
            {
                xs.Where(x => x.level == Log.DEBUG).Subscribe(x => _logger.Debug(m => m("Node = {0}, Message = {1}", x.name, x.msg)));
                xs.Where(x => x.level == Log.INFO).Subscribe(x => _logger.Info(m => m("Node = {0}, Message = {1}", x.name, x.msg)));
                xs.Where(x => x.level == Log.WARN).Subscribe(x => _logger.Warn(m => m("Node = {0}, Message = {1}", x.name, x.msg)));
                xs.Where(x => x.level == Log.ERROR).Subscribe(x => _logger.Error(m => m("Node = {0}, Message = {1}", x.name, x.msg)));
                xs.Where(x => x.level == Log.FATAL).Subscribe(x => _logger.Fatal(m => m("Node = {0}, Message = {1}", x.name, x.msg)));
                return(xs);
            }).Subscribe();
        }