Closed rlnt closed 2 years ago
I think it is expected behaviour.
According to guide, messagesLogLevel
is
Sets the log level of chat messages. Useful for custom logging of chat messages while keeping more general events.
It only affects chat messages.
Weird option but alright, thank you. How can I set the actual log level then?
As far as I know, you can't set log level except debug
option (that sets 'info' level).
So you need to implement your own logger as you have shown.
You set the level on the logger object.
client.log.setLevel('warn');
The client has no log field though or they are missing on the type declarations.
The client object looks like this, there is no setLevel()
function:
{
opts: {
connection: { reconnect: true },
channels: [ '#########' ],
identity: {
username: '########',
password: '###############'
},
logger: {
info: [Function: info],
warn: [Function: warn],
error: [Function: error]
},
options: {}
},
clientId: null,
_globalDefaultChannel: '#tmijs',
_skipMembership: false,
_skipUpdatingEmotesets: false,
_updateEmotesetsTimer: null,
_updateEmotesetsTimerDelay: 60000,
maxReconnectAttempts: Infinity,
maxReconnectInterval: 30000,
reconnect: true,
reconnectDecay: 1.5,
reconnectInterval: 1000,
reconnecting: false,
reconnections: 0,
reconnectTimer: 1000,
secure: true,
emotes: '',
emotesets: {},
channels: [],
currentLatency: 0,
globaluserstate: {},
lastJoined: '',
latency: 2021-09-10T15:41:34.878Z,
moderators: {},
pingLoop: null,
pingTimeout: null,
reason: '',
username: '',
userstate: {},
wasCloseCalled: false,
ws: null,
log: {
info: [Function: info],
warn: [Function: warn],
error: [Function: error]
},
_events: {
reconnect: [AsyncFunction (anonymous)],
message: [AsyncFunction (anonymous)],
connected: [Function: a] { listener: [AsyncFunction (anonymous)] }
},
_maxListeners: 0
}
It's not in the types because I didn't write them and also the logger can be user defined. You could use an existing library Winston. The logger object you're passing in doesn't have a setLevel
method so of course it won't appear when logging the client instance, but it does show your logger object at the log key. Again, look at the reference implementation linked above. This object is set to client.log
and includes a setLevel
method.
Actual behaviour: When I set the log level to
warn
or toerror
, it will still log info messages.Expected behaviour: It should only log the messages on the defined log level.
Error log: /
Server configuration
Further information When I use these option to set up my client:
I have this output (the success messages are done manually, the rest is from the logger):
As you can see, it still logs info messages even though the log level is set to
warn
.For now, as a workaround, I just ignore the info logger function so it won't do anything on info log messages, like this: