mirror of
https://github.com/zhigang1992/probot.github.io.git
synced 2026-01-12 22:49:53 +08:00
133 lines
4.5 KiB
HTML
133 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>logger.js - Documentation</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"></script>
|
|
<script src="scripts/prettify/lang-css.js"></script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
<body>
|
|
|
|
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
<label for="nav-trigger" class="navicon-button x">
|
|
<div class="navicon"></div>
|
|
</label>
|
|
|
|
<label for="nav-trigger" class="overlay"></label>
|
|
|
|
<nav>
|
|
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Context.html">Context</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#config">config</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#issue">issue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#repo">repo</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Robot.html">Robot</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Robot.html#on">on</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Robot.html#route">route</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li>
|
|
</nav>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">logger.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/**
|
|
* A logger backed by [bunyan](https://github.com/trentm/node-bunyan)
|
|
*
|
|
* The default log level is `info`, but you can change it by setting the
|
|
* `LOG_LEVEL` environment variable to `trace`, `debug`, `info`, `warn`,
|
|
* `error`, or `fatal`.
|
|
*
|
|
* By default, logs are formatted for readability in development. If you intend
|
|
* to drain logs to a logging service, set `LOG_FORMAT=json`.
|
|
*
|
|
* **Note**: All execptions reported with `logger.error` will be forwarded to
|
|
* [sentry](https://github.com/getsentry/sentry) if the `SENTRY_DSN` environment
|
|
* variable is set.
|
|
*
|
|
* @typedef logger
|
|
*
|
|
* @example
|
|
*
|
|
* robot.log("This is an info message");
|
|
* robot.log.debug("…so is this");
|
|
* robot.log.trace("Now we're talking");
|
|
* robot.log.info("I thought you should know…");
|
|
* robot.log.warn("Woah there");
|
|
* robot.log.error("ETOOMANYLOGS");
|
|
* robot.log.fatal("Goodbye, cruel world!");
|
|
*/
|
|
|
|
const Logger = require('bunyan')
|
|
const bunyanFormat = require('bunyan-format')
|
|
const serializers = require('./serializers')
|
|
|
|
// Return a function that defaults to "info" level, and has properties for
|
|
// other levels:
|
|
//
|
|
// robot.log("info")
|
|
// robot.log.trace("verbose details");
|
|
//
|
|
Logger.prototype.wrap = function () {
|
|
const fn = this.info.bind(this);
|
|
|
|
// Add level methods on the logger
|
|
['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(level => {
|
|
fn[level] = this[level].bind(this)
|
|
})
|
|
|
|
// Expose `child` method for creating new wrapped loggers
|
|
fn.child = (attrs) => {
|
|
// Bunyan doesn't allow you to overwrite name…
|
|
const name = attrs.name
|
|
delete attrs.name
|
|
const log = this.child(attrs, true)
|
|
|
|
// …Sorry, bunyan, doing it anwyway
|
|
if (name) log.fields.name = name
|
|
|
|
return log.wrap()
|
|
}
|
|
|
|
// Expose target logger
|
|
fn.target = logger
|
|
|
|
return fn
|
|
}
|
|
|
|
const logger = new Logger({
|
|
name: 'probot',
|
|
level: process.env.LOG_LEVEL || 'info',
|
|
stream: bunyanFormat({outputMode: process.env.LOG_FORMAT || 'short'}),
|
|
serializers
|
|
})
|
|
|
|
module.exports = logger
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jun 07 2018 22:02:51 GMT-0400 (EDT) using the Minami theme.
|
|
</footer>
|
|
|
|
<script>prettyPrint();</script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
</body>
|
|
</html>
|