Skip to content

Commit

Permalink
Merge pull request #43 from Olian04/dev
Browse files Browse the repository at this point in the history
Published 4.4.0
  • Loading branch information
Olian04 authored Jul 16, 2020
2 parents 2872c4f + 67f05f0 commit d2cc1db
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 343 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require('better-logging')(console);
console.debug('foo'); // [11:46:35] [debug] foo
console.log('foo'); // [11:46:35] [log] foo
console.info('foo'); // [11:46:35] [info] foo
console.warn('foo'); // [11:46:35] [warning] foo
console.warn('foo'); // [11:46:35] [warn] foo
console.error('foo'); // [11:46:35] [error] foo
console.line('foo'); // foo

Expand Down Expand Up @@ -77,6 +77,23 @@ console.warn('foo'); // [11:44:40] [11:44:40 AM] [2/2/2019] [warn] [1549104280
console.error('foo'); // [11:44:40] [11:44:40 AM] [2/2/2019] [error] [1549104280580] [lel] foo
```

You might also want to keep log from previous runs, all you need to do is tell better-logging where you want to store the logs:

```js
require('better-logging')(console, {
saveToFile: `${Date.now()}.log`,
});

console.logLevel = 3;

console.debug('foo'); // won't log to console, but will be saved in 1594897100267.log
console.log('foo'); // logged to console & saved in 1594897100267.log
console.info('foo'); // logged to console & saved in 1594897100267.log
console.warn('foo'); // logged to console & saved in 1594897100267.log
console.error('foo'); // logged to console & saved in 1594897100267.log
console.line('foo'); // logged to console, but "line" is never saved in logs
```

Some times the default log levels might not fit your needs, in those cases you can redefine the log levels to anything you like.

```js
Expand Down Expand Up @@ -143,9 +160,9 @@ betterLogging(console, {

__Strategies:__

* ALL _(default)_: Will consume all arguments and format them as a single string.
* FIRST: Will consume just the first argument and format it as a string, it will then spread the rest of the arguments into the implementation call.
* NONE : Won't format any arguments, HOWEVER the format function will be called with an empty string as the message.
* ALL _(default)_: Will consume all arguments and format them as a single string. <br> `log(1, 2, 3) => impl.log(format('1 2 3'), ...[])`
* FIRST: Will consume just the first argument and format it as a string, it will then spread the rest of the arguments into the implementation call. <br> `log(1, 2, 3) => impl.log(format('1'), ...[2, 3])`
* NONE : Won't format any arguments, HOWEVER the format function will be called with an empty string as the message. <br> `log(1, 2, 3) => impl.log(format(''), ...[1, 2, 3])`

## Express middleware

Expand Down
14 changes: 14 additions & 0 deletions demo/saveToFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');

require('..')(console, {
saveToFile: path.join(__dirname, `logs-js/${process.title}-${Date.now()}.log`),
});

console.logLevel = 4;

console.log('this is a log message');
console.info('this is a info message');
console.error('this is a error message');
console.warn('this is a warn message');
console.debug('this is a debug message');
console.line('this is a line message');
15 changes: 15 additions & 0 deletions demo/saveToFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import betterLogging from '..';
import path from 'path';

betterLogging(console, {
saveToFile: path.join(__dirname, `logs-ts/${process.title}-${Date.now()}.log`),
});

console.logLevel = 4;

console.log('this is a log message');
console.info('this is a info message');
console.error('this is a error message');
console.warn('this is a warn message');
console.debug('this is a debug message');
console.line('this is a line message');
Loading

0 comments on commit d2cc1db

Please sign in to comment.