Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 864771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:32:03+00:00 2026-05-15T09:32:03+00:00

Well, I don’t know if thats what I want. But here is my problem:

  • 0

Well, I don’t know if thats what I want. But here is my problem:

In case of some error I am logging the FILE, CLASS, FUNCTION and LINE in a file. For that I am doing something like:

myLog('['. __FILE__ . ']' . '[' . __CLASS__ . ']' . '[' . __FUNCTION__ . ']' . '[' . __LINE__ . ']');

The problem is everywhere I’ve to repeat that code in the parameter. and If I want to change the format, I’ve to change everywhere.

How can I have something like:

myLog(LOG_MSG_FORMAT);

With PHP define it is not possible since it will give my the LINE number of the place where that definition is, not where the definition is getting used.

Any solution to this is welcome. I am not bitchy about having C like functionality of #def.

EDIT:
The function does not necessarily be called only in case of errors. It is just that I want to log the the file, line, etc. wherever I am calling that function.
So if I just paste a code somewhere “”, it should log the line, etc.

For example:

<?php
...
...
<log this location>
...
...
<log this location>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:32:04+00:00Added an answer on May 15, 2026 at 9:32 am

    as others said, you can use debug_backtrace to find out the calling location of your log function. debug_backtrace is quite inconsistent, therefore there is some trickery involved, here’s an example:

    // helper
    function e($a, $k, $d = null) { 
        return isset($a[$k]) ? $a[$k] : $d; 
    }
    
    function mylog($msg) {
        $t0 = e(debug_backtrace(), 0);
        $t1 = e(debug_backtrace(), 1);
    
        $header = sprintf("%s:%s (%s:%s)",
            e($t1, 'class', 'global'),
            e($t1, 'function', 'unknown'),
            e($t0, 'file'),
            e($t0, 'line'));
    
        $_ = func_get_args();
        $s = $header . ': ' . vsprintf(array_shift($_), $_);
    
        echo $s, "\n"; // or error_log
    }
    

    As a free bonus, my_log also accepts a parameter list in printf style, e.g.

     my_log("send mail to=%s subject=%s time=%d", $to, $subject, time());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, well I don't really know how to describe this but here's my current
Well I don't actually want to make a calendar but I need a view
Well I don't really know how to search for the thing I'm looking for.
Well I don't know correct word for this so I wrote three of them,
Paint.net dies opening this image, and MS paint as well.I don't know how to
I'm not sure what I'm missing here, but I can't find a reliable ORM
I was reviewing some information about the components of the URL, but can't find
I'm not sure if this is possible but I would like to retrieve some
I don't well understand the difference betweeen these two lock classes. In boost documentation
I have the following query, the variable a works well if I don't use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.