Skip to content

seasonjs/log

Repository files navigation

@seasonjs/log

Js log library which copy from vscode

Version License

quick start

install

npm

npm i @seasonjs/log

yarn

yarn add @seasonjs/log

pnpm

pnpm add @seasonjs/log

special notice

import {LoggerService} from '@seasonjs/log/node' this may need package @vscode/spdlog you may need install it and add external key to your builder options

here is an example:

import {defineConfig} from "vite";
// this is vite config,but it also work with rollup, as you know.
export default defineConfig(() => {
    return {
        build: {
            rollupOptions: {
                external: ['@vscode/spdlog']
            },
        },
    }
})

example usage

just console log

import {LogService, ConsoleLogger} from '@seasonjs/log'

const logger = new LogService(new ConsoleLogger(LogLevel.Debug))
logger.info("this is an info")

use with node and write to file

import path from "node:path"
import {LogService, ConsoleLogger, DEFAULT_LOG_LEVEL, URI, BufferLogger} from '@seasonjs/log'
import {LoggerService} from '@seasonjs/log/node'

const uri = URI.file(path.join(__dirname, './.test_data/log'))
const loggerService = new LoggerService(DEFAULT_LOG_LEVEL, uri)
const bufferLogger = new BufferLogger(loggerService.getLogLevel());
// In this case mean you can set anyother logger to bufferLogger, which is implements with ILogger.
bufferLogger.logger = loggerService.createLogger('example')
const logger = new LogService(new ConsoleLogger(loggerService.getLogLevel()), [bufferLogger])
logger.info("this is an info")

Releases

No releases published

Packages

No packages published