Socket
Socket
Sign inDemoInstall

@stencila/logga

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencila/logga - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [1.2.1](https://github.com/stencila/logga/compare/v1.2.0...v1.2.1) (2019-07-03)
### Bug Fixes
* **Handlers:** Only add default handler if no other ([a462fc5](https://github.com/stencila/logga/commit/a462fc5))
# [1.2.0](https://github.com/stencila/logga/compare/v1.1.2...v1.2.0) (2019-07-02)

@@ -2,0 +9,0 @@

2

dist/index.d.ts

@@ -39,3 +39,3 @@ export declare enum LogLevel {

*/
export declare function removeAllHandlers(): void;
export declare function removeHandlers(): void;
/**

@@ -42,0 +42,0 @@ * Replace all existing handlers with a new handler.

@@ -79,6 +79,6 @@ "use strict";

*/
function removeAllHandlers() {
function removeHandlers() {
process.removeAllListeners(LOG_EVENT_NAME);
}
exports.removeAllHandlers = removeAllHandlers;
exports.removeHandlers = removeHandlers;
/**

@@ -92,3 +92,3 @@ * Replace all existing handlers with a new handler.

function replaceHandlers(handler) {
removeAllHandlers();
removeHandlers();
addHandler(handler);

@@ -137,4 +137,6 @@ }

exports.defaultHandler = defaultHandler;
// Always enable the default handler
addHandler(defaultHandler);
// Enable the default handler if there no other handler
// already enabled e.g. by another package using `logga`
if (!process.listenerCount(LOG_EVENT_NAME))
addHandler(defaultHandler);
/**

@@ -141,0 +143,0 @@ * Get a logger for the specific application or package.

{
"name": "@stencila/logga",
"version": "1.2.0",
"version": "1.2.1",
"description": "Unified logging across related Javascript modules",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -13,6 +13,4 @@ # Logga

We wanted to have a unified, consistent mechanism for emitting log event data across Javascript/Typescript projects. We wanted to decouple log event emission from log event consumption. We wanted something lightweight.
We wanted to have a unified, consistent mechanism for emitting log event data across libraries. We wanted to decouple log event emission from log event consumption. We didn't want to have to pass `log` objects around everywhere. We wanted type safety. We wanted something lightweight.
For example, `encoda` and `dockta` are two Typescript projects that use `logga`. We want users of these projects to be able to use them as standalone tools and have log events printed at the command line. Both projects are also integrated into the `stencila` command line tool, and in the future, we'll also combine them into the `stencila` desktop Electron-based application. For each of these apps, we want to handle log events from both packages in a consistent way and display them in a way that is appropriate for the platform e.g. HTML messages when in Electron, log files when running as a server.
## Approach

@@ -67,2 +65,34 @@

You can register a new handler by calling `addHandler` with a handling function. Or use `replaceHandlers` to replace any existing log handlers (including the default).
You can register a new handler by calling `addHandler` with a handling function. Or use `replaceHandlers` to replace any existing log handlers (including the default). If you don't want any log handling at all, remove the default handler using `removeHandlers`.
Logga can be used with a log handling library e.g. Winston, Pino.
```javascript
// In library, create a named logger
const logger = getLogger('encoda')
```
```javascript
// Handle the log messages in application code
addHandler((data: LogData) => {
// Send off to log output function
winstonLogger.log(LogLevel[data.level], data.message);
// or filter on tag
if (data.tag === 'encoda') {
// do something different
}
})
```
## See also
See this [issue in `node-bunyan`](https://github.com/trentm/node-bunyan/issues/116) describing the use case for, and approaches to, a global, shared logger in Node.
> I guess this is similar to the idea in log4j (likewise clones like log4js, Python's logging module, etc.) where logger objects are global to the process such that, e.g., log = logging.getLogger("foo") used in two separate modules gets the same logger.
[`bole`](https://www.npmjs.com/package/bole) has the same goals as `logga` (but uses a singleton object instead of events)
> `bole` is designed for global singleton use. Your application has many log sources, but they all aggregate to the same sources. You configure output in one place for an application, regardless of how many modules and dependencies are also using `bole` for logging.
[`encoda`](https://github.com/stencila/encoda) and [`dockta`](https://github.com/stencila/dockta) are two Typescript projects that use `logga`. We want users of these projects to be able to use them as standalone tools and have log events printed at the command line. Both projects are also integrated into the `stencila` command line tool, and in the future, we'll also combine them into the `stencila` desktop Electron-based application. For each of these apps, we want to handle log events from both packages in a consistent way and display them in a way that is appropriate for the platform e.g. HTML messages when in Electron, log files when running as a server.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc