npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-logger-fc

v0.2.0

Published

Ship Egg.js logs to Alibaba Cloud SLS via FC stdout (JSON, with RequestId).

Downloads

356

Readme

egg-logger-fc

Ship Egg.js logs to Alibaba Cloud SLS via Function Compute stdout — JSON lines with the FC RequestId attached.

Why

FC 3.0 automatically collects everything an instance writes to stdout / stderr into the bound SLS Logstore (official doc). egg-logger's default behavior writes to local files under /tmp/log, which vanish when the FC instance is destroyed — SLS never sees them.

This plugin:

  1. Disables egg-logger's file / jsonFile transports on every logger.
  2. Replaces the console transport with a JSON one that writes to stdout (info / warn / debug) and stderr (error).
  3. Attaches the FC x-fc-request-id header plus standard ctx fields (method, url, ip, userId, useMs) to every request-scoped log line, so each field becomes individually queryable in SLS.
  4. Tags every line with the source logger's name (logger: "coreLogger" | "errorLogger" | "logger" | "<customLoggerName>"), so SLS queries can still split what used to live in egg-web.log / common-error.log / <app>-web.log / custom log files.

Install

npm i egg-logger-fc

Enable

// config/plugin.js
exports.loggerFC = {
  enable: true,
  package: 'egg-logger-fc',
};

With zero config, business logs land in SLS as:

{"time":"2026-04-17T07:00:26.518Z","level":"INFO","pid":12,"hostname":"fc-xxx","msg":"[auth] login ok","logger":"logger","requestId":"1-abcdef","method":"POST","url":"/api/auth/session","ip":"10.0.0.1","userId":42,"useMs":34}

To slice what used to be separate log files, filter on logger:

  • logger: logger — business logs (was <app>-web.log)
  • logger: coreLogger — Egg framework core logs (was egg-web.log)
  • logger: errorLogger — centralized errors (was common-error.log)
  • logger: <name> — any config.customLogger[name] you declared

Configure

// config/config.default.js
exports.loggerFC = {
  // Default: 'x-fc-request-id' (FC 3.0 convention)
  requestIdHeader: 'x-fc-request-id',

  // Optional: merge extra fields into every request-scoped log line.
  // Must return a plain object. Thrown errors are swallowed so that a
  // broken config never breaks request handling.
  extraFields: ctx => ({
    traceId: ctx.get('x-trace-id'),
    tenantId: ctx.state.tenantId,
  }),
};

Log level

Set ALIYUN_FC_LOG_LEVEL (FC's standard env var) to debug / info / warn / error. The plugin maps it to the console transport's level on every logger.

Advanced: using the transport directly

If you want the transport without the auto-configuration (e.g. to attach it to a custom logger), import it:

const { JsonStdoutTransport } = require('egg-logger-fc');

app.getLogger('auditLogger').set('console', new JsonStdoutTransport({
  name: 'auditLogger', // becomes the `logger` field in every emitted JSON line
  level: 'INFO',
  localStorage: app.ctxStorage,
  requestIdHeader: 'x-fc-request-id',
  extraFields: ctx => ({ userId: ctx.state.user?.id }),
}));

License

MIT