i am using Winston ^3.0.0-rc6 as below :
var options = {
file: {
level: 'info',
filename: `${appRoot}/logs/app.log`,
handleExceptions: true,
json: true,
prettyPrint: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: true,
}
};
const jsonFormatter = (logEntry) => {
if (logEntry.type) {
const base = {
timestamp: new Date()
};
const json = Object.assign(base, logEntry);
logEntry[MESSAGE] = JSON.stringify(json);
} else {
logEntry = "";
}
return logEntry;
}
const logger = winston.createLogger({
format: winston.format(jsonFormatter)(),
transports: [
new winston.transports.File(options.file)
],
exceptionHandlers: [
new winston.transports.File(options.uncaughtExceptions)
]
});
my log output :
{"timestamp":"2018-06-10T07:41:03.387Z","type":"Authentication","status":"failed","level":"error","message":"Incorrect password"}
but i want them to be like :
{
"timestamp": "2018-06-10T07:41:03.387Z",
"type": "Authentication",
"status": "failed",
"level": "error",
"message": "Incorrect password"
}
i tried to play around with json : true , and prettyPrint but it did not do the trick .
Can any one help please
Thanks.
I noticed in your code that on the line
logEntry[MESSAGE] = JSON.stringify(json);
you're using JSON.stringify() which takes two more optional arguments
JSON.stringify(value[, replacer[, space]])
If you set space to the amount of spaces you'd like you'll get the output you're looking for. So change the initial line to be:
logEntry[MESSAGE] = JSON.stringify(json, null, 2); // or 4 ;)
(The replacer argument is null because we don't want to change the default behavior.)
This is deprecated: You can check the link here.
I tried to play around with json: true, and prettyPrint but it did not do the trick.
Simple code like this work for you:
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
If this does not work, let me know so that I can improvise.
Hello guys i have a problem with displaying my pie chart, when i try to add more data into the pie chart this error occurs, i need your expertise on this matter
this is my controller code. and the error message is
[50053] - Incomplete dimensions binding
onInit: function() {
this._setupSelectionList();
// 2.Create a JSON Model and set the data
var oModel = new sap.ui.model.json.JSONModel("http://lssinh000.sin3.sap.corp:8000/SAP_LE/lionExpress/Volunteer/Services/request.xsjs");
var oVizFrame = this.getView().byId("idpiechart");
// 3. Create Viz dataset to feed to the data to the graph
var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions : [{
name : 'Status',
value : "{Status}",
name : 'StartDate',
value : '{StartDate}'
}],
measures : [{
name : 'reqID',
value : '{reqID}',
},],
data : {
path : "/Status"
}
});
oVizFrame.setDataset(oDataset);
oVizFrame.setModel(oModel);
// 4.Set Viz properties
oVizFrame.setVizProperties({
title:{
text : "Delivery Summary"
},
plotArea: {
colorPalette : d3.scale.category20().range(),
drawingEffect: "glossy"
}});
var feedSize = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "size",
'type': "Measure",
'values': ["reqID"]
}),
feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "color",
'type': "Dimension",
'values': ["Status"]
}),
feedValue = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "value",
'type': "Dimension",
'values': ["StartDate"]
});
oVizFrame.addFeed(feedSize);
oVizFrame.addFeed(feedColor);
oVizFrame.addFeed(feedValue);
//this.getView().byId("idPopOver").connect(oVizFrame.getVizUid());
},
In the dataset, the name attribute has to be same as in the values arrays of the feeds.
The JSON data is in Correct Format ! yet i am unable to bind the JSON data with the Grid . I dont even get an Empty Grid ! The problem lies with my extjs code,I am a new to Extjs! i am using 4.2.1
I am Trying to Render the Grid in the upload.gsp div by using
renderTo: 'csvGrid' in the extjs Panel .
It simply Renders the JSON data but not inside the grid ! Please help !
Grails Contoller Actions Contoller Code
def index() {
render (view:"upload")
}
def upload() {
def uploadedCSVFile = request.getFile('file')
// def csvMap = [:]
// def listOfCsvMap = []
def materialCode
def serialNumber
def label
String [] row ;
char separator = ';';
CSVReader reader = new CSVReader(new InputStreamReader(uploadedCSVFile.getInputStream()),separator);
String [] header = reader.readNext()
// String [] temp;
if (header[0].equalsIgnoreCase("Material_Code") && header[1].equalsIgnoreCase("Serial_Number") && header[2].equalsIgnoreCase("#Labels") )
{
List <String []> fileData = reader.readAll()
Iterator<String[]> rowIterator = fileData.iterator()
def listOfCsvMap = []
while (rowIterator.hasNext())
{
def csvMap = [:]
row = rowIterator.next()
materialCode = row.collect().get(0)
serialNumber = row.collect().get(1)
label = row.collect().get(2)
csvMap.put('Material_Code', materialCode)
csvMap.put('Serial_Number', serialNumber)
csvMap.put('Labels', label)
listOfCsvMap.add(csvMap)
}
render([items:listOfCsvMap] as JSON)
upload.gsp
<body>
<div class="body">
<g:uploadForm action="upload" enctype="multipart/form-data">
<input type="file" name="file">
<g:submitButton name="upload" value="Upload"/>
</g:uploadForm>
<g:javascript src="grid.js" />
<div id="csvGrid"> </div>
and in the grid.js
var store1;
Ext.onReady(function() {
store1 = new Ext.data.JsonStore({
storeId: 'myStore1',
pageSize: 20,
proxy: {
type: 'ajax',
url:'upload',
reader: {
type: 'json',
root: 'items'
}
},
fields: ['Material_Code','Serial_Number','Labels']
});
var grid = Ext.create('Ext.grid.Panel', {
store: store1,
stateful: false,
layout:'fit',
enableColumnMove: true,
enableColumnResize:true,
emptyText:'<b style="font-size:14px;color: #F49000;">'+'Please fill all the mandatory fields!!!'+'</b>',
columns: [
{
text : 'Material Code',
width:175,
sortable : true,
dataIndex: 'Material_Code',
},
{
text : 'Serial Number',
width :275,
sortable : true,
dataIndex: 'Serial_Number'
},
{
text : '#Labels',
width :275,
sortable : true,
dataIndex: 'Labels'
}
],
bbar: Ext.create('Ext.PagingToolbar', {
store: store1,
pageSize: 20,
displayInfo: true,
displayMsg: 'Displaying rows {0} - {1} of {2}',
emptyMsg: "No rows to display"
}),
height: 350,
width: 850,
renderTo: 'csvGrid',
viewConfig: {
stripeRows: true,
enableTextSelection:true
}
});
store1.reload();
});
The error that is causing the issue directly is this :
<g:uploadForm action="upload" enctype="multipart/form-data">
The action is upload, which is the url that returns the JSON.
A solution would be to create a separate page, define it as action and load the JavaScript on that page.
Alternatively, instead of submitting the form you can send the values as parameters when you load the store (pass them in the options object of store1.load({params: {...}}). In this case it would be a better design to create the whole page with extjs, including the form.
There are other problems with the code, like you have store1.reload();, but you never called load() before.
i am facing a problem which i want to generate a button in grid column by using reconfigure function.
i find my code consist of the Extjs error during renderer function 'Uncaught TypeError: Cannot read property 'dom' of null'
i checked that it should be come from "renderTo: id3", do you have any idea on it? Do i do something wrong in my render button function in the grid?
Although i pop up error message, but the UI still can show the button i genereated. it is very confused.
var createColumns = function (json) {
var keys = getKeysFromJson(json[0]);
return keys.map(function (field) {
if(field!='unread'&&field!='linkerType'&&field!='linkParam'&&field!='refNumber'&&field!='oid'&&field!='refOwner'){
return {
text: Ext.String.capitalize(field),
//flex : 1,
dataIndex: field,
sortable: true,
menuDisabled: true,
renderer: function (val, metadata, record) {
if(field=='action') {
var str = val.split(":");
metadata.style = "text-align: left";
if(str[2]=='true'&&str[1]=='false'){
var id3 = Ext.id();
Ext.defer(function () {
Ext.widget('button', {
renderTo: id3,
margin: '0 0 0 10',
iconAlign: 'center',
tooltip:'Ok to Ship Again',
cls: 'x-btn-default-small',
text: '<img src="images/OKToShipAgain.png">',
handler: function() {
items=[];
items.push({
"oid" : record.get('oid'),
"refNumber" : record.get('refNumber'),
"refOwner" : record.get('refOwner')
});
Ext.Ajax.request({
url: '#{csMenuBean.contextPath}/ws3/todolistservice/submitOktoship',
params: {data: Ext.encode(items)},
success : function(response){
}
});
}
})
}, 50);
return Ext.String.format('<span id="{0}"></span>', id3);
}
i'm having trouble trying to figure out how this is happening. i'm using Extjs and AJAX with JsonStore from my callback my page in ASP call the database and return some fields in this fields there is a Date and this date return the proper date ex.: "date_creat_post": "29\u002F04\u002F2011"...
Now once i look at my output from this in my page in a datagrid i'm getting the following:
04/05/2013 <----> the date it return in the callback is 04/05/2011
06/05/2012 <----> the date it return in the callback is 06/05/2010
07/04/2012 <----> the date it return in the callback is 07/04/2010
I looked all threw my code to see if they're is a place where i am adding 1 year to the date.
but can't find it. i have been trying now for at least 2 days to figure this out.
Here's my code:
Ext.onReady(function(){
Ext.QuickTips.init();
// for this demo configure local and remote urls for demo purposes
var url = {
local: '', // static data file
remote: '../myurl.asp'
};
// configure whether filter query is encoded or not (initially)
var encode = true;
// configure whether filtering is performed locally or remotely (initially)
var local = false;
var PostStore = new Ext.data.JsonStore({
// store configs
autoDestroy: true,
baseParams : {filter : '[{"type":"boolean","value":false,"field":"is_sent_post"}]'},// we start only with is_sent == false
url: url.remote,
remoteSort: false,
sortInfo: {
field: 'date_creat_post',
direction: 'DESC'
},
storeId: 'Post_Store',
// reader configs
idProperty: 'id_post',
root: 'Post',
totalProperty: 'totalcount',
fields: [{
name: 'id_post',
type: 'number'
}, {
name: 'name_post',
type: 'string'
}, {
name: 'date_creat_post',
type: 'date'//,
//dateFormat: 'Y-m-d H:i:s'
}, {
name: 'from_addr_post',
type: 'string'
}, {
name: 'sender_name_post',
type: 'string'
}, {
name: 'is_sent_post',
type: 'boolean'
}, {
name: 'date_sending_post',
type: 'date'//,
//dateFormat: 'Y-m-d H:i:s'
}, {
name: 'html_post',
type: 'string'
}, {
name: 'list_send_post',
type: 'number'
}],
writer: new Ext.data.JsonWriter({
writeAllFields: true
}),
autoSave: false,
batch: true
});
var filters = new Ext.ux.grid.GridFilters({
// encode and local configuration options defined previously for easier reuse
encode: encode, // json encode the filter query
local: local, // defaults to false (remote filtering)
filters: [{
type: 'numeric',
dataIndex: 'id_post'
}, {
type: 'string',
dataIndex: 'name_post'
}, {
type: 'date',
dataIndex: 'date_creat_post'
}, {
type: 'string',
dataIndex: 'from_addr_post'
}, {
type: 'string',
dataIndex: 'sender_name_post'
}, {
type: 'boolean',
dataIndex: 'is_sent_post'
}, {
type: 'date',
dataIndex: 'date_sending_post'
}, {
type: 'string',
dataIndex: 'html_post'
}, {
type: 'numeric',
dataIndex: 'list_send_post'
}]
});
// use a factory method to reduce code while demonstrating
// that the GridFilter plugin may be configured with or without
// the filter types (the filters may be specified on the column model
var createColModel = function (finish, start) {
var columns = [{
dataIndex: 'id_post',
hidden:true,
header: 'Id',
// instead of specifying filter config just specify filterable=true
// to use store's field's type property (if type property not
// explicitly specified in store config it will be 'auto' which
// GridFilters will assume to be 'StringFilter'
filterable: true
//,filter: {type: 'numeric'}
}, {
dataIndex: 'name_post',
header: 'Subject',
width: 150,
id: 'postname',
filter: {
type: 'string'
// specify disabled to disable the filter menu
//, disabled: true
}
}, {
dataIndex: 'date_creat_post',
header: 'Date Created',
renderer: Ext.util.Format.dateRenderer('d/m/Y'),
filter: {
type: 'date' // specify type here or in store fields config
}
}, {
dataIndex: 'from_addr_post',
header: 'From Address',
hidden:true,
id: 'fromaddress',
filter: {
type: 'string'
// specify disabled to disable the filter menu
//, disabled: true
}
}, {
dataIndex: 'sender_name_post',
header: 'Sender Name',
id: 'sendername',
filter: {
type: 'string'
// specify disabled to disable the filter menu
//, disabled: true
}
}, {
dataIndex: 'is_sent_post',
header: 'Status',
filter: {
type: 'boolean' // specify type here or in store fields config
},
renderer: function(value) {
var rtn = (value == 1) ? 'sent' : 'stand-by';
return rtn
}
}, {
dataIndex: 'date_sending_post',
header: 'Sending Date',
hidden:true,
//renderer: Ext.util.Format.dateRenderer('d/m/Y'),
filter: {
type: 'date' // specify type here or in store fields config
}
}, {
dataIndex: 'list_send_post',
header: 'Opticians list',
hidden:true,
id: 'optlist',
filter: {
type: 'number'
// specify disabled to disable the filter menu
//, disabled: true
}
}];
return new Ext.grid.ColumnModel({
columns: columns.slice(start || 0, finish),
defaults: {
sortable: true
}
});
};
/*
//======================contextMenu triggered by right click========================================
*/
var doRowCtxMenu = function ( thisGrid, rowIndex,cellIndex, evtObj )
{
//Ext.popup.msg('Done !', 'Right clicked !');
evtObj.stopEvent();
var sm = thisGrid.getSelectionModel();
var records = sm.getSelections(); // returns an array of Ext.data.Records
try
{
//var r = records[0]; // get the 1st Ext.data.Record of the list
thisGrid.rowCtxMenu = new Ext.menu.Menu({
items: [{
text : '<span style="color:red;">Delete Selected Email ?</span>',
handler : function () {
deletePost(records,thisGrid);
}
}]
});
thisGrid.rowCtxMenu.showAt(evtObj.getXY());
}
catch(err)
{
Ext.popup.msg('Warning !', 'You need to select a row first !');
}
};
/*
//======================END contextMenu triggered by right click========================================
//======================Delete Post Fonction =================================================
*/
function deletePost(records,thisGrid)
{
Ext.Msg.show({
title :'Warning !',
msg : 'You are about to delete 1 email !',
buttons : Ext.Msg.YESNOCANCEL,
fn : function(btn){
if (btn=='yes')
{
var store = thisGrid.getStore();
var s = thisGrid.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
store.proxy.conn.url = '../myurl.asp';
store.save();
lastOptions = store.lastOptions;
/*Ext.apply(lastOptions.params, {
//myNewParam: true
});*/
store.load(lastOptions);
}
},
animEl : 'elId'
});
}
/*
//======================End delete Function========================================
*/
var Postgrid = new Ext.grid.GridPanel({
id:'post_grid',
border: false,
width: 462,
height:250,
store: PostStore,
colModel: createColModel(8),
loadMask: true,
viewConfig:{
emptyText:'No Post to display, change/clear your filters, refresh the grid or add a new Email!'
},
plugins: [filters],
sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {
rowselect: function(sm, row, rec) {
Ext.getCmp("post_form").getForm().loadRecord(rec);
//Ext.getCmp("htmlEdit").setValue("sdcdsdcdscsdc");
}
}
}),
//autoExpandColumn: 'company',
listeners: {
cellcontextmenu : doRowCtxMenu,
render: {
fn: function(){
PostStore.load({
params: {
start: 0,
limit: 50
}
});
}
}
},
bbar: new Ext.PagingToolbar({
store: PostStore,
pageSize: 50,
plugins: [filters]
})
});
// add some buttons to bottom toolbar just for demonstration purposes
Postgrid.getBottomToolbar().add([
'->',
{
text: 'Clear Filter Data',
handler: function () {
Postgrid.filters.clearFilters();
}
}
]);
var panelGrid = new Ext.Panel({
width : 462,
height : 250,
layout : 'fit',
renderTo: 'post-grid',
items: Postgrid
});
});
i will give my callback in firebug json:
{"totalcount":3, "Post": [{"id_post": 83,"name_post": "ghfgh","date_creat_post": "29\u002F04\u002F2011","from_addr_post": "fgh#sdf.com","sender_name_post": "gfh","is_sent_post": false,"date_sending_post": "29\u002F04\u002F2011","html_post": "<p>dfgdgdgd<\u002Fp>","list_send_post": null},{"id_post": 61,"name_post": "thomas test","date_creat_post": "28\u002F07\u002F2010","from_addr_post": "","sender_name_post": "","is_sent_post": false,"date_sending_post": "28\u002F07\u002F2010","html_post": "<p>test test test ets<\u002Fp>","list_send_post": null},{"id_post": 59,"name_post": "kevin test","date_creat_post": "29\u002F06\u002F2010","from_addr_post": "kevin#art-systems.net","sender_name_post": "kevin#art-systems.net","is_sent_post": false,"date_sending_post": "29\u002F06\u002F2010","html_post": "<p>jkljljoi ioijiio ijiojio oijio joijoi<\u002Fp>\u000A<p> <\u002Fp>\u000A<p><span style=\u0022background-color: #ffffff;\u0022>igiuihhuhi<\u002Fspan><\u002Fp>","list_send_post": null}]}
Thanks in advance i hope some on on the wicked web can help me....
cheers.
so after trying many solution giving to be i came to this has problem
finally the the date example after many attemps to format and inserting in my msSQL database
this problem is the problem : 13\09\2011 (d/m/Y) becomes this 09/01/2012 (d/m/Y) so for some reason the month 13 is being added to the month so say the 13 month doesn't exist so the date will go to 09/01/2012....
after looking again it's the format that doesn't seem ok so i changed it de (m/d/Y) and now im getting a sql error when i hit 13 day on my datefield in (extjs).
"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
and on and on does anyone have any ideas now ????
Instead of using the built in Ext.util.Format.dateRenderer, you could try creating one of your own that parses the Date as desired.
ataIndex: 'date_creat_post',
header: 'Date Created',
renderer: daterenderer
And then a function for your daterenderer:
function dateRenderer(value, id, r) {
var myDate = r.data['date_creat_post'];
// do some things here to strip out the date and make it into a happy format
var d = new Date(myDate);
return d.format('d/m/Y');
}