Skip to content

Commit

Permalink
first stable release!
Browse files Browse the repository at this point in the history
  • Loading branch information
kccarbone committed Jan 17, 2023
1 parent 7fca125 commit 135950f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "bark-logger",
"version": "0.0.5",
"version": "1.0.0",
"description": "Simple log framework for browser and server",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"start": "tsc -w",
"test": "tsc && jest build/tests/*",
"build": "tsc",
"clean": "rm -rf build/ out/"
"local": "tsc -w",
"test": "tsc && jest build/tests/*",
"clean": "rm -rf build/ out/",
"link": "tsc && mkdir -p out/lib && cp package.json out/ && cp -r build/src/* out/lib/ && cd out/ && npm link",
"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/"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const printToConsole: LogAction = (timestamp: Date, level: Levels, name: string,
const timeString = `${two(timestamp.getHours())}:${two(timestamp.getMinutes())}:${two(timestamp.getSeconds())}`;

console.log(''
+ style(`[${timeString}] `, (color.accent ?? 37).toString())
+ style(`[${timeString}] `, (color.accent ?? 39).toString())
+ style(`${color.label}`, color.fg.toString(), color.bg.toString())
+ style((name ? ` (${name}) ` : ' '), (color.accent ?? 90).toString())
+ style(`${message}`, '39', '49')
Expand Down
14 changes: 10 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Levels from './levels';
import actions from './actions';

const globalContext = globalThis as any;
const globalKey = 'BARK_LOGGER_CONFIG';
const env = process?.env ?? {};
const env = (typeof process === 'object') ? process.env ?? {} : {};

class Config {
threshold = env.LOGLEVEL ?? Levels.INFO;
Expand All @@ -12,8 +13,13 @@ class Config {
// Create a singleton instance of config object so that
// settings can be shared (and controlled) across all
// instances, even between different modules
if (typeof (global as any)[globalKey] === 'undefined') {
(global as any)[globalKey] = new Config();
if (typeof globalContext[globalKey] === 'undefined') {
Object.defineProperty(globalContext, globalKey, {
value: new Config(),
enumerable: false,
configurable: false,
writable: false
});
}

export default (global as any)[globalKey] as Config;
export default globalContext[globalKey] as Config;
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import config from './config';

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

class Logger {
export class Logger {
readonly _name: string;

constructor(name: string) {
this._name = name ?? '';
constructor(name = 'main') {
this._name = name;
}

trace = (msg: string) => this.log(msg, Levels.TRACE);
Expand Down
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { jest, describe, expect, test } from '@jest/globals';

// Import library
import { getLogger, Levels, config } from '../src/index';
import { Logger, Levels, getLogger, config } from '../src/index';

// Create logger
const logger = getLogger();
const logger = new Logger();

// Configure mocks
const mockAction = jest.fn().mockName('mockAction');
Expand Down

0 comments on commit 135950f

Please sign in to comment.