Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

loghere

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loghere - npm Package Compare versions

Comparing version
0.0.1
to
1.0.0
+82
lib/logger.js
'use strict'
const Time = require('./time.js')
const LOGGER_LEVEL = [
'ALL',
'TRACE',
'DEBUG',
'INFO',
'WARN',
'ERROR',
'FATAL',
'MARK',
'OFF',
]
const levelIndex = Symbol('Level-Index')
module.exports = class Logger {
constructor() {
// ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < MARK < OFF
this[levelIndex] = 0
}
get level() {
const index = this[levelIndex]
return LOGGER_LEVEL[index]
}
set level(val) {
const index = LOGGER_LEVEL.indexOf(val.toUpperCase())
const SMALLEST_INDEX = 0
if ( index >= SMALLEST_INDEX) {
this[levelIndex] = index
} else {
throw new Error(`日志等级 level 错误,只能设置为以下值:${LOGGER_LEVEL.toString()}`)
}
}
static getTime() {
const now = new Time()
return now.getFormattedTime()
}
isActive(currentLevel) {
const currentIndex = LOGGER_LEVEL.indexOf(currentLevel)
if (currentIndex >= this[levelIndex]) {
return true
}
return false
}
debug(content) {
const currentLevel = 'DEBUG'
if (this.isActive(currentLevel)) {
console.debug(`[${Logger.getTime()}] [${currentLevel}] ${content}`)
}
}
info(content) {
const currentLevel = 'INFO'
if (this.isActive(currentLevel)) {
console.info(`[${Logger.getTime()}] [${currentLevel}] ${content}`)
}
}
warn(content) {
const currentLevel = 'WARN'
if (this.isActive(currentLevel)) {
console.warn(`[${Logger.getTime()}] [${currentLevel}] ${content}`)
}
}
error(content) {
const currentLevel = 'ERROR'
if (this.isActive(currentLevel)) {
console.error(`[${Logger.getTime()}] [${currentLevel}] ${content}`)
}
}
}
'use strict'
const Logger = require('./logger.js')
module.exports.getLogger = function getLogger() {
const logger = new Logger()
return logger
}
'use strict'
/**
* 将 0 至 9 的数字前补零,输出为字符串,例如 00,01,...,09
* @param {number} n
*/
function zerofill(n) {
if (typeof n !== 'number') {
throw new Error('参数 n 应该是一个数字')
}
const SMALLEST_SINGLE_DIGIT = 0
const LARGEST_SINGLE_DIGIT = 9
if (n >= SMALLEST_SINGLE_DIGIT && n <= LARGEST_SINGLE_DIGIT) {
return `0${n.toString()}`
}
return n.toString()
}
module.exports = class Time extends Date {
constructor() {
super()
}
getFullYear() {
return super.getFullYear().toString()
}
getFullMonth() {
return zerofill(this.getMonth())
}
getFullDay() {
return zerofill(this.getUTCDay())
}
getFullHour() {
return zerofill(this.getHours())
}
getFullMinute() {
return zerofill(this.getMinutes())
}
getFullSecond() {
return zerofill(this.getSeconds())
}
getFormattedTime() {
const formatted = `${this.getFullYear()}-${this.getFullMonth()}-${this.getFullDay()} ${this.getFullHour()}:${this.getFullMinute()}:${this.getFullSecond()}`
return formatted
}
}
+1
-1
'use strict'
module.exports = require('./lib/loghere')
module.exports = require('./lib/loghere.js')
{
"name": "loghere",
"version": "0.0.1",
"description": "PM2 中使用的一款简易日志工具",
"version": "1.0.0",
"description": "可以在 PM2 和 Serverless 中使用的一款简易日志工具",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

# loghere
PM2 中使用的一款简易日志工具
可以在 PM2 和 Serverless 中使用的一款简易日志工具