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

feat: Log all arguments when first argument is not a string #19

Merged
merged 1 commit into from Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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], [4, 5, 6]);
});
});