1
This commit is contained in:
commit
3f7488fa69
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.*
|
||||||
|
!.gitignore
|
||||||
|
go.sum
|
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 apigo
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
32
README.md
Normal file
32
README.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# log for GoJS
|
||||||
|
|
||||||
|
## set log config in env.yml
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
log:
|
||||||
|
level: info # specify the log level (error/warning/info/debug), default: info
|
||||||
|
file: out.log # specify the log file, default logs to standard output
|
||||||
|
splitTag: 20060102 # log file split format, refer to Golang date time format syntax, default does not split
|
||||||
|
sensitive: phone,password,secret,token,accessToken # fields to be desensitized in logs, separated by commas. The matching values in requests, responses, HTTP headers, and request/response JSON data indices will be desensitized
|
||||||
|
```
|
||||||
|
|
||||||
|
### more config see [ssgo/log](https://github.com/ssgo/log)
|
||||||
|
|
||||||
|
## example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import log from 'log'
|
||||||
|
log.info('hello world')
|
||||||
|
log.error('some error', {name: 'abc'})
|
||||||
|
```
|
||||||
|
|
||||||
|
## module.exports
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function debug(message:string, info?:Object): void {}
|
||||||
|
function info(message:string, info?:Object): void {}
|
||||||
|
function warn(message:string, info?:Object): void {}
|
||||||
|
function error(message:string, info?:Object): void {}
|
||||||
|
```
|
||||||
|
|
||||||
|
## full api see [log.ts](https://apigo.cc/gojs/log/log.ts)
|
23
go.mod
Normal file
23
go.mod
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
module apigo.cc/gojs/log
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
apigo.cc/gojs v0.0.1
|
||||||
|
apigo.cc/gojs/util v0.0.1
|
||||||
|
github.com/ssgo/u v1.7.9
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||||
|
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
|
||||||
|
github.com/ssgo/config v1.7.7 // indirect
|
||||||
|
github.com/ssgo/log v1.7.7 // indirect
|
||||||
|
github.com/ssgo/standard v1.7.7 // indirect
|
||||||
|
github.com/ssgo/tool v0.4.27 // indirect
|
||||||
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
|
golang.org/x/text v0.19.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
46
log.go
Normal file
46
log.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
|
"apigo.cc/gojs"
|
||||||
|
"apigo.cc/gojs/goja"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed log.ts
|
||||||
|
var logTS string
|
||||||
|
|
||||||
|
//go:embed README.md
|
||||||
|
var logMD string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
obj := map[string]any{
|
||||||
|
"info": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
|
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
|
args.Logger.Info(args.Str(0), args.Map2Array(1)...)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
"warn": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
|
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
|
args.Logger.Warning(args.Str(0), args.Map2Array(1)...)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
"error": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
|
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
|
args.Logger.Error(args.Str(0), args.Map2Array(1)...)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
"debug": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
|
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
|
args.Logger.Debug(args.Str(0), args.Map2Array(1)...)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
gojs.Register("apigo.cc/gojs/log", gojs.Module{
|
||||||
|
Object: obj,
|
||||||
|
Desc: "logger api by github.com/ssgo/log",
|
||||||
|
TsCode: logTS,
|
||||||
|
Example: logMD,
|
||||||
|
})
|
||||||
|
}
|
13
log.ts
Normal file
13
log.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// just for develop
|
||||||
|
|
||||||
|
export default {
|
||||||
|
debug,
|
||||||
|
info,
|
||||||
|
warn,
|
||||||
|
error,
|
||||||
|
}
|
||||||
|
|
||||||
|
function debug(message:string, info?:Object): void {}
|
||||||
|
function info(message:string, info?:Object): void {}
|
||||||
|
function warn(message:string, info?:Object): void {}
|
||||||
|
function error(message:string, info?:Object): void {}
|
15
log_test.go
Normal file
15
log_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package log_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"apigo.cc/gojs"
|
||||||
|
_ "apigo.cc/gojs/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test(t *testing.T) {
|
||||||
|
gojs.Run(`
|
||||||
|
import log from 'apigo.cc/gojs/log'
|
||||||
|
log.info('some info', {extinfo: 'extinfo'})
|
||||||
|
`, "")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user