Skip to content
Snippets Groups Projects
Commit 7be18309 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Init view to show server logs on client side

parent cc4604f2
No related branches found
No related tags found
No related merge requests found
......@@ -115,6 +115,9 @@ Meteor.startup ->
roles : ['admin', 'bot']}
{ _id: 'manage-oauth-apps',
roles : ['admin']},
{ _id: 'view-logs',
roles : ['admin']}
]
......
......@@ -168,6 +168,7 @@ RocketChat.settings.addGroup 'Logs', ->
@add 'Log_Level', '0', { type: 'select', values: [ { key: '0', i18nLabel: '0_Errors_Only' }, { key: '1', i18nLabel: '1_Errors_and_Information' }, { key: '2', i18nLabel: '2_Erros_Information_and_Debug' } ] , public: true }
@add 'Log_Package', false, { type: 'boolean', public: true }
@add 'Log_File', false, { type: 'boolean', public: true }
@add 'Log_View_Limit', 10000, { type: 'int' }
RocketChat.settings.init()
......
......@@ -30,12 +30,12 @@ ansispan = function (str) {
};
ansispan.foregroundColors = {
'30': 'black',
'30': 'gray',
'31': 'red',
'32': 'green',
'33': 'yellow',
'34': 'blue',
'35': 'purple',
'34': '#6B98FF',
'35': '#FF00FF',
'36': 'cyan',
'37': 'white'
};
@stdout = new Meteor.Collection 'stdout'
Meteor.startup ->
RocketChat.AdminBox.addOption
href: 'admin-view-logs'
i18nLabel: 'View_Logs'
permissionGranted: ->
return RocketChat.authz.hasAllPermission('view-logs')
FlowRouter.route '/admin/view-logs',
name: 'admin-view-logs'
action: (params) ->
BlazeLayout.render 'main',
center: 'pageSettingsContainer'
pageTitle: t('Logs')
pageTemplate: 'viewLogs'
Template.viewLogs.onCreated ->
@subscribe 'stdout'
Template.viewLogs.helpers
hasPermission: ->
return RocketChat.authz.hasAllPermission 'view-logs'
logs: ->
return stdout.find({}, {sort: {ts: 1}})
ansispan: (string) ->
return ansispan(string.replace(/\s/g, '&nbsp;').replace(/(\\n|\n)/g, '<br>'))
formatTS: (date) ->
return moment(date).format('YMMDD-HH:mm:ss.SSS(ZZ)')
<template name="viewLogs">
{{#if hasPermission}}
<div class="section terminal">
{{#each logs}}
<div>
<!-- <span class="time">{{formatTS ts}}</span> -->
{{{ansispan string}}}
</div>
{{/each}}
</div>
{{else}}
{{_ "Not_authorized"}}
{{/if}}
</template>
......@@ -10,13 +10,19 @@ Package.onUse(function(api) {
api.use('coffeescript');
api.use('underscore');
api.use('random');
api.use('logging');
api.use('nooitaf:colors');
api.use('raix:eventemitter');
api.use('templating', 'client', {weak: true});
api.use('templating', 'client');
api.use('kadira:flow-router', 'client');
api.addFiles('ansispan.js', 'client');
api.addFiles('logger.coffee', 'client');
api.addFiles('client/viewLogs.coffee', 'client');
api.addFiles('client/views/viewLogs.html', 'client');
api.addFiles('client/views/viewLogs.coffee', 'client');
api.addFiles('server.coffee', 'server');
api.export('Logger');
......
......@@ -194,12 +194,55 @@
options.arguments.unshift @getPrefix(options)
console.log.apply console, options.arguments
# Meteor.publish 'stdout', ->
# write = process.stdout.write
# process.stdout.write = (string, encoding, fd) =>
# write.apply(process.stdout, arguments)
# id = Random.id()
# @added 'stdout', id, {string: string}
# @removed 'stdout', id
# @ready()
processString = (string, date) ->
if string[0] is '{'
try
return Log.format EJSON.parse(string), {color: true}
try
return Log.format {message: string, time: date, level: 'info'}, {color: true}
return string
StdOut = new class extends EventEmitter
constructor: ->
@queue = []
write = process.stdout.write
process.stdout.write = (string, encoding, fd) =>
write.apply(process.stdout, arguments)
date = new Date
string = processString string, date
item =
id: Random.id()
string: string
ts: date
@queue.push item
if RocketChat?.settings?.get('Log_View_Limit')? and @queue.length > RocketChat.settings.get('Log_View_Limit')
@queue.shift()
@emit 'write', string, item
Meteor.publish 'stdout', ->
unless @userId
return @ready()
if RocketChat.authz.hasPermission(@userId, 'view-logs') isnt true
return @ready()
for item in StdOut.queue
@added 'stdout', item.id,
string: item.string
ts: item.ts
@ready()
StdOut.on 'write', (string, item) =>
@added 'stdout', item.id,
string: item.string
ts: item.ts
return
......@@ -4395,3 +4395,36 @@ a.github-fork {
}
}
}
.terminal {
background-color: #000 !important;
color: #fff;
position: absolute;
top: 0px;
bottom: 0px;
margin: 0;
right: 0;
left: 0;
overflow-y: scroll;
border: none !important;
padding: 8px 10px !important;
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
* {
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}
> div {
word-break: break-all;
> .time {
color: #666;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment