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 🙏

© 2024 – Pkg Stats / Ryan Hefner

c4logger

v0.0.1

Published

C4Framework Logger

Downloads

4

Readme

C4Logger基于winston进行封装,提供日志的多目的输出,即同一日志信息可以同时输出到文件、控制台和ELK(redis)。

支持日志的颜色显示,对象输出和profile的帮助方法,并且可以在运行时修改当前的日志级别。

日志默认支持fatal、err、warn、info、debug、trace六个日志级别,对应red、red、yellow、green、blue、magenta的颜色(在./src/C4LogLevels.ts中进行配置)。

使用C4Logger.yml进行配置,配置文件属性详见配置文件注释。配置文件需要配合C4Configger或其他加载配置文件的方法进行配置。在C4Framework中使用Helper进行初始化。

在C4Logger对象构造完毕后,可以根据需要添加对应的Logger的配置。参考./src/main.ts。

  • C4Logger

    • 说明:C4 Logger对象

    • 路径:./src/C4Logger.ts

    • 成员变量:

      • m_Logger,Winston的Logger实例;
      • m_Transports,日志写入目标的配置的存储字典,key为logger的名字,value为C4LogTransportInstance。
    • 成员方法:

      • init
      /**
      * 初始化Logger
      * @param LogConfig Logger配置
      */
      async init(LogConfig : C4LoggerOptions.C4LoggerConfig)
      • addTransport
      /**
      * 添加Logger配置
      * @param LogConfig logger配置
      */
      async addTransport(LogConfig : C4LoggerOptions.C4LoggerOptions)
      • removeTransport
      /**
      * 移除Logger配置
      * @param LoggerName logger名
      */
      async removeTransport(LoggerName : string)
      • changeLevel
      /**
      * 改变日志级别
      * @param Level 级别
      * @param LoggerName logger名
      */
      changeLevel(Level : C4LogLevel.C4LogLevel) : void;
      changeLevel(Level : C4LogLevel.C4LogLevel, LoggerName?: string) : void 
      • close
      /**
      * 关闭Logger
      * @param LoggerName logger名
      */
      async close(LoggerName ?: string)
      • fatal
      • err
      • warn
      • info
      • debug
      • trace
      fatal(msg : any, ...meta : any[]) : C4Logger 
      err(msg : any, ...meta : any[]) : C4Logger 
      warn(msg : any, ...meta : any[]) : C4Logger 
      info(msg : any, ...meta : any[]) : C4Logger 
      debug(msg : any, ...meta : any[]) : C4Logger 
      trace(msg : any, ...meta : any[]) : C4Logger 
      • profile
      /**
      * 进行性能统计
      * @param id 标识
      * @param meta meta信息
      */
      profile(id : string, ...meta : any[]) : C4Logger
  • C4LogTransportInstance

    • 说明:Log Transport的接口类

    • 路径:./src/C4LogTransportInstance.ts

    • 成员变量:无

    • 成员方法:

      • init
      • changeLevel
      • close
      • getName
      • getTransport
      // 初始化
      init(LogConfig : C4LoggerOptions.C4LoggerOptions) : void;
      
      // 改变日志等级
      changeLevel(Level : C4LogLevel.C4LogLevel) : void;
      
      // 关闭Logger
      close() : void;
      
      // 获取Logger名字
      getName() : string;
      
      // 获取Transport实例
      getTransport() : Winston.TransportInstance | null;
      • 其他Transport需要继承并实现这些方法
  • C4Log2ConsoleTransport

    • 说明:写入控制台的Logger,继承自C4LogTransportInstance

    • 路径:./src/C4Log2ConsoleTransport

    • 成员变量:

      • m_transport,Winston的TransportInstance对象;
    • 成员方法:与C4LogTransportInstance相同

  • C4Log2FilesTransport

    • 说明:写入文件的Logger,继承自C4LogTransportInstance

    • 路径:./src/C4Log2FilesTransport

    • 成员变量:

      • m_transport,Winston的TransportInstance对象;
      • m_CurDate,日期字符串,用来按日期来切分日志文件;
      • m_CurDateCount,相同日期文件的计数,用来按日期来切分日志文件;
    • 成员方法:与C4LogTransportInstance相同

  • C4Log2RedisTransport

    • 说明:写入Redis的Logger(用于ELK写入),继承自C4LogTransportInstance

    • 路径:./src/C4Log2RedisTransport

    • 成员变量:

      • m_transport,Winston的TransportInstance对象;
      • m_RClient,redis客户端;
    • 成员方法:与C4LogTransportInstance相同