Skip to content

Commit a062166

Browse files
committed
feat: Первый релиз
1 parent f99d4cd commit a062166

File tree

10 files changed

+1939
-8
lines changed

10 files changed

+1939
-8
lines changed

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish
2+
3+
on:
4+
release
5+
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v3
12+
13+
- name: Setup Node
14+
uses: actions/setup-node@v3
15+
16+
- name: Publish
17+
run: npm publish
18+
env:
19+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Release please
13+
id: release
14+
uses: google-github-actions/release-please-action@v3
15+
with:
16+
release-type: node
17+
package-name: yc-logging-stream

.gitignore

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,130 @@
1-
/example
2-
/node_modules
3-
/package-lock.json
4-
/pino.js
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*

example/options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
auth: {
3+
oauthToken: ''
4+
},
5+
destination: {
6+
logGroupId: ''
7+
}
8+
}

example/pino.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const pino = require('pino')
2+
3+
const options = require('./options.js')
4+
5+
const transport = pino.transport({
6+
targets: [{
7+
target: 'pino/file',
8+
options: {
9+
destination: 'example.log'
10+
}
11+
},{
12+
target: '../pino',
13+
options
14+
}]
15+
})
16+
17+
const logger = pino(transport)
18+
19+
const run = async function () {
20+
for (let i = 0; i < 3; i++) {
21+
logger.trace(`Example ${i} trace message`)
22+
logger.debug(`Example ${i} debug message`)
23+
logger.info(`Example ${i} info message`)
24+
logger.warn(`Example ${i} warn message`)
25+
logger.error(`Example ${i} error message`)
26+
logger.fatal(`Example ${i} fatal message`)
27+
}
28+
29+
await new Promise(resolve => setTimeout(resolve, 5000))
30+
}
31+
32+
run()

example/stream.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const loggingStream = require('../index.js')
2+
3+
const options = require('./options.js')
4+
5+
const stream = loggingStream.createWriteStream(options)
6+
7+
const run = async function () {
8+
for (let i = 0; i < 10; i++) {
9+
console.log('message #' + i)
10+
stream.write({
11+
timestamp: new Date(),
12+
level: loggingStream.logLevels.INFO,
13+
message: 'Example message #' + i,
14+
jsonPayload: {
15+
foo: 'bar',
16+
i
17+
}
18+
})
19+
}
20+
21+
await new Promise(resolve => setTimeout(resolve, 5000))
22+
}
23+
24+
run()

index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,43 @@ const {
77
},
88
cloudApi: {
99
logging: {
10-
log_ingestion_service: { WriteRequest }
10+
log_ingestion_service: { WriteRequest },
11+
log_entry: {
12+
LogLevel_Level: logLevels
13+
}
1114
}
1215
}
1316
} = require('@yandex-cloud/nodejs-sdk')
1417

1518
const createWriteStream = function (options) {
16-
const session = new Session({ oauthToken: options.oauthToken })
19+
// Init client and session
20+
// https://github.com/yandex-cloud/nodejs-sdk#getting-started
21+
const session = new Session(options.auth)
22+
1723
const client = session.client(LogIngestionServiceClient)
1824

25+
// https://cloud.yandex.ru/docs/logging/api-ref/grpc/log_ingestion_service#Destination
26+
const destination = {}
27+
if (options.destination.logGroupId) {
28+
destination.logGroupId = options.destination.logGroupId
29+
} else if (options.destination.folderId) {
30+
destination.folderId = options.destination.folderId
31+
}
32+
1933
const write = async function (entries) {
34+
// https://cloud.yandex.ru/docs/logging/api-ref/grpc/log_ingestion_service#WriteRequest
2035
await client.write(WriteRequest.fromPartial({
21-
destination: options.destination,
36+
destination,
2237
entries: entries instanceof Array ? entries : [entries]
2338
}))
2439
}
2540

2641
return new Writable({
2742
objectMode: true,
43+
// https://cloud.yandex.ru/docs/logging/api-ref/grpc/log_ingestion_service
44+
// IncomingLogEntry:
45+
// entries:
46+
// The number of elements must be in the range 1-100.
2847
highWaterMark: 100,
2948
async write (chunk, encoding, callback) {
3049
try {
@@ -47,4 +66,4 @@ const createWriteStream = function (options) {
4766
})
4867
}
4968

50-
module.exports = { createWriteStream }
69+
module.exports = { createWriteStream, logLevels }

0 commit comments

Comments
 (0)