@willers/logger
v1.0.1
Published
Encapsulates logging with the winston lib
Downloads
2
Readme
logger
Auxilia a criação de arquivos de logs utilizando a biblioteca winston
a partir de definições em variáveis de ambiente do Node.
Instalação
npm install @willers/logger
Stack utilizada
dotenv
^16.3.1winston
^3.9.0winston-daily-rotate-file
^4.7.1
Árvore de arquivos
├── src
│ └── logger.js
├── test
│ └── loggers.test.js
├── .env
├── .eslintrc.cjs
├── .gitignore
├── package-lock.json
├── package.json
└── README.md
Configuração das variáveis de ambiente
No arquivo .env deve ser definido na propriedade LOGGER_NAMES
os nomes dos logs que devem ser criados. Em resumo, para cada nome sera criado um tipo de Transports da biblioteca winston.
A partir desses nomes definidos o pw-logger irá procurar pelas variáveis que definirão o tipo de Transport que deve ser gerado. Atualmente é suportado os tipos Console e DailyRotateFile.
Para DailyRotateFile é possivel as seguintes propriedades levando em conta que o nome definido em LOGGER_NAMES é ERROR:
LOGGER_ERROR_TYPE
: Define o tipo do Transports a ser criado, nesse caso é um _DailyRotateFile;LOGGER_ERROR_DATE_PATTERN
: Padrão de data que ser utilizado para geração no nome do arquivo;LOGGER_ERROR_MAX_SIZE
: Tamanho máximo permitido para cada arquivo de log;LOGGER_ERROR_LEVEL
: Nível de log, podendo ser (error, warn, info, debug);LOGGER_ERROR_FILENAME
: Nome do arquivo a ser gerado contendo o seu caminho.
Na pasta test há um teste exemplificando como utilizar o logger em conjunto com o arquivo .env
Uso
Com as variáveis de ambiente definidas, tome como exemplo o código abaixo para criação e uso de uma instância de log:
import Logger from '@willers/logger'
const logger = Logger.create(import.meta.url);
logger.error('Teste de erro');
logger.info('Teste de informação');
Documentação
Esta bibliteca retorna uma instância Logger do projeto winston
, para mais detalhes sobre a documentação, consultar a documentação oficial do winston