Skip to content

Commit

Permalink
feat: Log all arguments when first argument is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 10, 2024
1 parent c41df31 commit c360245
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
16 changes: 12 additions & 4 deletions README.md
Expand Up @@ -33,34 +33,42 @@ logger.info([1, 2, 3]);

Logging (and level of logging) is controlled by [`gulp-cli`][gulp-cli-url]

#### logger.debug(msg)
#### logger.debug(msg, ...args)

Highest log level. Typically used for debugging purposes.

If the first argument is a string, all arguments are passed to node's
[`util.format()`][util-format-url] before being emitted.

#### logger.info(msg)
If the first argument is not a string, all arguments will be emitted directly.

#### logger.info(msg, ...args)

Standard log level. Typically used for user information.

If the first argument is a string, all arguments are passed to node's
[`util.format()`][util-format-url] before being emitted.

#### logger.warn(msg)
If the first argument is not a string, all arguments will be emitted directly.

#### logger.warn(msg, ...args)

Warning log level. Typically used for warnings.

If the first argument is a string, all arguments are passed to node's
[`util.format()`][util-format-url] before being emitted.

#### logger.error(msg)
If the first argument is not a string, all arguments will be emitted directly.

#### logger.error(msg, ...args)

Error log level. Typically used when things went horribly wrong.

If the first argument is a string, all arguments are passed to node's
[`util.format()`][util-format-url] before being emitted.

If the first argument is not a string, all arguments will be emitted directly.

## License

MIT
Expand Down
32 changes: 20 additions & 12 deletions index.d.ts
Expand Up @@ -2,35 +2,43 @@
* Highest log level. Typically used for debugging purposes.
*
* If the first argument is a string, all arguments are passed to node's util.format() before being emitted.
*
* If the first argument is not a string, all arguments will be emitted directly.
*
* @param msg Message to log
* @param args Arguments to format message with via util.format()
* @param args Additional arguments
*/
export function debug(msg: string, ...args: any[]): void;
export function debug(msg: any): void;
export function debug(msg: any, ...args: any[]): void;
/**
* Standard log level. Typically used for user information.
*
* If the first argument is a string, all arguments are passed to node's util.format() before being emitted.
*
* If the first argument is not a string, all arguments will be emitted directly.
*
* @param msg Message to log
* @param args Arguments to format message with via util.format()
* @param args Additional arguments
*/
export function info(msg: string, ...args: any[]): void;
export function info(msg: any): void;
export function info(msg: any, ...args: any[]): void;
/**
* Warning log level. Typically used for warnings.
*
* If the first argument is a string, all arguments are passed to node's util.format() before being emitted.
*
* If the first argument is not a string, all arguments will be emitted directly.
*
* @param msg Message to log
* @param args Arguments to format message with via util.format()
* @param args Additional arguments
*/
export function warn(msg: string, ...args: any[]): void;
export function warn(msg: any): void;
export function warn(msg: any, ...args: any[]): void;
/**
* Error log level. Typically used when things went horribly wrong.
*
* If the first argument is a string, all arguments are passed to node's util.format() before being emitted.
*
* If the first argument is not a string, all arguments will be emitted directly.
*
* @param msg Message to log
* @param args Arguments to format message with via util.format()
* @param args Additional arguments
*/
export function error(msg: string, ...args: any[]): void;
export function error(msg: any): void;
export function error(msg: any, ...args: any[]): void;
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"test": "nyc mocha --async-only"
},
"dependencies": {
"glogg": "^2.0.0"
"glogg": "^2.1.0"
},
"devDependencies": {
"eslint": "^7.32.0",
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Expand Up @@ -83,4 +83,14 @@ describe('gulplog', function () {

logger.info([1, 2, 3]);
});

it('logs all arguments if first argument is not a string', function (done) {
logger.on('info', function (arg1, arg2) {
expect(arg1).toEqual([1, 2, 3]);
expect(arg2).toEqual([4, 5, 6]);
done();
});

logger.info([1, 2, 3], [1, 2, 3]);
});
});

0 comments on commit c360245

Please sign in to comment.