prod-log
v0.5.4
Published
safe log in product environment
Downloads
68
Readme
prod-log
中文 | English
Console output for production environments.
[!WARNING] In principle, it is recommended to remove logs directly during the compilation process.
Project Background
There is a need for conditional output in the console of production environments, solely for development assistance in troubleshooting.
By default, logs are not output; only under certain conditions are some logs output.
Installation
pnpm add prod-logSystem Features
- Log Classification: Console messages are categorized with different prefixes to distinguish log sources;
- Conditional Output: In production environments, output is conditional, defaulting to no output;
- Remove Native: In production environments, prevents native
consolelog output; - Native Types: Corresponds to
console's original classifications:log,warn, anderror; - Stack Information: All logs include call stack information;
Initialization
createPl({
productEnv: import.meta.env.PROD,
productLog: () => false,
logIcon: true
})Configuration Description
| Parameter | Description | Type | Default Value | |------------|---------------------------------|----------|---------------------------------------------------------------------| | productEnv | Whether it is a production environment | boolean | false | | productLog | Whether to output logs in production environment | function | () => new URL(location.href).searchParams.get("debug") === "true" | | logIcon | Whether to output log icons | boolean | true |
Examples
- Development environment log:
Pl.dev('dev') - Production environment log:
Pl.prod('prod',obj) - User behavior:
Pl.user('Select list',obj) - System output:
Pl.sys('Login successful',{obj}) - API response:
Pl.res('API return',{obj}) - System version:
Pl.version('System version','0.0.1')

Syntax
Pl.user(info, obj, logLevel)
Parameter Description
| Parameter | Description | Type | |-----------|------------------------------------------|----------| | info | Log title | string | | obj | Message object to be output | object | | logLevel | Log level ('info','warn','error') | boolean |
Log Level LogLevel
- Normal:
Pl.res('Normal log') - Warning:
Pl.res('404',{data},'warn') - Error:
Pl.res('Network exception',{data},'error')

Log Stack
Each log output will carry call stack information

Log Output Conditions
- In the development environment, all categories and levels of logs are output.
- Logs with log levels (
LogLevel) ofwarnanderrorare output in all environments. devtype logs are only output in the development environment.prodtype logs are output in any environment.versiontype logs are output in any environment.usertype logs, in the production environment, are not output by default. They are only output when the URL carriesdebug=true.restype logs, in the production environment, are not output by default. They are only output when the URL carriesdebug=true.systype logs, in the production environment, are not output by default. They are only output when the URL carriesdebug=prod.
