Skip to content

Commit

Permalink
Merge pull request #2 from StatelessStudio/v1.0.2
Browse files Browse the repository at this point in the history
V1.0.2
  • Loading branch information
DrewImm authored Jan 20, 2022
2 parents 3ef8fbe + 01d3511 commit ae30304
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 51 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ts-tiny-log

## [1.0.2]

### Fixes
- Export default instance from `/default`

## [1.0.1]

Initial Release
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
`npm i ts-tiny-log`

```typescript
import { log } from 'ts-tiny-log';
import { log } from 'ts-tiny-log/default';

log.info('Test!');
```
Expand All @@ -15,7 +15,7 @@ log.info('Test!');
There are 5 log-levels, `fatal`, `error`, `warn`, `info`, and `debug`. Each one accepts any number of arguments, and also accepts any type of variable, object, array, error, etc.

```typescript
import { log } from 'ts-tiny-log';
import { log } from 'ts-tiny-log/default';

// info level with a string variable
log.info('Hello, ', env.APP_TITLE);
Expand All @@ -34,12 +34,13 @@ catch (e) {

## Settings

Configure the log by passing a new instance to `setLog()`
Configure the log by creating a new instance. Export this so you can import your custom logger in your application.

`src/log.ts`
```typescript
import { Log, setLog } from 'ts-tiny-log';
import { Log } from 'ts-tiny-log';

setLog(new Log({
export const log: Log = new Log({
shouldWriteTimestamp: false
}));
```
Expand All @@ -52,10 +53,10 @@ Set the level that will be logged. Any level below this will also be logged. For
**Example:**

```typescript
import { Log, log, setLog } from 'ts-tiny-log';
import { Log } from 'ts-tiny-log';
import { LogLevel } from 'ts-tiny-log/levels';

setLog(new Log({
export const log: Log = new Log({
// Set the level to warn
level: LogLevel.warn
}));
Expand Down Expand Up @@ -83,10 +84,11 @@ Turn on/off timestamp column per log entry

**Example:**

`src/log.ts`
```typescript
import { Log, log, setLog } from '../src';
import { Log } from '../src';

setLog(new Log({
export const log: Log = new Log({
// Don't write timestamps
shouldWriteTimestamp: false
}));
Expand All @@ -111,9 +113,9 @@ Turn on/off log-level column per log entry
**Example:**

```typescript
import { Log, log, setLog } from '../src';
import { Log } from '../src';

setLog(new Log({
export const log: Log = new Log({
// Don't write log-level
shouldWriteLogLevel: false
}));
Expand All @@ -139,9 +141,9 @@ Determines how metadata columns (such as log-level and timestamp) are displayed.
**Example:**

```typescript
import { Log, log, setLog } from '../src';
import { Log } from '../src';

setLog(new Log({
export const log: Log = new Log({
// Use square brackets for columns
metadataFormat: str => `[${str.trim().toUpperCase()}]`
}));
Expand All @@ -165,7 +167,7 @@ Stream log output to a custom function.
In this example, output will be streamed to a file via a custom `streamToFile()` function:

```typescript
import { Log, log, setLog } from '../src';
import { Log } from '../src';
import { appendFileSync } from 'fs';

/**
Expand All @@ -178,7 +180,7 @@ function streamToFile(...data: any[]): void {
}

// Set our custom Log
setLog(new Log({
export const log: Log = new Log({
standardOut: streamToFile,
standardError: streamToFile,
}));
Expand Down
3 changes: 1 addition & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LogLevel } from '../src/levels';
import { log } from '../src/log';
import './log';
import { log } from './log';

log.fatal('Abort!');
log.error('An error!', new Error('Broken!'));
Expand Down
6 changes: 3 additions & 3 deletions example/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Log, setLog } from '../src';
import { Log } from '../src';

setLog(new Log({
export const log: Log = new Log({
// Add log settings here!
}));
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-tiny-log",
"version": "1.0.1",
"version": "1.0.2",
"ts-project-version": "1.2.4",
"private": "true",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Log } from './log';

export const log: Log = new Log();
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Log, log, setLog } from './log';
export { Log } from './log';
export { LogContract } from './contract';
7 changes: 0 additions & 7 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,3 @@ export class Log implements LogContract {
return line;
}
}

/**
* Internal log
*/
let log: Log = new Log();
export { log };
export const setLog = (l: Log) => log = l;
9 changes: 9 additions & 0 deletions test/spec/default.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Log } from '../../src';
import { log } from '../../src/default';

describe('default', () => {
it('exports a default log instance', () => {
expect(log).toBeDefined();
expect(log instanceof Log).toBeTrue();
});
});
9 changes: 0 additions & 9 deletions test/spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,4 @@ describe('index', () => {

expect(something).toBeDefined();
});

it('exports a log function', () => {
expect(index.log).toBeDefined();
});

it('exports a setLog function', () => {
const log = new index.Log();
expect(index.setLog(log)).toBe(log);
});
});
13 changes: 1 addition & 12 deletions test/spec/log.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LogLevel } from '../../src/levels';
import { Log, log, setLog } from '../../src/log';
import { Log } from '../../src/log';
import { captureLog } from '../utils/log/capture-log';
import { testLogLevelMethod } from '../utils/log/test-log-level-method';
import { timestampRegex } from '../utils/regex/timestamp';
Expand All @@ -11,17 +11,6 @@ describe('Log', () => {
expect(log).toBeDefined();
});

it('exposes the log instance', () => {
const oldLog = log;
const newLog = new Log();

setLog(newLog);
expect(log).toBe(newLog);

setLog(oldLog);
expect(log).toBe(oldLog);
});

it('can accept settings', () => {
const log: Log = new Log({
shouldWriteLogLevel: true,
Expand Down

0 comments on commit ae30304

Please sign in to comment.