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 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 489k
  • Answers 489k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Left shift the first number by the number of bits… May 16, 2026 at 9:03 am
  • Editorial Team
    Editorial Team added an answer They will be initialized at class definition time, which will… May 16, 2026 at 9:03 am
  • Editorial Team
    Editorial Team added an answer The problem was that the view where the field was… May 16, 2026 at 9:03 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

When a user logs in I want to save their IP in the database.
We have a hosted site that has a CMS we built running on a
Possible Duplicate: 500 - An error has occurred! DB function reports no errors when
With PHP and MySQL I am working on a user login type site. Here
I almost have facebook connect working the way I need it on my site,
I use PHP and Oracle, with crontab executing the PHP scripts at scheduled times.
Im making a login/logout class that logs users in, sets cookies based on user's
I'm developing a media bookmarking site and am looking for a way to remember
I'm looking for a server-side implementation to disable a browser from saving invalid login

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.