hunterslogger
v1.0.3
Published
A utility for managing console logs within a JavaScript application
Downloads
41
Readme
logger
A utility for managing console logs within a JavaScript application. This utility allows for centralized control over the format of application logs.
Tables of contents
Installing
npm install --save hunterslogger
Usage
import Logger from 'hunterslogger';
const logger = new Logger('nameOfThisFile');
...
logger.log('your log message');
logger.warn('your warning');
logger.error('your error');
Classes
Functions
Logger
Kind: global class
new Logger(moduleName)
Conctructor
| Param | Type | Description | | --- | --- | --- | | moduleName | String | name of the module that is consuming Logger |
logger.log(message)
Log a message to the browser console
Kind: instance method of Logger
| Param | Type | Description | | --- | --- | --- | | message | String | message to be logged |
logger.warn(message)
Log a warning to the console
Kind: instance method of Logger
| Param | Type | | --- | --- | | message | String |
logger.error(message)
Log an error to the console
Kind: instance method of Logger
| Param | Type | | --- | --- | | message | String |
verifyVariableIsType(variable, type)
Verify that a given variable is of a particular type.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | variable | * | the variable being verified | | type | String | the expected type of the variable |
Contributing
- Pull down the code into a local git repo
- Install the development dependencies:
npm install
- Make your changes (be sure to have unit tests covering your changes)
- Run the unit tests:
npm run test
- If all of the unit tests pass, build the source code:
npm run build
- Submit a pull request :)
Testing
Tests are run with Jasmine: https://jasmine.github.io/index.html
Tests can be run with the following command: npm run test
I wanted to maintain a build status, so I decided to use Travis CI after finding the following StackOverflow answer after some googling: https://stackoverflow.com/questions/13546097/how-do-show-my-tests-passing-failing-in-github
Since specs are written using ES2015 syntax, spec files must be transpiled using babel. I detail how I created this build step below.
When I initially attempted to run the Jasmine unit tests, I received the following error in the console:
Hunters-MacBook-Pro:logger hunterhodnett$ ./node_modules/.bin/jasmine
/Users/hunterhodnett/PersonalProjects/logger/spec/logger.spec.js:5
import Logger from '../src/logger.js';
^^^^^^
SyntaxError: Unexpected token import
This led me to the following StackOverflow question: https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import
...which led me to perform the following google search: https://www.google.com/search?q=jasmine+spec+babel&rlz=1C5CHFA_enUS725US725&oq=jasmine+spec+babel&aqs=chrome..69i57.5799j0j4&sourceid=chrome&ie=UTF-8
...which led me to the following gist (first result in google search): https://gist.github.com/mauvm/172878a9646095d03fd7
...which led me to create the run.js file in the /spec directory, as well as change the "test" command (within the
"scripts" section of package.json) to "./node_modules/.bin/babel-node spec/run.js", which kicks off a transpile of run.js,
which imports and runs Jasmine from within a node environment that supports ES2015 syntax.