Skip to content
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

Roslibjs logging 211 #299

Merged
merged 11 commits into from
Feb 15, 2020
Merged

Roslibjs logging 211 #299

merged 11 commits into from
Feb 15, 2020

Conversation

joshua-glazer
Copy link
Member

@joshua-glazer joshua-glazer commented Feb 11, 2020

Assignee Section

hi it me

Description

Created js functions for logging to mimic rospy functions: logInfo, logWarn, logErr, logFatal
These all call rosLog which is assisted by rosTimeStamp and publishRosLog. A new publisher was created so that these functions all log to /rosout. In practice this means you'll find the logs in rosout.log on the computer which is running as ROS MASTER. The functions include the timestamp and the log level.

I've left some todos. Most of them are bonus features that aren't necessarily required. However one missing aspect is the logic for activating/deactivating logDebug as this would need some discussion on where we put the variable that handles this.

How to Test:

  • run the GUI with rosgui and startgui
  • open a terminal and subscribe to /rosout: rostopic echo /rosout
  • open the chrome console on the GUI and call the following functions one by one, passing in a string of your choosing as the parameter: logDebug, logInfo, logWarn, logErr, logFatal
  • verify that messages with the format [<loglevel>] [<timestamp>]: <message> are shown:
    • in the chrome console, where debug/info are normal messages, warn is a warning, error and fatal are errors
    • in the GUI console, where they all show up simply as text
    • in the terminal, where they are shown with all of the parameters (seq, secs, nsecs, etc.)
    • at the end of ~/.ros/log/latest/rosout.log. May require that you close roscore (and possibly all the other ros scripts) before the logfile is updated

Future potential issues:

closes #211

Approval from at least one software team lead is necessary before merging.

Reviewer Section

Aside from local testing and the General Integration Test it is implied that static analysis should be included in the verification process.

For Pull Requests that do not include code changes, it is not required to perform the tests above.

Copy link
Collaborator

@MartensCedric MartensCedric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very hot @vashmata . Honestly I'm very impressed by this PR. It looks clean

robot/basestation/static/js/roslibjs/ros-helpers.js Outdated Show resolved Hide resolved
robot/basestation/static/js/roslibjs/ros-helpers.js Outdated Show resolved Hide resolved
@joshua-glazer
Copy link
Member Author

I've made some significant refactorings to hopefully clean the code up more

joshua-glazer and others added 2 commits February 13, 2020 17:05
Co-authored-by: MartensCedric <cedricmartens98@gmail.com>
MartensCedric
MartensCedric previously approved these changes Feb 13, 2020
@MartensCedric
Copy link
Collaborator

@PeterGhimself I approved

Copy link
Member

@PeterGhimself PeterGhimself left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to include a step by step instruction on how to actually test your code. Just add it to your PR description and I'll test it right after.

@@ -188,6 +204,76 @@ function initRosWeb () {
}

/* functions used in main code */

function rosTimestamp () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding any new function good practice is to add a docstring for it.
Please add a high level overview of what each function does, in a sentence or two.

Copy link
Collaborator

@MartensCedric MartensCedric Feb 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeterGhimself It looks like I did add a docstring. Did I do it right?

let currentTime = new Date()
let secs = currentTime.getTime()/1000 // seconds before truncating the decimal
let secsFloored = Math.floor(secs) // seconds after truncating
let nsecs = Math.round(1000000000*(secs-secsFloored)) // nanoseconds since the previous second
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say rename this nanoSecs to make the name clearer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

logData = {}
logData[ROSDEBUG] = {prefix : '[DEBUG]', isError : false}
logData[ROSINFO] = {prefix : '[INFO]', isError : false}
logData[ROSWARN] = {prefix : '[WARN]', isError : true}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do two things:

  1. since semantically (and like in C++) warnings != erros this isError should be false
  2. we should use console.warn('something')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dealt with

stamps = rosTimestamp()
consoleMsg = logData[logLevel].prefix + ' [' + stamps[1] + ']: ' + message

!logData[logLevel].isError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler is better. Either make if else statement or write a comment (in English) explaining what's going on plz

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dealt with

Copy link
Collaborator

@MartensCedric MartensCedric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to open the issues of what you wrote on the PR if you want them to get implemented

Copy link
Member

@PeterGhimself PeterGhimself left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and everything seems good. Messages appear in console, in GUI console, as well as appearing in the ~/.ros/log/latest/rosout.log on a ROS master computer.

Great work 😍 😎

josh_is_hungry

@PeterGhimself PeterGhimself merged commit 0e37849 into master Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find equivalent or simulate a way to log info to ROS from roslibjs
3 participants