Comments (2)
Hi @baiyuxiong,
There is no way to separate njs logs and nginx error logs as of now.
One way to separate them is to filter the error.log file as
grep '\[info\].*js' error.log
to get NJS logs.
from njs.
When it comes to logging your own logs separately or per server/location, there is a trick to logging.
First you create your own SysLog server with JS, which waits for messages, and you parse them into JSON. You then evaluate this based on an ID, you discard everything else, or you log βBasicβ. You can split everything with an ID (by me "ff_http_id":3) separately into files or into a DB, as you like:
public static readonly SYSLOG_TAG = 'nginx';
......
syslog = new SysLogServer();
....
syslog.setOnMessage((
_sysLogServer,
msg
) => {
const parts = msg.toString().split(`${NginxService.SYSLOG_TAG}: `);
try {
const nginxLog = JSON.parse(parts[1]);
....
In the nginx config you log a log_format:
log_format ff_h_accesslogs_3 escape=json '{"source":"nginx","source_type":"http","logging":"access","ff_http_id":3,"time":"$time_iso8601","host":"$remote_addr","proxy_protocol_addr":"$proxy_protocol_addr","forwardedfor":"$http_x_forwarded_for","req":"$request","method":"$request_method","scheme":"$scheme","uri":"$request_uri","status":"$status","size":"$body_bytes_sent","referer":"$http_referer","ua":"$http_user_agent","reqtime":"$request_time","runtime":"$upstream_http_x_runtime","apptime":"$upstream_response_time","cache":"$upstream_http_x_cache","vhost":"$host"}';
then:
server {
listen 10443 ssl http2 proxy_protocol;
access_log syslog:server=127.0.0.1:514,tag=nginx ff_h_accesslogs_3;
In njs javascript you can now put together such a JSON string and log it:
async function some(s: NginxHTTPRequest) {
s.warn('{"source":"njs", "ff_http_id":3, ......}');
Maybe this approach will help you :)
from njs.
Related Issues (20)
- How to remove or override value of 'Server' header for all locations. HOT 10
- Introducing QuickJS engine as alternative JS engine. HOT 7
- ngx.shared.SharedDict.clear() hangs when called on an empty dict HOT 1
- NJS call wrong function. HOT 7
- Sending a Buffer with r.send() does not work HOT 1
- Repo looks empty
- Test failure with zlib-ng HOT 6
- False Positive Duplicate Checker Warning HOT 3
- njs source code compile error HOT 2
- Port missing in Host header when using ngx.fetch with non-standard port HOT 3
- Add support for a fetch-like API for TCP (and UDP) sockets.
- Add support for statefiles to js_shared_dict_zone.
- r.requestText.replaceAll replaces only first occurence of string HOT 1
- http request from js_body_filter njs script HOT 1
- Segfault at String.prototype.replaceAll HOT 2
- Segfault at Array.prototype.toSpliced HOT 1
- closed request followed by 400 response HOT 1
- heap-use-after-free src/njs_value.h:992:27
- Configuration of unit is incomplete (due to unable to find njs library) HOT 2
- memmove-vec-unaligned-erms
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from njs.