Skip to content

Commit

Permalink
fix: windows7 os.hostname() throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglolo authored and rvagg committed Aug 11, 2022
1 parent 2c38dcc commit 3b15a2e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bole.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ const _stringify = require('fast-safe-stringify')
const individual = require('individual')('$$bole', { fastTime: false }) // singleton
const format = require('./format')
const levels = 'debug info warn error'.split(' ')
const hostname = require('os').hostname()
const hostnameSt = _stringify(hostname)
const os = require('os')
const pid = process.pid
let hasObjMode = false
const scache = []

// Ref: https://github.com/rvagg/bole/issues/20
let hostname
try {
hostname = os.hostname()
} catch (e) {
hostname = os.version().indexOf('Windows 7 ') === 0 ? 'windows7' : 'hostname-unknown'
}
const hostnameSt = _stringify(hostname)

for (const level of levels) {
// prepare a common part of the stringified output
scache[level] = ',"hostname":' + hostnameSt + ',"pid":' + pid + ',"level":"' + level
Expand Down

0 comments on commit 3b15a2e

Please sign in to comment.