Observability Glossary

Logging Levels

Linkedin icon
Reddit icon

Logging levels are a way to categorize log messages based on their severity or importance. They enable developers to control which messages are written to the log file or the log management solution, making it easier to filter and manage log output. The most common logging levels are DEBUG, INFO, WARN, ERROR, and FATAL, each representing a different level of severity.

For example, a DEBUG message might be used for detailed information that is only needed for debugging purposes, while an ERROR message indicates a critical issue that requires immediate attention. By setting the logging level, developers can choose which types of messages they want to see, making it easier to focus on the most relevant information.

In JavaScript, logging levels are often implemented using a logging library such as Winston. Here's an example of how logging levels can be used in Winston:

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'your-service-name' },
  transports: [
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' })
  ]
});

logger.error('This is an error message');
logger.warn('This is a warning message');
logger.info('This is an info message');
logger.debug('This is a debug message');
Explore related concepts
Start resolving issues today.
Without the hassle.