How to use the http function from npmlog

Find comprehensive JavaScript npmlog.http code examples handpicked from public code repositorys.

npmlog.http is an object in the npmlog library that provides methods to log HTTP-related messages with different log levels.

44
45
46
47
48
49
50
51
52
53
logger(':remote-addr :user [:user-ip/:user-sess] :method :url :status :time-spent :append', {
    stream: {
        write: message => {
            message = (message || '').toString();
            if (message) {
                log.http('ACME', message.replace('\n', '').trim());
            }
        }
    }
})
fork icon245
star icon0
watch icon54

+ 3 other calls in file

262
263
264
265
266
267
268
269
270
271
For example,

* log.silly(prefix, message, ...)
* log.verbose(prefix, message, ...)
* log.info(prefix, message, ...)
* log.http(prefix, message, ...)
* log.warn(prefix, message, ...)
* log.error(prefix, message, ...)

Like `log.log(level, prefix, message, ...)`.  In this way, each level is
fork icon19
star icon22
watch icon13

+ 9 other calls in file

How does npmlog.http work?

npmlog.http is a property of the npmlog module in Node.js that is used to log HTTP request and response information. When npmlog.http is set to true, the npmlog module will output logs related to HTTP requests and responses. This can be useful for debugging and troubleshooting HTTP-related issues in Node.js applications.

52
53
54
55
56
57
58
59
60
61
// Setup logger. Stream all http logs to general logger
app.use(require('morgan')(config.log.http, {
    'stream': {
        'write': function(line) {
            if ((line = (line || '').trim())) {
                log.http('express', line);
            }
        }
    }
}));
fork icon4
star icon24
watch icon3

55
56
57
58
59
60
61
62
63
64
                  process.env.npm_config_proxy;
let agent;
if (proxyUrl) {
  const ProxyAgent = require('https-proxy-agent');
  agent = new ProxyAgent(proxyUrl);
  log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
}

fetch(sanitized, { agent })
  .then((res) => {
fork icon257
star icon0
watch icon115

+ 5 other calls in file

Ai Example

1
2
3
const npmlog = require("npmlog");

npmlog.http("GET", "https://registry.npmjs.org/npm", 200);

This logs an HTTP GET request to the https://registry.npmjs.org/npm URL with a status code of 200. The output will look something like this: vbnet Copy code

13
14
15
16
17
18
19
20
21
22
// returns a Promise of the signed url
const get_signed_target_url = url_signer('DELETE', log);

function del(url) {
    const time1 = new Date();
    log.http("DELETE", url);
    const req = request.del({uri: url});
    req.on('response', function (res) {
        if (res.statusCode >= 200 && res.statusCode < 300) {
            const time2 = new Date();
fork icon2
star icon0
watch icon5

+ 5 other calls in file

77
78
79
80
81
82
83
84
85
86
    } catch (e) {
        return callback(e);
    }
    if (req) {
      req.on('response', function (res) {
        log.http(res.statusCode, uri);
      });
    }
    return callback(null,req);
}
fork icon0
star icon0
watch icon0

+ 17 other calls in file

65
66
67
68
69
70
71
72
73
74
    const protocol = m[1] === 'https:' ? 'https:' : 'http:';
    const host = m[2];
    const port = +(m[3] || (protocol === 'https:' ? 443 : 80));
    const agentOpts = { host, port, protocol };
    agent = new ProxyAgent(agentOpts);
    log.http('download', 'proxy agent configured using: "%o"', agentOpts);
  } else {
    log.warn('download', 'ignoring invalid "proxy" config setting: "%s"', proxyUrl);
  }
}
fork icon0
star icon0
watch icon0

+ 17 other calls in file

332
333
334
335
336
337
338
339
340
341
342
343
    callback()
  }
}


async function download (gyp, url) {
  log.http('GET', url)


  const requestOpts = {
    headers: {
      'User-Agent': `node-gyp v${gyp.version} (node ${process.version})`,
fork icon0
star icon0
watch icon1

+ 37 other calls in file