With logging already integrated inside Egg, there is no need to import any packages

When we first ran the project

The project directory will be logs and run

So what are these two directories for

The run directory is a run-time configuration that is automatically added by the Egg while it is running and does not need to be modified

Focus on the logs directory

The logs directory contains a directory with the same name as our project, which contains many. Log files for logging

By default it has been logged for us and we don’t need to do any configuration

So what do these files do

Details: eggjs.org/zh-cn/core/…

So let’s do a little bit of logging

Make a simple GET request

module.exports = (app) => {
  const { router, controller } = app;
  router.get("/test", controller.home.test);
};
Copy the code
const Controller = require("egg").Controller; Class HomeController extends Controller {async test() {this.ctx.logger.debug(" I am a debug log "); This.ctx.logger. info(" I am info log "); This.ctx.logger. warn(" I am a warn log "); This.ctx.logger. error(" I am error log "); } } module.exports = HomeController;Copy the code

rendering

However, we did not find that our debug log was not output

Why is that?

Because the official documentation states that only INFO and above logs (WARN and ERROR) will be output to the file by default.

If we want to enter debug logs we need to do some configuration in the configuration file (see documentation for details)

exports.keys = "sandy";
exports.logger = {
  keys: "sandy",
  level: 'DEBUG',
};
Copy the code

So once you’ve configured it, let’s refresh it and see if it works

After the successful output, is there no problem

So how do you do log cutting?

This is easy. Look at the official documentation, which explains how to cut in detail. Right