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

  • Home
  • SEARCH
  • 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 900629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:25:12+00:00 2026-05-15T15:25:12+00:00

How do i save logs in PHP? Is there any magical function available in

  • 0

How do i save logs in PHP? Is there any “magical” function available in php for doing so, or any library? Or should i have to fopen file everytime and dump in it? I want to save my logs in text file.

Thanks in advance 🙂

  • 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-15T15:25:13+00:00Added an answer on May 15, 2026 at 3:25 pm

    I wrote a simple class to do this. Maybe you’ll find it useful.

    class Log
      {
      public function __construct($log_name,$page_name)
        {
        if(!file_exists('/your/directory/'.$log_name)){ $log_name='a_default_log.log'; }
        $this->log_name=$log_name;
    
        $this->app_id=uniqid();//give each process a unique ID for differentiation
        $this->page_name=$page_name;
    
        $this->log_file='/your/directory/'.$this->log_name;
        $this->log=fopen($this->log_file,'a');
        }
      public function log_msg($msg)
        {//the action
        $log_line=join(' : ', array( date(DATE_RFC822), $this->page_name, $this->app_id, $msg ) );
        fwrite($this->log, $log_line."\n");
        }
      function __destruct()
        {//makes sure to close the file and write lines when the process ends.
        $this->log_msg("Closing log");
        fclose($this->log);
        }
      }
    
     $log=new Log('file_name','my_php_page');
     $log->log_msg('fizzy soda : 45 bubbles remaining per cubic centimeter');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I save stuff in an Isolated Storage file (using class IsolatedStorageFile). It works well,
When I save a file with an .htm or .html extension, which one is
I am attempting to save an rtf file using FileDialog and would like to
When a user logs in I want to save their IP in the database.
To save network traffic I'd like to compress my data. The only trick is
I would like to save the programs settings every time the user exits the
Occasionally while attempting to save a Crystal Report that I'm working on in VS2008,
How do I save each sheet in an Excel workbook to separate CSV files
I need to save a user's login information in encrypted form for this application
I want to save the objects I generated in a program. After restart the

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.