added logging
parent
2e07dab28d
commit
df9a879fef
17
src/base.mjs
17
src/base.mjs
|
@ -1,19 +1,31 @@
|
|||
import UCISocket from '@uci/socket'
|
||||
// import UCISocket from '../../uci-socket/src'
|
||||
import EventEmitter from 'events'
|
||||
import { bindFuncs } from '@uci/utils/src/function'
|
||||
|
||||
import { processor, commands, namespaces } from './processing.mjs'
|
||||
|
||||
import logger from '@uci/logger'
|
||||
let log = {}
|
||||
const LOG_OPTS = {
|
||||
repo:'uci-base',
|
||||
npm:'@uci/base',
|
||||
file:'src/base.mjs',
|
||||
class:'Base',
|
||||
id:this.id,
|
||||
instance_created:new Date().getTime()
|
||||
}
|
||||
|
||||
export default class Base extends EventEmitter {
|
||||
constructor(opts={}) {
|
||||
super()
|
||||
log = logger.child(LOG_OPTS)
|
||||
this.id = opts.id || opts.name || 'uci-base:'+ new Date().getTime()
|
||||
this.desc = opts.desc // additional details for humans
|
||||
this.socket={}
|
||||
this._processors = { _default: processor }
|
||||
this._defaultCmds = commands
|
||||
this._namespaces = namespaces
|
||||
if(opts.sockets) {
|
||||
opts.sockets.split(/[,|\s]+/).forEach( socketStr => {
|
||||
let socket = {}
|
||||
socketStr.split(/[>#]+/).map(function(prop,index) {
|
||||
|
@ -28,6 +40,7 @@ export default class Base extends EventEmitter {
|
|||
Object.assign(this.socket[socket.name],socket) // copy socket info props to new socket
|
||||
this.socket[socket.name]._packetProcess = this._packetProcess.bind(this,socket.name)
|
||||
})
|
||||
} else log.warn({opts:opts},'no sockets requested for creations -- on standard emitter')
|
||||
this.bindFuncs = bindFuncs
|
||||
// console.log('base opts', opts)
|
||||
|
||||
|
@ -51,6 +64,8 @@ export default class Base extends EventEmitter {
|
|||
|
||||
async end(name) {} // TODO end all or named sockets
|
||||
|
||||
async addSocket(options) {} //TODO add ability to add another socket at runtime and initialize
|
||||
|
||||
async send (name,packet) {
|
||||
if (typeof name !== 'string') {
|
||||
packet = name
|
||||
|
|
|
@ -59,12 +59,14 @@ const commands ={
|
|||
},
|
||||
c:{
|
||||
error: function (packet) {
|
||||
// TODO log and make this show only on env debug
|
||||
console.log('==============Packet ERROR [consumer]==========')
|
||||
console.log(packet.error )
|
||||
console.dir(packet.packet)
|
||||
console.log('===========================')
|
||||
},
|
||||
reply: function(packet) {
|
||||
// TODO log and make this show only on env debug
|
||||
console.log('==============Packet returned from socket - default reply==========')
|
||||
console.dir(packet)
|
||||
console.log('===========================')
|
||||
|
|
Loading…
Reference in New Issue