I want to implement error handling and maintain log file to record errors in my CodeIgniter application.
In general, CodeIgniter doesn't record the error message along with the path and line number in certain cases like database exceptions or custom error logging. This is difficult to trace. So is there any way to log the error along with the path and line number?
Codeigniter provide logs with date time and path of a file. You can follow this instruction:
application->config.php
and changed the following values as per your requirnment
log_threshold
log_path
log_file_extension
Thank you
CodeIgniter has some error logging functions built in.
Go to application/config/config.php
set
$config['log_threshold'] = 1;
Note
your /application/logs folder should be writable
Related
I have a public website made using Apex 21.1.3
When a user shares a page of my website, let's say on facebook, Facebook adds "?fbclickId=something" to the URL.
My app then crashes saying : Unable to find item ID for item fbclickId in application.
Apex thinks the user is trying to set an element that does not exist on the application.
I have url processing layer using htaccess that formats the urls before sending them to Apex in a reverse proxy. I could say let's ignore all what comes after a question mark "?" but in this case I wont be able to set any application item value neither. So that's not possible.
Does anyone have an idea how to make Apex ignore setting a parameter if it doesn't exist ?
Using google for example :
This URL https://www.google.com/?anyparameter=anyvalue will always resolve to https://www.google.com
Thanks
Cheers
I'm not aware of any way to ignore invalid parameters, but you can make the error a bit nicer for the end user.
Create a custom apex error handling function. The only difference with standard error handling is that the error with code WWV_FLOW.FIND_ITEM_ID_ERR has a custom message and no additional info. Change the string "Invalid url arguments" to something more relevant for your business case.
create or replace function apex_error_custom
(
p_error IN apex_error.t_error
)
RETURN apex_error.t_error_result
IS
l_result apex_error.t_error_result := apex_error.t_error_result();
BEGIN
l_result := apex_error.init_error_result ( p_error => APEX_ERROR_CUSTOM.p_error );
IF p_error.apex_error_code = 'WWV_FLOW.FIND_ITEM_ID_ERR' THEN
l_result.message := 'Invalid url arguments';
l_result.additional_info := NULL;
END IF;
RETURN l_result;
END apex_error_custom;
Change the application definition to use the new error function:
Application Definitions > Error Handling > Custom Error Function. Note this affects all errors in the application.
An additional way to make the error nicer is to change the default error page to use a defined template (Shared Components > Themes > your theme > Component Defaults > Error page). Note this affects all errors in the application.
Here is the solution I came up with.
I couldn't find any way to ignore unavailable fields but found a trick to avoid sending them to Apex, hence escaping the error.
In the middle tier (nginx, apache, IIS) add the following logic :
Whenever there are two question marks, ignore the second one part:
For example : someApexAppUrl?Parameter=value?fbclickid=something
Should become : someApexAppUrl?Parameter=value
Whenever there is a parameter added to the url for example
someApexAppUrl?Parameter=value
Check the parameter name against
Application Items with a protection level of Unrestricted, Checksum Required - Application Level, Checksum Required - User Level, Checksum Required - Session Level
The hard coded list of the default Apex urls parameters which are : session, request, clear, debug, printerFriendly, trace, timezone, lang, territory, cs, dialogCs, x01 according to this article
Application page items with a name pattern P99_Someting
Whenever a parameter is not among these three categories, ignore it and don't send it to Apex. This way even if facebook adds something like ?fbclickid=xxx the Apex App will still work nicely.
You can add the item to your application to avoid getting this error message.
Create an Application Item (under Shared Components) called FBCLICKID. Set its Session State Protected to Unrestricted.
I'm a bit new to laravel, but I'm experienced in Php.
In previous works, I set a mecanism that allowed me to be informed when nearly any problem occurred on the server:
I got full stack
precise PHP error messages
for nearly all king of errors
a mail sent to me
So when I began to work with laravel, I tried to do the same things, and achieved:
full stack
a mail sent to me
But I can't have meaningful error in all case. One example:
$store = Store::create(...)
In this line I forget to specify the namespace (\App\Store::create), and I get those error messages:
first:
FatalThrowableError ; Type error: Argument 1 passed to App\Http\Controllers\User::create() must be an instance of Illuminate\Http\Request, array given, called in /var/www/html/laravel/blog/app/Http/Controllers/User.php on line 94
second:
ErrorException ; Trying to get property of non-object in VerifyCsrfToken.php (line 156)
third:
FatalThrowableError ; Type error: Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, array given, called in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 72
I understand that laravel is a complex framework but I can't figure why it produces this errors, and how I can have more useful errors (as as it is I can only know that "something is bad").
Has someone an idea ?
ยน There is some errors that Php prefers to keep to himself (in its logs) :-)
When you start a new Laravel project, error and exception handling is
already configured for you. The App\Exceptions\Handler class is where
all exceptions triggered by your application are logged and then
rendered back to the user.
https://laravel.com/docs/5.4/errors
I recommend you to dive into the official docs and into your App\Exceptions\Handler.
Maybe you are looking for report and render methods in that class.
I finally cornered the problem and I learned a lot.
I thank for their benevolence #Don't Panic and #Vitalmax !
The error was that I forgot that PHP namespaces are case insensitive: in my post I cleaned a bit the code as I knew that it didn't stick to the code's conventions (a controller's name must begin with a capital letter). Originally my controller name was user and the faulty code was:
$user = User::create(...)
As you can guess PHP believed that I wanted to call user::create (as I have such a method in my controller) and not User::create (as I wanted).
What I learned:
don't alter the code when asking for help
Laravel use a cache system that can get in the way of the debugging (see a question that I asked on laracast's forum )
take more time to read the error message; I know this rule but I keep doing otherwise
For handling entities in Drupal I'm using Entity Metadata Wrappers (the "Drupal way").
It's really easy to start coding and see all the advantages it has... except when you get a fatal error and you are not clear where it comes from.
This is what the database log shows:
EntityMetadataWrapperException: Unknown data property
field_whatever. at EntityStructureWrapper->getPropertyInfo()
(line 335 of
/var/www/html/sites/all/modules/entity/includes/entity.wrapper.inc).
Sadly, many times that "field_whatever" is "nid", "uid" or some very common property, so it's name is spread all over my code, which makes me difficult to get to the origin of the error.
I'm currently doing this:
Write a tiny piece of code and then run to see if something fails.
Using getPropertyInfo when handling entities with "not so common" fields.
Loosing hair.
What is worst is that sometimes the error does not appear when you are coding, but a week later. So it could be anywhere...
Is there any way of handling entity metadata wrapper errors better? Can I get better information in the database log and not just a line? A backtrace maybe?
Thanks.
Well, having the devel module active (just to see the nice krumo message) we can do something like this inside our module:
<?php
set_exception_handler('exception_with_trace');
function exception_with_trace($e)
{
dpm($e->getTrace());
}
That will return the backtrace error of the exception thrown by the entity metadata handler on the next page load (some page in your site where everything is running fine).
Also you can set the exception handler exclusively and more elegant just for some pages or some users with some role... or when some parameter in the url is met, or when in some state of your Drupal site is met (ex. when a bool persistent variable 'exception_with_trace' is true). Even, under certain conditions and control, you can use it in production too.
If the site does not work "at all" you can include it in your settings.php file, but instead of printing the trace, you must write the trace to a file and watch the trace in a different context (not Drupal but some php file).
If exceptions are too long and are causing memory problems then getting the trace as string is also possible. See http://php.net/manual/es/exception.gettraceasstring.php
Hope that helps.
I want to use jp#gc - Graphs Generator in my Test Plan to create graphs from existing results file(results.csv).
I am getting error - "Error loading file".
My results.csv file has data like below:
14:31:14;1208;login;200;OK;Thread Group 1-2;text;true;950;10;10;1208;1;0;U6021712-TPL-A
I am not sure how Graphs Generator will be able to create various graphs using the data mentioned above. On checking the error log I noticed below message:
2014/12/12 14:31:29 INFO - jmeter.save.CSVSaveService: results.csv does not appear to have a valid header. Using default configuration.
2014/12/12 14:31:29 WARN - jmeter.save.CSVSaveService: Error parsing field 'timeStamp' at line 1 java.text.ParseException: Unparseable date: ""
2014/12/12 14:31:29 WARN - jmeter.reporters.ResultCollector: Problem reading JTL file: results.csv
Any help would be much appreciated!
As error message says, you have an error in the definition of timestamp field on the JMeter instance where you run this code.
And configuration differs from the one that led to the CSV file you got.
So you need to check that you use the same jmeter.properties and user.properties on this instance that the one you used on the instance that generated the CSV.
For example here you should have this to fix this issue (but you may have other issues):
jmeter.save.saveservice.timestamp_format=HH:mm:ss
In Jmeter, timeStamp is long datatype. So make sure that no spaces in timeStamp row (If you have a space , jmeter doesn't accept it and throws
java.lang.NumberFormatException: For input string: "timeStamp"
Example:
Valid data set
1456177238234,224,Java Request 1,200,,Auto Quick Invest 1-1,,true,,0,2,2,null,0,1,0,M-SFO1-SFO1216
Invalid data set
1456177238234,224,Java Request 1,200,,Auto Quick Invest 1-1,,true,,0,2,2,null,0,1,0,M-SFO1-SFO1216
Because timeStamp field has space.
Using BIRT designer 3.7.1, it's easy enough to define a report for an XML file data source; however, the input file name is written into the .rptdesign file as constant value, initially. Nice for the start, but useless in real life. What I want is start the BIRT ReportEngine via the genReport.bat script, specifying the name of the XML data source file as parameter. That should be trivial, but it is surprisingly difficult...
What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime. Also, in BIRT Designer you can define the Report Parameter (datasource) and give it a default value, say "file://d:/sample.xml".
Yet, it doesn't work. This is the result of my Preview attempt in Designer:
Cannot open the connection for the driver: org.eclipse.datatools.enablement.oda.xml.
org.eclipse.datatools.connectivity.oda.OdaException: The xml source file cannot be found or the URL is malformed.
ReportEngine, started with 'genReport.bat -p "datasource=file://d:/sample.xml" xx.rptdesign' says nearly the same.
Of course, I have made sure that the XML file exists, and tried different spellings of the file URL. So, what's wrong?
What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime.
No, it won't - at least, if you specify the value of &XML Data Source File as params["datasource"].value (instead of a valid XML file path) at design time then you will get an error when attempting to run the report. This is because it is trying to use the literal string params["datasource"].value for the file path, rather than the value of params["datasource"].value.
Instead, you need to use an event handler script - specifically, a beforeOpen script.
To do this:
Left-click on your data source in the Data Explorer.
In the main Report Design pane, click on the Script tab (instead of the Layout tab). A blank beforeOpen script should be visible.
Copy and paste the following code into the script:
this.setExtensionProperty("FILELIST", params["datasource"].value);
If you now run the report, you should find that the value of the parameter datasource is used for the XML file location.
You can find out more about parameter-driven XML data sources on BIRT Exchange.
Since this is an old thread but still usefull, i ll add some info :
In the edit datasource, add some url to have sample data to create your dataset
Create your dataset
Then remove url as shown
add some script