Skip to content

Commit 135950f

Browse files
committed
first stable release!
1 parent 7fca125 commit 135950f

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "bark-logger",
3-
"version": "0.0.5",
3+
"version": "1.0.0",
44
"description": "Simple log framework for browser and server",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"scripts": {
8-
"start": "tsc -w",
9-
"test": "tsc && jest build/tests/*",
108
"build": "tsc",
11-
"clean": "rm -rf build/ out/"
9+
"local": "tsc -w",
10+
"test": "tsc && jest build/tests/*",
11+
"clean": "rm -rf build/ out/",
12+
"link": "tsc && mkdir -p out/lib && cp package.json out/ && cp -r build/src/* out/lib/ && cd out/ && npm link",
13+
"prerelease": "rm -rf build/ out/ && tsc && mkdir -p out/lib && cp package.json out/ && cp LICENSE out/ && cp -r build/src/* out/lib/ && npm publish --tag next out/"
1214
},
1315
"repository": {
1416
"type": "git",

src/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const printToConsole: LogAction = (timestamp: Date, level: Levels, name: string,
1818
const timeString = `${two(timestamp.getHours())}:${two(timestamp.getMinutes())}:${two(timestamp.getSeconds())}`;
1919

2020
console.log(''
21-
+ style(`[${timeString}] `, (color.accent ?? 37).toString())
21+
+ style(`[${timeString}] `, (color.accent ?? 39).toString())
2222
+ style(`${color.label}`, color.fg.toString(), color.bg.toString())
2323
+ style((name ? ` (${name}) ` : ' '), (color.accent ?? 90).toString())
2424
+ style(`${message}`, '39', '49')

src/config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Levels from './levels';
22
import actions from './actions';
33

4+
const globalContext = globalThis as any;
45
const globalKey = 'BARK_LOGGER_CONFIG';
5-
const env = process?.env ?? {};
6+
const env = (typeof process === 'object') ? process.env ?? {} : {};
67

78
class Config {
89
threshold = env.LOGLEVEL ?? Levels.INFO;
@@ -12,8 +13,13 @@ class Config {
1213
// Create a singleton instance of config object so that
1314
// settings can be shared (and controlled) across all
1415
// instances, even between different modules
15-
if (typeof (global as any)[globalKey] === 'undefined') {
16-
(global as any)[globalKey] = new Config();
16+
if (typeof globalContext[globalKey] === 'undefined') {
17+
Object.defineProperty(globalContext, globalKey, {
18+
value: new Config(),
19+
enumerable: false,
20+
configurable: false,
21+
writable: false
22+
});
1723
}
1824

19-
export default (global as any)[globalKey] as Config;
25+
export default globalContext[globalKey] as Config;

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import config from './config';
33

44
const loggers: { [name: string]: Logger } = {};
55

6-
class Logger {
6+
export class Logger {
77
readonly _name: string;
88

9-
constructor(name: string) {
10-
this._name = name ?? '';
9+
constructor(name = 'main') {
10+
this._name = name;
1111
}
1212

1313
trace = (msg: string) => this.log(msg, Levels.TRACE);

tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { jest, describe, expect, test } from '@jest/globals';
22

33
// Import library
4-
import { getLogger, Levels, config } from '../src/index';
4+
import { Logger, Levels, getLogger, config } from '../src/index';
55

66
// Create logger
7-
const logger = getLogger();
7+
const logger = new Logger();
88

99
// Configure mocks
1010
const mockAction = jest.fn().mockName('mockAction');

0 commit comments

Comments
 (0)