
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
$ npm install --save logepi
$ yarn install logepi
The library is comprised of two major components:
Log
static class which creates an instance of a Winston logger, exposing several methods to output messages with different loglevels.Middleware
functions to add automatic logging of request/response flows for HTTP servers. Currently the library supports Koa and Express.There's also a TypeScript declaration file available for TS-based apps.
Log
API// commonjs style
const { Log } = require("logepi");
// ES modules style
import { Log } from "logepi";
Log.error("An error was found", { tags: { process: "foo" } });
Log.warning("Careful!", { tags: { process: "foo" } });
Log.info("Hopefully someone will read this.", { tags: { process: "foo" } });
Log.verbose("Now I'm all blah-by.", { tags: { process: "foo" } });
Log.debug("I've said too much!", { tags: { process: "foo" } });
In order to filter what messages are printed to the console transport, you can use the Log.setOutputLevel()
method:
// Limit messages to "error" level.
Log.setOutputLevel("error");
You can also use the LogLevel
enum, with uppercased keys (INFO
, WARN
, ERROR
, VERBOSE
, DEBUG
).
// commonjs style
const { KoaLoggingMiddleware } = require("logepi");
// ES modules style
import { KoaLoggingMiddleware } from "logepi";
app
.use(...)
// ...make sure it's the *last* middleware...
.use(KoaLoggingMiddleware());
// commonjs style
const { ExpressLoggingMiddleware } = require("logepi");
// ES modules style
import { ExpressLoggingMiddleware } from "logepi";
app
.use(...)
// ...make sure it's the *last* middleware...
.use(ExpressLoggingMiddleware());
Logepi offers a way to inject tagged data in a logline, with the format [key:value]
. When logging, use the tags
key on the data
argument of any of the Log API methods. There's an example right in the next section.
All middlewares expose the same configuration object:
/**
* Allows to configure log levels for requests and responses.
*/
logLevels: {
/**
* Sets the log level for all incoming requests.
*/
request: "info",
/**
* Sets the log level for all outgoing responses, according to their status code.
*/
response: {
status2xx: "info", // For 200-399 codes
status4xx: "warn", // For 400-499 codes
status5xx: "error" // For 500-599 codes
}
}
Note: Logs are single-lined, but for clarity's sake, they're shown in multiple lines.
Log.info("API is now ready", { tags: { port } });
outputs:
[timestamp:2019-01-11T21:04:41.915Z]
[level:info]
[message:API is now ready]
[port:9000]
[timestamp:2019-01-11T21:00:45.442Z]
[level:info]
[message:IncomingRequest]
[url:/api/apps]
[queryParams:undefined]
[body:{}]
[headers:{"host":"localhost:9000","connection":"keep-alive","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","accept-encoding":"gzip, deflate, br","accept-language":"es-ES,es;q=0.9,en;q=0.8,en-US;q=0.7"}]
[timestamp:2019-01-11T21:00:45.446Z]
[level:info]
[message:OutgoingResponse]
[status:200]
[body:{"ok":true,"data":{"foo":true}}]
[headers:{"host":"localhost:9000","connection":"keep-alive","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","accept-encoding":"gzip, deflate, br","accept-language":"es-ES,es;q=0.9,en;q=0.8,en-US;q=0.7"}]
Feel free to report any issues and we'll figure out a way to make it work.
That's great! Open an issue first and let's discuss what you want to add or, by all means, fork this project! :)
This project is licensed under the MIT License.
FAQs
A tiny (Togepi-sized) package for logs, built on top of Winston.
We found that logepi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.