You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All the details could be found here - [Winston Transport for Stackify](https://github.com/stackify/stackify-log-winston)
45
+
46
+
#### Using direct logger
47
+
48
+
If you are not using Winston logger you can use default Stackify logger. It has 5 levels of messages: trace, debug, info, warn and error. To send the message to Stackify API you should run one of the following methods in any place of your code where you want to track some information:
49
+
```js
50
+
stackify.log(level, message, meta)
51
+
stackify.trace(message, meta)
52
+
stackify.debug(message, meta)
53
+
stackify.info(message, meta)
54
+
stackify.warn(message, meta)
55
+
stackify.error(message, meta)
56
+
```
57
+
The timestamp will be added to every message by default.
58
+
59
+
Meta parameter should be a valid JSON object.
60
+
61
+
Examples of usage:
62
+
```js
63
+
// Add the module to all the script files where you want to log any messages.
64
+
var stackify =require('stackify-logger');
65
+
66
+
stackify.log('info', 'hey!');
67
+
stackify.debug('any message');
68
+
stackify.info('any message', {anything:'this is metadata'});
69
+
stackify.warn('attention');
70
+
stackify.log('error', {error :newError()});
71
+
```
72
+
When logging an error message you could pass an Error object in metadata like in the last case so the exception details would be available.
73
+
74
+
#### Exception handling
75
+
Supported frameworks
76
+
Express (ver 4.x) and all express-based frameworks only (e.g. SailsJS, Connect, LocomotiveJS) will be supported. This means all of the frameworks that support the format of the middleware functions used in Express.JS.
77
+
function (req, res, next) {
78
+
//some code
79
+
next();
80
+
}
81
+
82
+
Using with pure NodeJS app
83
+
If you are not using any of the frameworks and all requests are handled inside native createServer method you should run stackify.stats() first line inside of this method :
84
+
85
+
var http = require('http')
86
+
var stackify = require('stackify-logger')
87
+
http.createServer(function (req, res) {
88
+
stackify.stats(req, res);
89
+
res.setHeader('content-type', 'text/plain')
90
+
res.end('hello')
91
+
})
92
+
})
93
+
You can use it also with any framework that doesn’t modify native createServer method.
94
+
95
+
96
+
Using with express
97
+
It acts as middleware when running on express-based apps. A middleware is a function which has access to request object (req) and response object (res), and the next middleware in line in the request-response cycle of an Express application (next). Each middleware can execute any code, make changes to request and response object, finish request-response cycle, and call the next middleware in the stack. Since middleware are execute serially, their order of inclusion is important.
98
+
99
+
You can activate it with the app.use() command in the appropriate place of your code, e.g.:
100
+
var express = require('express');
101
+
var app = express();
102
+
app.use(stackify.stats);
15
103
104
+
To handle exceptions correctly put this right after all route handlers and before all the other app.use() commands.
16
105
17
-
Note: *We are dependent on the Guava project from Google. We require version 15.0 (or beyond) for the background thread that sends data back to Stackify.*
106
+
To use it with the frameworks that have a wrapper around app.use() method or have different ways to use middleware plugins you should check the exact way of using middleware in it. For example, to add stackify.stats in SailsJS you should do this
18
107
19
108
## License
20
109
@@ -30,4 +119,4 @@ Unless required by applicable law or agreed to in writing, software
30
119
distributed under the License is distributed on an "AS IS" BASIS,
31
120
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
121
See the License for the specific language governing permissions and
0 commit comments